码迷,mamicode.com
首页 > Web开发 > 详细

aspose.word 读取word段落内容

时间:2017-03-21 15:42:43      阅读:637      评论:0      收藏:0      [点我收藏+]

标签:密码   word   操作   破解版   public   miss   map   string   count   

aspose.word 插件下载 链接: http://pan.baidu.com/s/1qXIgOXY 密码: wsj2

使用原因:无需安装office,无兼容性问题,破解版有一定限制

代码:

public ParagraphCollection WordParagraphs(string fileName)
{
          Document doc = new Document(fileName);
          if (doc.FirstSection.Body.Paragraphs.Count > 0)
          {
             return doc.FirstSection.Body.Paragraphs;//word中的所有段落
          }
          return null;
}
public string GetWordParagraphs(int index)
{
       var phs = _word.WordParagraphs(Server.MapPath(model.WordFpath));  
        return phs[i].GetText();
}

附上使用Microsoft.Office.Interop.Word 读取段落(操作灵活但兼容性未解决)

public class WordHelper
{    
  private _Document doc = null;
  public WordHelper()
  {
    objApp = new Application();
  }
  public void Open(string fileName)
  {
     object objDoc = fileName;
     object objMissing = Missing.Value;
     doc = objApp.Documents.Open(ref objDoc);
     doc.Activate();
  } 
       
   public Paragraphs GetParagraphs()
  {
    return objApp.ActiveDocument.Paragraphs;
  }
  public string GetParagraphs(int index)
  {
     return objApp.ActiveDocument.Paragraphs[index].Range.Text;
  }

    public void Close()
  {
       objApp.ActiveDocument.Close();
       objApp.Quit();
  }

     
}

 

aspose.word 读取word段落内容

标签:密码   word   操作   破解版   public   miss   map   string   count   

原文地址:http://www.cnblogs.com/z-huifei/p/6594336.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!