i'm using microsoft interop word version 15.0.0.0 in order create new word document, insert text it, , save it.
when i'm saving using following command:
document.saveas2(wordfilepath);
the document saved in format docx.
but when i'm saving using following command:
document.saveas2(wordfilepath, microsoft.office.interop.word.wdsaveformat.wdformatdocument97);
the document seemingly saved word-97 doc (windows explorer display word-97 doc icon , type), internally saved docx (i can see in 2 ways: has same size of corresponding docx, , when open word-2016 , select saveas, default save format docx!).
how can save document in real document-97 format?
here's function used create new word document, type depends on extension (doc vs. docx) of given file path:
public static void texttomsworddocument(string body, string wordfilepath) { microsoft.office.interop.word.application winword = new microsoft.office.interop.word.application(); winword.visible = false; object missing = system.reflection.missing.value; microsoft.office.interop.word.document document = winword.documents.add(ref missing, ref missing, ref missing, ref missing); if (body != null) { document.content.setrange(0, 0); document.content.text = (body + system.environment.newline); } if (system.io.path.getextension(wordfilepath).tolower() == "doc") document.saveas2(wordfilepath, microsoft.office.interop.word.wdsaveformat.wdformatdocument97); else // assuming "docx" extension: document.saveas2(wordfilepath); document.close(ref missing, ref missing, ref missing); document = null; winword.quit(ref missing, ref missing, ref missing); winword = null; }
and here's code used call function:
texttomsworddocument("abcdefghijklmnopqrstuvwxyz", "text.doc"); texttomsworddocument("abcdefghijklmnopqrstuvwxyz", "text.docx");
it's been rather stupid error...compare ‘ == ".doc" ’ instead of ‘ == "doc"...
i didn't notice due fact when saveas2 received file path extension ".doc" , no wdsaveformat, - strangely enough- created word document file had problem explained here...
Comments
Post a Comment