In my Word document are various document properties. When I open the word document with the Wordproccessing object and convert the document to HTML the fields aren´t replaced.
How can I programmatically refresh these values?
my current Code is:
using (MemoryStream ms = new MemoryStream())
{
ms.Write(item.File.OpenBinary(), 0, item.File.OpenBinary().Length);
OpenSettings os = new OpenSettings();
using (WordprocessingDocument doc = WordprocessingDocument.Open(ms, true, os))
{
HtmlConverterSettings settings = new HtmlConverterSettings()
{
PageTitle = "My Page Title"
};
XElement html = HtmlConverter.ConvertToHtml(doc, settings);
Output.Text = html.ToStringNewLineOnAttributes();
}
}
I´m using OpenXMLPowerTools and DocumentFormat.OpenXML
In the HTML Output the fields appears as follows:
<span
lang="de-DE"
class="pt-Platzhaltertext">[Anrede]</span>
XML - Code in Word Doucment:
<w:sdt>
<w:sdtPr>
<w:alias w:val="Anrede"/>
<w:tag w:val="Anrede"/>
<w:id w:val="1584338639"/>
<w:placeholder>
<w:docPart w:val="F2B19A5D640C4F3295F8F7C07F7DD0BD"/>
</w:placeholder>
<w:showingPlcHdr/>
<w:dataBinding w:prefixMappings="xmlns:ns0='http://schemas.microsoft.com/office/2006/metadata/properties' xmlns:ns1='http://www.w3.org/2001/XMLSchema-instance' xmlns:ns2='http://schemas.microsoft.com/office/infopath/2007/PartnerControls' xmlns:ns3='e0f4b66e-a41b-4a2f-a5f4-37511d6ee82e' " w:xpath="/ns0:properties[1]/documentManagement[1]/ns3:Anrede[1]" w:storeItemID="{E0660C1E-777E-43B2-B0E8-59A22ED635AC}"/>
<w:text/></w:sdtPr>
<w:sdtEndPr/>
<w:sdtContent>
<w:r w:rsidRPr="00300F69">
<w:rPr>
<w:rStyle w:val="Platzhaltertext"/>
</w:rPr>
<w:t>[Anrede]</w:t>
</w:r>
</w:sdtContent>