OpenXml 获取Excel文件指定工作簿中的表格部件和表格数量
2011-12-12 15:27
239 查看
代码:
using System; using System.Linq; using DocumentFormat.OpenXml.Packaging; using DocumentFormat.OpenXml.Spreadsheet; namespace OpenXmlExcelGetTables { class Program { static void Main(string[] args) { using (SpreadsheetDocument document = SpreadsheetDocument.Open("Tables.xlsx", true)) { WorkbookPart wbPart = document.WorkbookPart; Sheet theSheet = wbPart.Workbook.Descendants<Sheet>().Where(s => s.Name == "Sheet1").FirstOrDefault(); if (theSheet == null) { throw new ArgumentException("sheetName"); } WorksheetPart wsPart = wbPart.GetPartById(theSheet.Id) as WorksheetPart; // get the tables in Excel int count = wsPart.GetPartsOfType<TableDefinitionPart>().Count(); Console.WriteLine(count); } } } }
相关文章推荐
- WinForm开发中,将Excel文件导入到DataGridView中时,获取Excel中所有表格的名称。
- win32命令行小程序获取指定文件夹或者目录下面的所有文件大小,文件数量,目录数量
- 获取指定路径下的文件类型及数量
- .VC获取EXCEL 表格的总行列数 新建文件
- dos下快速获取文件数量并删除小于指定数量的文件夹
- Python获取指定目录下文件数量及总大小
- Unity获取文件夹下指定类型的文件数量
- 关于Excel操作编写的一个软件设计构思案例[连载] --如何打开Excel文件,获取需要列的数据显示到表格内做修改
- [置顶] win32命令行小程序获取指定文件夹或者目录下面的所有文件大小,文件数量,目录数量
- Linux系统编程:获取指定目录下指定文件类型的数量
- 用Excel获取数据——不仅仅只是打开表格
- grep 在文件中查找指定的内容,并输出行号 及 获取指定行号的内容
- jquery获取指定表格的指定列的值 以及 操作radio,checkbox,select表单操作实现代码
- 直接通过ODBC读写Excel表格文件
- PHP获取指定函数定义在哪个文件中及行号
- 最简单的XML格式Excel表格文件
- 统计指定文件夹下的文件数量
- vb实现获取指定目录内的所有文件(包括子目录)
- 获取指定目录下指定类型所有文件的全路径及文件名
- java与Excel (.xls文件) ---使用JXL创建,增添表格文件