我正在处理一些Word文件,现在我想看看正在处理的文件是否包含“形状”之外的其他内容,在我的情况下,这将是纯文本强>
我知道如何检测文件是否包含形状等。 但要查看文档是否包含文本,我不太确定应该如何执行
string path = "C:/Users/Test/Desktop/Test/";
foreach (string file in Directory.EnumerateFiles(path, "*.docx"))
{
var fileInfo = new FileInfo(file);
if (!fileInfo.Name.StartsWith("~$"))
{
var wordApplication = new Microsoft.Office.Interop.Word.Application();
var document = wordApplication.Documents.Open(file);
if (document.Content.Text.Contains(""))
{
Console.WriteLine(document.Name);
}
}
也许类似这样,如果文档不包含任何内容?
即使我输入一个包含文本的 Word 文件和一个不包含文本的 Word 文件,都会显示在控制台中
最佳答案
您可以统计word文档中的字数。
if (document.Words.Count <= 0)
{
Console.WriteLine(document.Name);
}
关于c# - 如何检查Word文件是否包含文本C#,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40108064/