zoukankan      html  css  js  c++  java
  • aspose.word 读取word段落内容

    注:转载请标明文章原始出处及作者信息

    aspose.word 插件下载 

    链接:https://pan.baidu.com/s/1aAAE8LRULH-uZXS_TaN9Bw 提取码:z9wf 

    使用原因:无需安装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();
      }
    
         
    }
    实践是检验真理的唯一标准
  • 相关阅读:
    UVA 10905
    UVA 10859 树形DP
    LA 4794 状态DP+子集枚举
    LA 3695 部分枚举
    UVA 11825 状态压缩DP+子集思想
    UVA 10891 区间DP+博弈思想
    HDU 5239 上海大都会 D题(线段树+数论)
    HDU 5242 上海大都会 G题
    HDU 5241 上海大都会 F题
    P1359 租用游艇
  • 原文地址:https://www.cnblogs.com/z-huifei/p/6594336.html
Copyright © 2011-2022 走看看