支持Strict Open Xml

This commit is contained in:
罗威 2022-03-08 18:24:29 +08:00
parent 25f5811888
commit f0bce37e82
3 changed files with 18 additions and 1 deletions

Binary file not shown.

View File

@ -4,5 +4,7 @@
{
public const string SpreadsheetmlXmlns = "http://schemas.openxmlformats.org/spreadsheetml/2006/main";
public const string SpreadsheetmlXmlStrictns = "http://purl.oclc.org/ooxml/spreadsheetml/main";
public const string SpreadsheetmlXmlRelationshipns = "http://schemas.openxmlformats.org/officeDocument/2006/relationships";
public const string SpreadsheetmlXmlStrictRelationshipns = "http://purl.oclc.org/ooxml/officeDocument/relationships";
}
}

View File

@ -15,6 +15,7 @@ namespace MiniExcelLibs.OpenXml
internal class ExcelOpenXmlSheetReader : IExcelReader
{
private static readonly string[] _ns = { Config.SpreadsheetmlXmlns, Config.SpreadsheetmlXmlStrictns };
private static readonly string[] _relationshiopNs = { Config.SpreadsheetmlXmlRelationshipns, Config.SpreadsheetmlXmlStrictRelationshipns };
private List<SheetRecord> _sheetRecords;
private List<string> _sharedStrings;
private MergeCells _mergeCells;
@ -529,7 +530,7 @@ namespace MiniExcelLibs.OpenXml
yield return new SheetRecord(
reader.GetAttribute("name"),
uint.Parse(reader.GetAttribute("sheetId")),
reader.GetAttribute("id", "http://schemas.openxmlformats.org/officeDocument/2006/relationships")
GetAttribute(reader, "id", _relationshiopNs)
);
reader.Skip();
}
@ -730,5 +731,19 @@ namespace MiniExcelLibs.OpenXml
{
return nss.Any(s => reader.IsStartElement(name, s));
}
private string GetAttribute(XmlReader reader, string name, params string[] nss)
{
foreach (var ns in nss)
{
var attribute = reader.GetAttribute(name, ns);
if (attribute != null)
{
return attribute;
}
}
return null;
}
}
}