怎么获取word文档的属性信息!如:字体大小、颜色等。。
如题。设计开发一word文档格式信息提取器,可提取出word文档的段落、图片等元素,并提取出各种元素的格式信息,如字体、字号、颜色、修饰等。
[解决办法]
获取word文档所有信息
[解决办法]
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();//段落格式
/// <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;
}