Reputation: 1353
Is there any way I can create doc file using C#. I have tried it but it does not open in 2003 but it opens in word 2007?
I have been using this code but the doc file does not open in 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);
Upvotes: 0
Views: 1700
Reputation: 70369
you need to use wdFormatDocument97
as the second parameter of SaveAs()
- for details see http://msdn.microsoft.com/en-us/library/microsoft.office.interop.word._document.saveas.aspx and http://msdn.microsoft.com/en-us/library/microsoft.office.interop.word.wdsaveformat.aspx
EDIT - as per comment:
use
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);
Upvotes: 1
Reputation: 18064
Refer this existing question:-
How can a Word document be created in C#?
And other URLs for your reference:-
Walkthrough: Creating a Table in Word
Creating Word document using C#
Upvotes: 1