zoukankan      html  css  js  c++  java
  • OpenXml读取word内容(二)

    注意事项

    上一篇已经说明,这次就不一一说了,直接来正文;

    word内容

    相关代码

    方法1

     1  static void Main(string[] args)
     2         {
     3             string wordPathStr = @"C:UsersuserDesktop新建文件夹 (2)openxml读取表格内容.docx";
     4             using (WordprocessingDocument doc = WordprocessingDocument.Open(wordPathStr, true))
     5             {
     6                 Body body = doc.MainDocumentPart.Document.Body;
     7                 foreach (var table in body.Elements<Table>())
     8                 {
     9                     foreach (var tableRow in table.Elements<TableRow>())
    10                     {
    11                         foreach (var tableCell in tableRow.Elements<TableCell>())
    12                         {
    13                             Console.Write(tableCell.InnerText);
    14                         }
    15                     }
    16                 }
    17             }
    18 
    19             Console.ReadKey();
    20         }
    View Code

     1  static void Main(string[] args)
     2         {
     3             string wordPathStr = @"C:UsersuserDesktop新建文件夹 (2)openxml读取表格内容.docx";
     4             using (WordprocessingDocument doc = WordprocessingDocument.Open(wordPathStr, true))
     5             {
     6                 Body body = doc.MainDocumentPart.Document.Body;
     7                 var tableCellList=body.Elements<OpenXmlElement>();
     8                 foreach (var table in body.Elements<Table>())
     9                 {
    10                     foreach (var tableRow in table.Elements<TableRow>())
    11                     {
    12                         Console.Write(tableRow.InnerText);
    13                     }
    14                 }
    15             }
    16             Console.ReadKey();
    17         }
    View Code

     1  static void Main(string[] args)
     2         {
     3             string wordPathStr = @"C:UsersuserDesktop新建文件夹 (2)openxml读取表格内容.docx";
     4             using (WordprocessingDocument doc = WordprocessingDocument.Open(wordPathStr, true))
     5             {
     6                 Body body = doc.MainDocumentPart.Document.Body;
     7                 var tableCellList=body.Elements<OpenXmlElement>();
     8                 foreach (var table in body.Elements<Table>())
     9                 {
    10                     Console.Write(table.InnerText);
    11                 }
    12             }
    13             Console.ReadKey();
    14         }
    View Code

    方法2

     1     static void Main(string[] args)
     2         {
     3             string wordPathStr = @"C:UsersuserDesktop新建文件夹 (2)openxml读取表格内容.docx";
     4             using (WordprocessingDocument doc = WordprocessingDocument.Open(wordPathStr, true))
     5             {
     6                 Body body = doc.MainDocumentPart.Document.Body;
     7                 var tableCellList = body.Elements<OpenXmlElement>();
     8                 foreach (var inst in tableCellList)
     9                 {
    10                     Console.Write(inst.InnerText);
    11                 }
    12             }
    13 
    14             Console.ReadKey();
    15         }
    View Code

    注:方法1和方法2使用场景,以后慢慢来介绍;

    控制台显示

  • 相关阅读:
    js的event对象 详解
    RestSharp使用详解(1)调用阿里巴巴开放存储服务
    RestSharp使用详解(2)RestSharp的BUG和不足
    WF实例学习笔记:(2)通过Workflow 调用 WCF Data Services 获取数据
    译文:SQL Azure客户端瞬态错误处理最佳实践
    Windbg 基本命令
    RestSharp使用详解(3)OSS文件上传的问题
    Transient Fault Handling and Retry Logic: 瞬间错误处理——重试
    推荐一本免费的Node.js电子书(台湾)
    CSS导航菜单应用滑动门技术的玻璃效果菜单
  • 原文地址:https://www.cnblogs.com/HYJ0201/p/8035361.html
Copyright © 2011-2022 走看看