Beispiel #1
0
        //4.0后调用COM组件的方式更加优雅
        static void NewWordFile(string content)
        {
            //启动word使之可见
            Application wordApp = new Application {
                Visible = true
            };

            wordApp.Documents.Add();
            Microsoft.Office.Interop.Word.Document wordDoc = wordApp.ActiveDocument;
            Paragraph para = wordDoc.Paragraphs.Add();

            para.Range.Text = content;
            object fileName = @"E:\hello.doc";

            wordDoc.SaveAs2(FileName: fileName);
            wordDoc.ClosePrintPreview();
            wordApp.Quit();
            Console.WriteLine("Finished.");
        }