Skip to content

Commit e1b7951

Browse files
committed
[Bug] SaveAsByTemplate rowInfo.IEnumerableMercell.Height null exception
1 parent abfc7ad commit e1b7951

File tree

4 files changed

+30
-19
lines changed

4 files changed

+30
-19
lines changed

docs/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@
2323
---
2424

2525
### 1.31.3
26-
- [Bug] Fix DescriptionAttr null check(via @wulaoh)
26+
- [Bug] DescriptionAttr null check(via @wulaoh)
27+
- [Bug] Throw custom exception when CSV column not found #543 (via @pszybiak)
28+
- [Bug] SaveAsByTemplate rowInfo.IEnumerableMercell.Height null exception #553 (via @shps951023)
2729

2830
### 1.31.2
2931
- [New] Support automatic merge for same vertical cells between @merge and @endmerge tags (via @eynarhaji)

docs/README.zh-CN.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@
2828

2929

3030
### 1.31.3
31-
- [Bug] 增加 DescriptionAttr null check(via @wulaoh)
31+
- [Bug] DescriptionAttr null check(via @wulaoh)
32+
- [Bug] Throw custom exception when CSV column not found #543 (via @pszybiak)
33+
- [Bug] SaveAsByTemplate rowInfo.IEnumerableMercell.Height null exception #553 (via @shps951023)
3234

3335
### 1.31.2
3436

docs/README.zh-Hant.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@
2727

2828

2929
### 1.31.3
30-
- [Bug] Fix DescriptionAttr null check(via @wulaoh)
30+
- [Bug] DescriptionAttr null check(via @wulaoh)
31+
- [Bug] Throw custom exception when CSV column not found #543 (via @pszybiak)
32+
- [Bug] SaveAsByTemplate rowInfo.IEnumerableMercell.Height null exception #553 (via @shps951023)
3133

3234
### 1.31.2
3335

src/MiniExcel/OpenXml/ExcelOpenXmlTemplate.Impl.cs

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -702,28 +702,33 @@ private void WriteSheetXml(Stream stream, XmlDocument doc, XmlNode sheetData, bo
702702
if (rowInfo.IEnumerableMercell != null)
703703
continue;
704704

705-
// https://github.com/shps951023/MiniExcel/issues/207#issuecomment-824518897
706-
for (int i = 1; i < rowInfo.IEnumerableMercell.Height; i++)
705+
// https://github.com/mini-software/MiniExcel/assets/12729184/1a699497-57e8-4602-b01e-9ffcfef1478d
706+
if (rowInfo?.IEnumerableMercell?.Height != null)
707707
{
708-
mergeBaseRowIndex++;
709-
var _newRow = row.Clone() as XmlElement;
710-
_newRow.SetAttribute("r", mergeBaseRowIndex.ToString());
711-
712-
var cs = _newRow.SelectNodes($"x:c", _ns);
713-
// all v replace by empty
714-
// TODO: remove c/v
715-
foreach (XmlElement _c in cs)
708+
// https://github.com/shps951023/MiniExcel/issues/207#issuecomment-824518897
709+
for (int i = 1; i < rowInfo.IEnumerableMercell.Height; i++)
716710
{
717-
_c.RemoveAttribute("t");
718-
foreach (XmlNode ch in _c.ChildNodes)
711+
mergeBaseRowIndex++;
712+
var _newRow = row.Clone() as XmlElement;
713+
_newRow.SetAttribute("r", mergeBaseRowIndex.ToString());
714+
715+
var cs = _newRow.SelectNodes($"x:c", _ns);
716+
// all v replace by empty
717+
// TODO: remove c/v
718+
foreach (XmlElement _c in cs)
719719
{
720-
_c.RemoveChild(ch);
720+
_c.RemoveAttribute("t");
721+
foreach (XmlNode ch in _c.ChildNodes)
722+
{
723+
_c.RemoveChild(ch);
724+
}
721725
}
722-
}
723726

724-
_newRow.InnerXml = new StringBuilder(_newRow.InnerXml).Replace($"{{{{$rowindex}}}}", mergeBaseRowIndex.ToString()).ToString();
725-
writer.Write(CleanXml(_newRow.OuterXml, endPrefix));
727+
_newRow.InnerXml = new StringBuilder(_newRow.InnerXml).Replace($"{{{{$rowindex}}}}", mergeBaseRowIndex.ToString()).ToString();
728+
writer.Write(CleanXml(_newRow.OuterXml, endPrefix));
729+
}
726730
}
731+
727732
}
728733
}
729734
}

0 commit comments

Comments
 (0)