如何使用c#创建doc 2003文件



我可以用c#创建文档文件吗?我试过了,但是在2003年没有打开,但是在2007年打开了?

我一直在使用这个代码,但文档文件无法在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);

您需要使用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);

参考这个存在的问题:-

如何在c#中创建Word文档?

和其他网址供参考:-

演练:在Word中创建表

创建Word文档

最新更新