如何用c#解析word(1)--获得文档中的style标签
前几天 受人指点 随手写了这个 代码
:注 在vb中实现此功能很简单 但是在c#中却不是太简单,很多方法
用法不同 当时让我 痛苦了好半天
Word.Document doc=null;
Word.ApplicationClass app=new ApplicationClass();
Word.Style _style;
string _XmlStr="";
object missing=System.Reflection.Missing.Value;
try
{
object FileName=Server.MapPath(".")+"\\test.doc";
object readOnly = false;
object isVisible = true;
object index=0;
doc=app.Documents.Open(ref FileName,ref missing,ref readOnly,ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref isVisible,ref missing,ref missing,ref missing,ref missing);
foreach(Word.Paragraph pa in app.ActiveDocument.Paragraphs)
{
_style=(Word.Style)pa.get_Style();
this.listStyle.Items.Add(_style.NameLocal);
}
}
catch(Exception ex)
{
js.ShowMsg(ex.Message);
}
finally
{
doc.Close(ref missing,ref missing,ref missing);
app.Quit(ref missing,ref missing,ref missing);
//app.ActiveDocument.Close(ref missing,ref missing,ref missing);
GC.Collect();
}