我正在使用以下提供的SAX方法解析大文件: Parsing and Reading Large Excel Files with the Open XML SDK
这是我修改过的版本(为简单起见,只获取行号)
using (SpreadsheetDocument myDoc = SpreadsheetDocument.Open("BigFile.xlsx", true))
{
WorkbookPart workbookPart = myDoc.WorkbookPart;
WorksheetPart worksheetPart = workbookPart.WorksheetParts.First();
OpenXmlReader reader = OpenXmlReader.Create(worksheetPart);
String rowNum;
while (reader.Read())
{
if (reader.ElementType == typeof(Row))
{
if (reader.HasAttributes)
rowNum = reader.Attributes.First(a => a.LocalName == "r").Value
}
}
}
问题是这会循环遍历每个项目/单元格/列/诸如此类,并且仅在元素类型为Row时才会起作用。
是否有SAX方式仅循环遍历行而不是工作表中的每个项目?
谢谢,
答案 0 :(得分:2)