I want to convert .docx file to .html. I work in C#. My code is this:
Microsoft.Office.Interop.Word.Application word = new Microsoft.Office.Interop.Word.Application();
Microsoft.Office.Interop.Word.Document wordDoc = new Microsoft.Office.Interop.Word.Document();
Object oMissing = System.Reflection.Missing.Value;
wordDoc = word.Documents.Add(ref oMissing, ref oMissing, ref oMissing, ref oMissing);
word.Visible = false;
Object filepath = @"C:\Users\John\Desktop\begin.docx";
Object confirmconversion = System.Reflection.Missing.Value;
Object readOnly = false;
Object saveto = @"C:\Users\John\Desktop\result.html";
Object oallowsubstitution = System.Reflection.Missing.Value;
wordDoc = word.Documents.Open(ref filepath, ref confirmconversion, ref readOnly, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing);
object fileFormat = WdSaveFormat.wdFormatHTML;
wordDoc.SaveAs(ref saveto, ref fileFormat, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oallowsubstitution, ref oMissing,
ref oMissing);
The problem is, this doesn't include the header and the footer. They aren't in the .html result file. How can I include them in the result?
The reason you see the headers and footers in Word is because you are basically in a Print view. In an HTML document you are in a "Draft" style view where headers and footers do not exist. You can setup a different style for your HTML document for when it is printed called a print stylesheet. This print stylesheet is only used when you print the document in the browser.
Another option would be to just convert it to a PDF and allow the user's to view the PDF since most browsers now either support PDF viewing or have a plugin to support it.
You could also add the headers and footers to the html file as an element and then use some CSS trickery to make the elements display at the top and bottom. Here is a link describing how to do this.
[2]: Old link redirected to a Russian site asking for a phone number with "Telegram" branding. now changed to web archive of 2012 content
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With