【问题标题】:Reading MS Word document in C#, dollar sign, special characters are ignored在 C# 中读取 MS Word 文档,美元符号,特殊字符被忽略
【发布时间】:2017-03-31 04:27:56
【问题描述】:

我正在逐字阅读 Word 文档 (Word 97),返回的文本会忽略美元符号和任何特殊字符。我已将编码设置为 (var wordEncode = Microsoft.Office.Core.MsoEncoding.msoEncodingUTF8;) 在文档打开时间,但它似乎不起作用。

这是我的代码:

var wordEncode = Microsoft.Office.Core.MsoEncoding.msoEncodingUTF8;
Document document = app.Documents.Open(@"C:\Transcript.doc", ReadOnly: true, Encoding: wordEncode);

for (int i = 1; i < document.Words.Count; i++)
{
    textOftheWord = document.Words[i].Text.ToString().Trim().ToLower();
}

示例:文档包含 $587,但在程序中读取后,变量“textOftheWord”为 587,$ 符号不通过。同样,任何特殊字符和带小数的数字都被忽略。

非常感谢您的帮助,谢谢!

【问题讨论】:

标签: c# .net ms-word ms-office


【解决方案1】:

希望这会有所帮助:

Microsoft.Office.Interop.Word.Application word = new Microsoft.Office.Interop.Word.Application();
object miss = System.Reflection.Missing.Value;
object path = @"C:\Transcript.doc";
object readOnly = true;
Microsoft.Office.Interop.Word.Document docs = word.Documents.Open(ref path, ref miss, ref readOnly, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss);
string totaltext = "";
for (int i = 0; i < docs.Paragraphs.Count; i++)
{
     totaltext += " \r\n " + docs.Paragraphs[i + 1].Range.Text.ToString();
}
Console.WriteLine(totaltext);
docs.Close();
word.Quit();

我能够使用它在变量中获得 578 美元。

在这里提出了类似的问题:Read from word document line by line

这里的原始答案:http://mantascode.com/c-how-to-parse-the-text-content-from-microsoft-word-document/

【讨论】:

    猜你喜欢
    • 2018-04-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-12-11
    • 2023-03-22
    • 1970-01-01
    • 2017-07-25
    • 1970-01-01
    相关资源
    最近更新 更多