- private void CreateWordDocument(object filePath)
- {
- object missing = System.Reflection.Missing.Value;
- ApplicationClass wordApp = null;
- _Document doc = null;
- try
- {
- wordApp = new ApplicationClass();
- //create word
- doc = wordApp.Documents.Add(ref missing, ref missing, ref missing, ref missing);
- doc.Activate();
- doc.Content.Text = "This is create word test!";
- doc.SaveAs(ref filePath, 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);
- }
- catch (Exception ex)
- {
- throw new Exception("Create word document failed", ex);
- }
- finally
- {
- if (doc != null)
- doc.Close(ref missing, ref missing, ref missing);
- if (wordApp != null)
- wordApp.Quit(ref missing, ref missing, ref missing);
- }
- }
C#创建Word文档源码
最新推荐文章于 2026-01-09 14:40:17 发布
1790

被折叠的 条评论
为什么被折叠?



