5

我试试这段代码

string[] ext = att.Name.Split('.');
string file = ext[0].ToString();
object Target = file + ".txt";
object nullobject = System.Reflection.Missing.Value;

Application.Documents.Open(ref FileName, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref value, ref value, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj);
object format = Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatUnicodeText;

Application.ActiveDocument.SaveAs(ref Target, ref format,
                        ref Unknown, ref Unknown, ref Unknown,
                        ref Unknown, ref Unknown, ref Unknown,
                        ref Unknown, ref Unknown, ref Unknown,
                        ref Unknown, ref Unknown, ref Unknown,
                        ref Unknown, ref Unknown);
Application.Visible = false;
Microsoft.Office.Interop.Word.Document oDoc1 = Application.ActiveDocument;
string strNewDocText1 = oDoc1.Content.Text;

但在 strNewDocText1 中获取输出,包括项目符号和额外的单词格式

我想将我的 word 文档的简单纯文本格式转换为文本文档。

4

1 回答 1

2

我相信你从这里拿了这个例子:http: //www.codeproject.com/Articles/5273/How-to-convert-DOC-into-other-formats-using-C

所以基本上你有一个 RTF,它必须转换为纯文本。这是一个例子

最简单的方法就是添加对 System.Windows.Forms.dll 的引用。

System.Windows.Forms.RichTextBox rtBox = new System.Windows.Forms.RichTextBox();

string richText = text// The rich text (with bullets and so on.)
rtBox.Rtf = richText ;
string plainText = rtBox.Text;

System.IO.File.WriteAllText(@"output.txt", plainText);
于 2012-06-28T10:14:27.730 回答