- using MSExcel = Microsoft.Office.Interop.Excel;
- using System.IO;
- using System.Refletion;
- Class Program
- {
- static void Main(string[] args)
- {
- string path; //文件路径
- string strContent; //文本内容
- MSWord.Application wordApp;提要 //word应用程序
- MSWord.document wordDoc; //word文档
- path = @"c:/test.docx";
- wordApp = new MSWord.applicationClass();
- if(File.Exists(path))
- {
- File.Delete(path);
- }
- Object nothing = Missing.Value;
- wordDoc = wordApp.Documents.Add(ref nothing,ref nothing,ref nothing,ref nothing);
- strContent = "你好!/n";
- wordDoc.Paragraphs.Last.Rang.Text = strContent;
- object format = MSWord.WdSaveFormat.wdFormatDocumentDefault;
- wordDoc.SaveAs(ref path,ref format,ref nothing,ref nothing,ref nothing,ref nothing,ref nothing,
- ref nothing,ref nothing,ref nothing,ref nothing,ref nothing,ref nothing,
- ref nothing,ref nothing,ref nothing);
- wordDoc.Close(ref nothing,ref nothing,ref nothing);
- wordApp.Quit(ref nothing,ref nothing,ref nothing);
- }
- }
使用C#向Excel文档写入数据
最新推荐文章于 2022-04-27 10:02:08 发布