c# - 如何使用C#保存doc文件

标签 c# ms-word

我一直在使用以下代码写入word文件,但无法存储word文件。有什么办法可以使用 C# 存储 word 文件吗?

object oMissing = System.Reflection.Missing.Value;
                object oEndOfDoc = "\\endofdoc"; /* \endofdoc is a predefined bookmark */
                //Start Word and create a new document.
                Microsoft.Office.Interop.Word._Application oWord = new Microsoft.Office.Interop.Word.Application();

            Microsoft.Office.Interop.Word._Document oDoc = new Microsoft.Office.Interop.Word.Document();

            oWord.Visible = true;

            oDoc = oWord.Documents.Add(ref oMissing, ref oMissing, ref oMissing, ref oMissing);

            //Insert a paragraph at the beginning of the document.
            Microsoft.Office.Interop.Word.Paragraph oPara1;

            oPara1 = oDoc.Content.Paragraphs.Add(ref oMissing);
            oPara1.Range.Text = "Heading 1";
            oPara1.Range.Font.Bold = 1;
            oPara1.Format.SpaceAfter = 24;    //24 pt spacing after paragraph.

最佳答案

您应该能够使用另存为。

oDoc.SaveAs("MyFile.doc", ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing);

如果您使用的是 .NET 4.0,则不需要 oMissings。

小号

关于c# - 如何使用C#保存doc文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7811481/

相关文章:

c# - 在保护模式下从 C# 打开 Winword

formatting - 如何将程序打印到 MS Word?

vba - 将 MS Word 文档中每个句子的第一个字母加粗

c# - Entity Framework 事务

c# - 将两个字符串添加到二维列表

c# - 从 C# 调用 C++ 代码时出现 System.EntryPointNotFoundException

excel - Powershell - 为文字或图像解析 PDF 文件

java - 表格中的页码

c# - itextsharp 不关心我的 html 样式

c# - 过滤 ICollectionView<object> 时性能下降