今天在Silverlight 应用程序中实现了 获取word文档批注信息 的功能。
在wcf服务继承接口类中编写的函数如下
- /// <summary>
- /// 获取word批注信息
- /// </summary>
- /// <param name="filePath">文档路径</param>
- /// <returns>批注信息</returns>
- public string GetWordNotes(string filePath)
- {
- object Nothing = System.Reflection.Missing.Value;
- string strWordComments = string.Empty;
- Microsoft.Office.Interop.Word.Application wordApp = new Application();
- wordApp.Visible = false;
- Document wordDoc = new Document();
- wordDoc = wordApp.Documents.Open(filePath, Nothing, Nothing, Nothing, Nothing,
- Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing);
- try
- {
- foreach (Comment wordComment in wordDoc.Comments)
- {
- strWordComments += wordComment.Range.Text+" 作者:"+wordComment.Author+" 创建日期:"+wordComment.Date;
- }
- }
- catch
- {
- }
- finally
- {
- wordDoc.Close(ref Nothing, ref Nothing, ref Nothing);
- }
- return strWordComments;
- }
其中wordComment.Range.Text 表示批注的内容
wordComment.Author 表示批注添加人
wordComment.Date 表示添加批注的时间