‘ Grazie alla libreria OpenXml SDK di Microsoft, inclusa dalla release 2015.05b della piattaforma
‘ web QWay/QualiWare, è possibile con poche righe di codice aggiungere contenuti ad un documento Word esistente.
‘ Il seguente frammento di codice rimuove i campi QualiWare presenti in un documento Word sostituendoli col testo che contengono
Dim path_doc As String
‘ Recupera il percorso del documento corrente
path_doc = "<percorso del documento>"
Dim myDoc As DocumentFormat.OpenXml.Packaging.WordprocessingDocument = DocumentFormat.OpenXml.Packaging.WordprocessingDocument.Open(path_doc, True)
Dim mainPart As DocumentFormat.OpenXml.Packaging.MainDocumentPart = myDoc.MainDocumentPart
Dim cc as DocumentFormat.OpenXml.Wordprocessing.FieldCode
Dim cc0,cc2
If not myDoc.MainDocumentPart.HeaderParts Is Nothing
For Each header as DocumentFormat.OpenXml.Packaging.HeaderPart In myDoc.MainDocumentPart.HeaderParts
For Each cc In header.RootElement.Descendants(Of DocumentFormat.OpenXml.Wordprocessing.FieldCode)()
If DBDollar("DOCPROPERTY",cc.text)
cc0=cc.parent.PreviousSibling
cc2=cc.parent.NextSibling
cc0.remove
cc.parent.remove
cc2.Remove
End If
Next
Next
End If
For Each cc In myDoc.MainDocumentPart.RootElement.Descendants(Of DocumentFormat.OpenXml.Wordprocessing.FieldCode)()
If DBDollar("DOCPROPERTY",cc.text)
cc0=cc.parent.PreviousSibling
cc2=cc.parent.NextSibling
cc0.remove
cc.parent.remove
cc2.Remove
End If
Next
If Not myDoc.MainDocumentPart.FooterParts Is nothing
For Each footer as DocumentFormat.OpenXml.Packaging.FooterPart In myDoc.MainDocumentPart.FooterParts
For Each cc In footer.RootElement.Descendants(Of DocumentFormat.OpenXml.Wordprocessing.FieldCode)()
If DBDollar("DOCPROPERTY",cc.text)
cc0=cc.parent.PreviousSibling
cc2=cc.parent.NextSibling
cc0.remove
cc.parent.remove
cc2.Remove
End If
Next
Next
End If
mainPart.Document.Save()
myDoc.Close()