【发布时间】:2015-04-20 20:09:09
【问题描述】:
使用 C#,我需要从 word 文档中提取数据。我在项目中安装了 NetOffice for word。数据分为两部分。
首先,我需要从文档设置中提取数据。
其次,我需要拉取文档中控件的内容。字段的内容包括复选框、日期和一些段落。输入法是通过控件,所以必须有某种方式通过api与控件交互,但我不知道该怎么做。
现在,我有以下代码可以从文档中提取纯文本:
private static string wordDocument2String(string file)
{
NetOffice.WordApi.Application wordApplication = new NetOffice.WordApi.Application();
NetOffice.WordApi.Document newDocument = wordApplication.Documents.Open(file);
string txt = newDocument.Content.Text;
wordApplication.Quit();
wordApplication.Dispose();
return txt;
}
所以问题是:如何从文档中的控件中提取数据,以及如何使用 NetOffice 或其他包?
【问题讨论】:
-
这里是一个可能有用的起点:(stackoverflow.com/questions/9518275/…)。 “文档设置”是指边距、字体、行距等属性吗?这些很容易得到。顺便说一句,根据 NetOffice 文档,api 方法与 Office Interop 方法完全相同,这应该有助于您搜索一下。
标签: c# ms-office text-extraction