有什么办法可以用C#创建doc文件。我已经尝试过,但它在2003年没有开放,但它在2007年开放了吗?
我一直在使用此代码,但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);
答案 0 :(得分:1)
参考现有问题: -
<强> How can a Word document be created in C#? 强>
以及其他网址供您参考: -
答案 1 :(得分:1)
您需要使用wdFormatDocument97
作为SaveAs()
的第二个参数 - 有关详细信息,请参阅http://msdn.microsoft.com/en-us/library/microsoft.office.interop.word._document.saveas.aspx和http://msdn.microsoft.com/en-us/library/microsoft.office.interop.word.wdsaveformat.aspx
编辑 - 根据评论:
使用
object vFormat = Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatDocument97;
oDoc.SaveAs(ref fileName,
ref vFormat, ref oMissing,
ref oMissing, ref oMissing,
ref oMissing, ref oMissing,
ref oMissing, ref oMissing,
ref oMissing, ref oMissing);