有沒有什麼辦法可以用C#創建doc文件?我已經嘗試過了,但它在2003年沒有打開,但它在Word 2007中打開?如何用C#創建doc 2003文件
我一直在使用這個代碼,但doc文件不打開Word 2003中:
//writing to doc file
object oMissing = System.Reflection.Missing.Value;
Microsoft.Office.Interop.Word._Application oWord = new Microsoft.Office.Interop.Word.Application();
Microsoft.Office.Interop.Word._Document oDoc = new Microsoft.Office.Interop.Word.Document();
oWord.Visible = false;
oDoc = oWord.Documents.Add(ref oMissing, ref oMissing, ref oMissing, ref oMissing);
//Insert a paragraph at the beginning of the document.
Microsoft.Office.Interop.Word.Paragraph oPara1;
oPara1 = oDoc.Content.Paragraphs.Add(ref oMissing);
oPara1.Range.Text = text;
object fileName = "C:\\question.doc";
oDoc.SaveAs(ref fileName,
ref oMissing, ref oMissing,
ref oMissing, ref oMissing,
ref oMissing, ref oMissing,
ref oMissing, ref oMissing,
ref oMissing, ref oMissing);
是什麼執行此代碼時,您使用的是Office版本嗎? – Yahia
我正在使用Word 2010和visual studio 2010. – fawad
好的 - 請參閱下面的答案... – Yahia