wordApp.Selection.Font.Size = 30; // font size
wordApp.Selection.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphCenter; // set align to center
wordApp.Selection.Font.Bold = (int)WdConstants.wdToggle; //set font style to bold.
wordApp.Selection.TypeText("Hello,asdfsdaffdsasdfdsf");//word content. Can get from database
In fact , it works well but only can export text to word 2007 . wordApp.Selection.TypeText("Hello,asdfsdaffdsasdfdsf");//word content. Can get from database
how can i export html to word 2007?
hearticy
Member
19 Points
14 Posts
How to export html to word 2007?
Feb 19, 2008 12:42 AM|LINK
Hi all, I am trying to export html to word 2007 . There are many ways to export html to word 97-2003 file , but not word 2007 file.
I use the following code :
protected void Button1_Click(object sender, EventArgs e)
{
// Start an instance of Word.
ApplicationClass wordApp = new ApplicationClass();
object missing = System.Reflection.Missing.Value;
object tempName = @"d:\Doc1.dotx"; // use template . Add header and footer in the template
object docName = @"D:\a.docx"; // new word document name
Document MyDoc = wordApp.Documents.Add(ref tempName, ref missing, ref missing, ref missing);
wordApp.Visible = true;
MyDoc.Activate();
wordApp.Selection.Font.Size = 30; // font size
wordApp.Selection.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphCenter; // set align to center
wordApp.Selection.Font.Bold = (int)WdConstants.wdToggle; //set font style to bold.
wordApp.Selection.TypeText("Hello,asdfsdaffdsasdfdsf");//word content. Can get from database
wordApp.Selection.InsertAfter("world");
// save word file.
MyDoc.SaveAs(ref docName, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing);
// close.
MyDoc.Close(ref missing, ref missing, ref missing);
wordApp.Quit(ref missing, ref missing, ref missing);
MyDoc = null;
wordApp = null;
Response.Write("ok");
}
--------------------------------------------
In fact , it works well but only can export text to word 2007 . wordApp.Selection.TypeText("Hello,asdfsdaffdsasdfdsf");//word content. Can get from database
how can i export html to word 2007?
thank you very much.