Word.ApplicationClass WordApp = new Word.ApplicationClass(); object missing = System.Reflection.Missing.Value; object fileName = "normal.dot"; // template file name object newTemplate = false; object docType = 0; object isVisible = true;// Create a new Document, by calling the Add function in the Documents collectionWord.Document aDoc = WordApp.Documents.Add(ref fileName, ref newTemplate, ref docType, ref isVisible);
WordApp.Visible = true; aDoc.Activate(); WordApp.Selection.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter;// Toggle the title to a Bold Font WordApp.Selection.Font.Bold = (int)Word.WdConstants.wdToggle;WordApp.Selection.TypeText(listView1.Items[0].Text);完整代码到这里看: http://www.c-sharpcorner.com/Code/2002/Mar/WordFromDotNet.asp
假如word文件保存在"D:\mydoc.doc"
用这个语句就可以打开word文件:response.redirect("D:\mydoc.doc")或者用这个 Response.Write("<s" & "cript language=JavaScript> window.open('D:\mydoc.doc','','status=yes,location=yes,toolbar=yes,resizable=yes,directories=yes,menubar=yes')</scrip" & "t>")
需要
Microsoft.Office.Interop.Word.dll
Office.dll Application app = new Application();
object template=Missing.Value;
object newTemplate=Missing.Value;
object documentType=Missing.Value;
object visible=true;
_Document doc = app.Documents.Add( ref template,ref newTemplate,ref documentType,ref visible);
object missing = System.Reflection.Missing.Value;
object fileName = "normal.dot"; // template file name
object newTemplate = false; object docType = 0;
object isVisible = true;// Create a new Document, by calling the Add function in the Documents collectionWord.Document aDoc = WordApp.Documents.Add(ref fileName, ref newTemplate, ref docType,
ref isVisible);
WordApp.Visible = true;
aDoc.Activate();
WordApp.Selection.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter;// Toggle the title to a Bold Font
WordApp.Selection.Font.Bold = (int)Word.WdConstants.wdToggle;WordApp.Selection.TypeText(listView1.Items[0].Text);完整代码到这里看:
http://www.c-sharpcorner.com/Code/2002/Mar/WordFromDotNet.asp