110,534
社区成员
发帖
与我相关
我的任务
分享
/// <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;
}
Word._Document oDoc;//文档对象
object path = @"E:\XXX.docx";//地址
oDoc = oWord.Documents.Open(ref path, ref oMissing, ref oReadOnly, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing);
有了对象之后就可以进行操作了:
Word.Table tab = oDoc.Tables[1];//获取表
String format = oDoc.Paragraphs.Format.ToString();//段落格式
抛砖引玉