{"id":25608,"date":"2019-07-10T09:37:53","date_gmt":"2019-07-10T07:37:53","guid":{"rendered":"http:\/\/help.qualiware.it\/qw-help\/?p=25608"},"modified":"2019-07-10T09:42:02","modified_gmt":"2019-07-10T07:42:02","slug":"inserimento-di-unimmagine-in-un-file-word","status":"publish","type":"post","link":"https:\/\/help.qualiware.it\/qw-help\/inserimento-di-unimmagine-in-un-file-word\/","title":{"rendered":"Inserimento di un&#8217;immagine in un file Word"},"content":{"rendered":"<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">' Il seguente frammento di codice mostra come si pu\u00f2 inserire un'immagine in un file Word in formato DOCX o DOCM\r\n' Pu\u00f2 essere usato in un form associato ad una categoria documentale di tipo file per apporre una firma e il nome\r\n' di chi ha firmato su un file Word\r\n' L'immagine \u00e8 contenuta in un campo del form chiamato \"FIRMA_SAVE\", e sul documento deve essere presente un segnalibro chiamato \"QW_FIRMA_WACOM\" nella posizione in cui andr\u00e0 inserita l'immagine.\r\n\r\ndim QWSess as QWSession = form.Session(\"QWSess\")\r\n\r\ndim path_doc as string\r\n\r\npath_doc = QWSess.Q95_NOME_DIR_DOCUM + \"\\\" + form.form_state.dmd_ref.TIPI_DOC.rowset.fields(\"DIRECTORY\").value + \"\\\" + iif(form.form_state.dmd_ref.DOCUMENT.rowset.fields(\"PUBBLICATO\").value, QWSess.DESCRITT.rowset.fields(\"DIR_IN_VIG\").value, QWSess.DESCRITT.rowset.fields(\"DIR_ATTESA\").value) + \"\\\" + form.form_state.dmd_ref.DOCUMENT.rowset.fields(\"NOMEFILE\").value\r\n\r\nif not dbdollar(\".DOCX\", upper(path_doc)) and not dbdollar(\".DOCM\", upper(path_doc)) then\r\n\tform.Alert(\"Il Documento deve essere in formato DOCX o DOCM !\", \"ERRORE\")\r\nelse\r\n\tdim nomefilejpg as string\r\n\t\r\n\tnomefilejpg = funique(Q95_PATH_TEMP + \"\\??????????.png\")\r\n\t'Base64ToFile(form.findcontrol2(\"FIRMA_SAVE\").Text, nomefilejpg)\r\n\tBase64ToFile(replace(unEscape(form.findcontrol2(\"FIRMA_SAVE\").Text), \"data:image\/png;base64,\", \"\"), nomefilejpg)\r\n\t\r\n\tif FileLen(nomefilejpg) &gt; 0 then\r\n\t\tDim doc As DocumentFormat.OpenXml.Packaging.WordprocessingDocument = DocumentFormat.OpenXml.Packaging.WordprocessingDocument.Open(path_doc, True)\r\n\t\t\r\n        For Each bookmarkStart As DocumentFormat.OpenXml.Wordprocessing.BookmarkStart In doc.MainDocumentPart.RootElement.Descendants(Of DocumentFormat.OpenXml.Wordprocessing.BookmarkStart)()\r\n            If bookmarkStart.Name = \"QW_FIRMA_WACOM\" Then\r\n\t\t\t\tDim elem As DocumentFormat.OpenXml.OpenXmlElement = bookmarkStart.NextSibling()\r\n\t\t\t\t\r\n\t\t\t\tWhile elem IsNot Nothing AndAlso Not (TypeOf elem Is DocumentFormat.OpenXml.Wordprocessing.BookmarkEnd)\r\n\t\t\t\t\tDim nextElem As DocumentFormat.OpenXml.OpenXmlElement = elem.NextSibling()\r\n\t\t\t\t\telem.Remove()\r\n\t\t\t\t\telem = nextElem\r\n\t\t\t\tEnd While\r\n\t\t\t\t\r\n\t\t\t\tDim mainPart As DocumentFormat.OpenXml.Packaging.MainDocumentPart\r\n\t\t\t\tDim imagePart As DocumentFormat.OpenXml.Packaging.ImagePart\r\n\t\t\t\t\r\n\t\t\t\tmainPart = doc.MainDocumentPart\r\n\t\t\t\timagePart = mainPart.AddImagePart(DocumentFormat.OpenXml.Packaging.ImagePartType.Png)\r\n\t\t\t\t\r\n\t\t\t\tUsing stream As System.IO.FileStream = New System.IO.FileStream(nomefilejpg, System.IO.FileMode.Open)\r\n\t\t\t\t\timagePart.FeedData(stream)\r\n\t\t\t\tEnd Using\r\n\t\t\t\t\r\n\t\t\t\tDim relationshipId As String = doc.MainDocumentPart.GetIdOfPart(imagePart)\r\n\t\t\t\t\r\n\t\t\t\tDim element as DocumentFormat.OpenXml.Wordprocessing.Drawing = New DocumentFormat.OpenXml.Wordprocessing.Drawing(New DocumentFormat.OpenXml.Drawing.Wordprocessing.Inline(New DocumentFormat.OpenXml.Drawing.Wordprocessing.Extent() With {\r\n\t\t\t\t\t.Cx = 990000L,\r\n\t\t\t\t\t.Cy = 792000L\r\n\t\t\t\t}, New DocumentFormat.OpenXml.Drawing.Wordprocessing.EffectExtent() With {\r\n\t\t\t\t\t.LeftEdge = 0L,\r\n\t\t\t\t\t.TopEdge = 0L,\r\n\t\t\t\t\t.RightEdge = 0L,\r\n\t\t\t\t\t.BottomEdge = 0L\r\n\t\t\t\t}, New DocumentFormat.OpenXml.Drawing.Wordprocessing.DocProperties() With {\r\n\t\t\t\t\t.Id = CType(1UI, DocumentFormat.OpenXml.UInt32Value),\r\n\t\t\t\t\t.Name = \"Picture 1\"\r\n\t\t\t\t}, New DocumentFormat.OpenXml.Drawing.Wordprocessing.NonVisualGraphicFrameDrawingProperties(New DocumentFormat.OpenXml.Drawing.GraphicFrameLocks() With {\r\n\t\t\t\t\t.NoChangeAspect = True\r\n\t\t\t\t}), New DocumentFormat.OpenXml.Drawing.Graphic(New DocumentFormat.OpenXml.Drawing.GraphicData(New DocumentFormat.OpenXml.Drawing.Pictures.Picture(New DocumentFormat.OpenXml.Drawing.Pictures.NonVisualPictureProperties(New DocumentFormat.OpenXml.Drawing.Pictures.NonVisualDrawingProperties() With {\r\n\t\t\t\t\t.Id = CType(0UI, DocumentFormat.OpenXml.UInt32Value),\r\n\t\t\t\t\t.Name = \"New Bitmap Image.jpg\"\r\n\t\t\t\t}, New DocumentFormat.OpenXml.Drawing.Pictures.NonVisualPictureDrawingProperties()), New DocumentFormat.OpenXml.Drawing.Pictures.BlipFill(New DocumentFormat.OpenXml.Drawing.Blip(New DocumentFormat.OpenXml.Drawing.BlipExtensionList(New DocumentFormat.OpenXml.Drawing.BlipExtension() With {\r\n\t\t\t\t\t.Uri = \"{28A0092B-C50C-407E-A947-70E740481C1C}\"\r\n\t\t\t\t})) With {\r\n\t\t\t\t\t.Embed = relationshipId,\r\n\t\t\t\t\t.CompressionState = DocumentFormat.OpenXml.Drawing.BlipCompressionValues.Print\r\n\t\t\t\t}, New DocumentFormat.OpenXml.Drawing.Stretch(New DocumentFormat.OpenXml.Drawing.FillRectangle())), New DocumentFormat.OpenXml.Drawing.Pictures.ShapeProperties(New DocumentFormat.OpenXml.Drawing.Transform2D(New DocumentFormat.OpenXml.Drawing.Offset() With {\r\n\t\t\t\t\t.X = 0L,\r\n\t\t\t\t\t.Y = 0L\r\n\t\t\t\t}, New DocumentFormat.OpenXml.Drawing.Extents() With {\r\n\t\t\t\t\t.Cx = 990000L,\r\n\t\t\t\t\t.Cy = 792000L\r\n\t\t\t\t}), New DocumentFormat.OpenXml.Drawing.PresetGeometry(New DocumentFormat.OpenXml.Drawing.AdjustValueList()) With {\r\n\t\t\t\t\t.Preset = DocumentFormat.OpenXml.Drawing.ShapeTypeValues.Rectangle\r\n\t\t\t\t}))) With {\r\n\t\t\t\t\t.Uri = \"http:\/\/schemas.openxmlformats.org\/drawingml\/2006\/picture\"\r\n\t\t\t\t})) With {\r\n\t\t\t\t\t.DistanceFromTop = CType(0UI, DocumentFormat.OpenXml.UInt32Value),\r\n\t\t\t\t\t.DistanceFromBottom = CType(0UI, DocumentFormat.OpenXml.UInt32Value),\r\n\t\t\t\t\t.DistanceFromLeft = CType(0UI, DocumentFormat.OpenXml.UInt32Value),\r\n\t\t\t\t\t.DistanceFromRight = CType(0UI, DocumentFormat.OpenXml.UInt32Value),\r\n\t\t\t\t\t.EditId = \"50D07946\"\r\n\t\t\t\t})\r\n\t\t\t\t\r\n\t\t\t\tbookmarkStart.Parent.InsertAfter(Of DocumentFormat.OpenXml.Wordprocessing.Run)(New DocumentFormat.OpenXml.Wordprocessing.Run(element), bookmarkStart)\t\t\t\t\r\n\t\t\t\t\r\n                bookmarkStart.Remove()\r\n                Exit For\r\n            End If\r\n        Next\r\n\t\t\r\n        doc.Close()\r\n\tend if\r\nend if\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>&#8216; Il seguente frammento di codice mostra come si pu\u00f2 inserire un&#8217;immagine in un file Word in formato DOCX o DOCM &#8216; Pu\u00f2 essere usato in un form associato ad una categoria documentale di tipo file per apporre una firma e il nome &#8216; di chi ha firmato su un file Word &#8216; L&#8217;immagine \u00e8&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"ngg_post_thumbnail":0,"footnotes":""},"categories":[65],"tags":[71],"acf":[],"_links":{"self":[{"href":"https:\/\/help.qualiware.it\/qw-help\/wp-json\/wp\/v2\/posts\/25608"}],"collection":[{"href":"https:\/\/help.qualiware.it\/qw-help\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/help.qualiware.it\/qw-help\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/help.qualiware.it\/qw-help\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/help.qualiware.it\/qw-help\/wp-json\/wp\/v2\/comments?post=25608"}],"version-history":[{"count":0,"href":"https:\/\/help.qualiware.it\/qw-help\/wp-json\/wp\/v2\/posts\/25608\/revisions"}],"wp:attachment":[{"href":"https:\/\/help.qualiware.it\/qw-help\/wp-json\/wp\/v2\/media?parent=25608"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/help.qualiware.it\/qw-help\/wp-json\/wp\/v2\/categories?post=25608"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/help.qualiware.it\/qw-help\/wp-json\/wp\/v2\/tags?post=25608"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}