如何使用 Interop 在 C# 中从 Excel 或 PowerPoint 文件获取修订?
正在开发一个需要计算文档和修订中的字数的应用程序。
正如您在此处,我已经解决了 Word 文档的这个问题(好吧,尽可能解决它),但现在我发现自己想知道如何从 Excel 或 PowerPoint 文档中获取该数据。
MSDN 文档到目前为止没有帮助 - 我会继续寻找,但如果有人知道答案,我将不胜感激。
编辑:因此,根据@Andrew(感谢他)提供的信息,我得到了 Excel 部分的代码:
foreach (Excel._Worksheet s in ExcelBook.Sheets)
{
if (s.UsedRange.Value2 != null)
{
for (int i = 1; i <= s.UsedRange.Value2.GetLength(0); i++)
{
for (int j = 1; j <= s.UsedRange.Value2.GetLength(1); j++)
{
string content = s.UsedRange.Value2[i, j];
MessageBox.Show(i + " - " + j + " - " + content);
}
}
}
}
现在我可以使用它来计算工作表中所有单元格中的单词数,但是仍然如此对修改没有帮助 - 有人知道如何跟进吗?
Am working on an application that needs to count words from documents and revisions.
as you can see here, I have already resolved this for Word Documents (well, as much it can be resolved) but now i find myself wondering how to get that data from Excel or PowerPoint documents.
The MSDN Documentation didn't help so far - i will keep looking but if anyone knows the answer i would appreciate a little help.
EDIT: So taking the information provided by @Andrew (Thanks go to him) i got this code for the Excel part:
foreach (Excel._Worksheet s in ExcelBook.Sheets)
{
if (s.UsedRange.Value2 != null)
{
for (int i = 1; i <= s.UsedRange.Value2.GetLength(0); i++)
{
for (int j = 1; j <= s.UsedRange.Value2.GetLength(1); j++)
{
string content = s.UsedRange.Value2[i, j];
MessageBox.Show(i + " - " + j + " - " + content);
}
}
}
}
Now i can use that to count words in all cells in the Sheet, however that still doesn't help with revisions - anyone has an idea on how to follow up on this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
从您链接到 Word 的 OM 的代码示例可以看出,您可以访问其修订跟踪功能。便利。
PowerPoint 没有任何修订跟踪功能,因此您无法使用任何内容,除非按照 Andrew 的建议,您一次从演示文稿中提取并存储文本,然后再执行相同操作并比较两者。无论如何,理解大部分文本并不是那么困难。比较两组文本以寻找修订可能相当复杂。
这里有一些用于提取幻灯片上常规文本的 VBA 宏(免责声明:我的网站):
http://www.pptfaq.com/FAQ00274.htm
这些想法很简单,不会无法处理分组形状、表格、图表等中的文本,但它们可以帮助您入门。
It appears from the code example that you linked to that Word's OM gives you access to its revision tracking feature. Handy.
PowerPoint has no revision tracking whatever, so there's nothing for you to work with unless as Andrew has suggested, you extract and store the text from a presentation at one point, then later do the same and compare the two. Getting at the text, most of it anyhow, isn't all that difficult. Comparing two sets of text looking for revisions could be quite complex.
There are some VBA macros for extracting regular text on slides here (disclaimer: my site):
http://www.pptfaq.com/FAQ00274.htm
These are simple-minded and won't deal with text in grouped shapes, tables, charts and so on, but they'll get you started.
您应该尝试这个。
几个月前它对我有帮助。这是关于 CodeProjects 的非常好的教程。
You should try this.
It helped me few months ago. It is a very nice tutorial on CodeProjects.