Skip to content

Commit

Permalink
[Bug] SaveAsByTemplate rowInfo.IEnumerableMercell.Height null exception
Browse files Browse the repository at this point in the history
  • Loading branch information
shps951023 committed Dec 27, 2023
1 parent abfc7ad commit e1b7951
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 19 deletions.
4 changes: 3 additions & 1 deletion docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
---

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

### 1.31.2
- [New] Support automatic merge for same vertical cells between @merge and @endmerge tags (via @eynarhaji)
Expand Down
4 changes: 3 additions & 1 deletion docs/README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@


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

### 1.31.2

Expand Down
4 changes: 3 additions & 1 deletion docs/README.zh-Hant.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@


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

### 1.31.2

Expand Down
37 changes: 21 additions & 16 deletions src/MiniExcel/OpenXml/ExcelOpenXmlTemplate.Impl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -702,28 +702,33 @@ private void WriteSheetXml(Stream stream, XmlDocument doc, XmlNode sheetData, bo
if (rowInfo.IEnumerableMercell != null)
continue;

// https://github.com/shps951023/MiniExcel/issues/207#issuecomment-824518897
for (int i = 1; i < rowInfo.IEnumerableMercell.Height; i++)
// https://github.com/mini-software/MiniExcel/assets/12729184/1a699497-57e8-4602-b01e-9ffcfef1478d
if (rowInfo?.IEnumerableMercell?.Height != null)
{
mergeBaseRowIndex++;
var _newRow = row.Clone() as XmlElement;
_newRow.SetAttribute("r", mergeBaseRowIndex.ToString());

var cs = _newRow.SelectNodes($"x:c", _ns);
// all v replace by empty
// TODO: remove c/v
foreach (XmlElement _c in cs)
// https://github.com/shps951023/MiniExcel/issues/207#issuecomment-824518897
for (int i = 1; i < rowInfo.IEnumerableMercell.Height; i++)
{
_c.RemoveAttribute("t");
foreach (XmlNode ch in _c.ChildNodes)
mergeBaseRowIndex++;
var _newRow = row.Clone() as XmlElement;
_newRow.SetAttribute("r", mergeBaseRowIndex.ToString());

var cs = _newRow.SelectNodes($"x:c", _ns);
// all v replace by empty
// TODO: remove c/v
foreach (XmlElement _c in cs)
{
_c.RemoveChild(ch);
_c.RemoveAttribute("t");
foreach (XmlNode ch in _c.ChildNodes)
{
_c.RemoveChild(ch);
}
}
}

_newRow.InnerXml = new StringBuilder(_newRow.InnerXml).Replace($"{{{{$rowindex}}}}", mergeBaseRowIndex.ToString()).ToString();
writer.Write(CleanXml(_newRow.OuterXml, endPrefix));
_newRow.InnerXml = new StringBuilder(_newRow.InnerXml).Replace($"{{{{$rowindex}}}}", mergeBaseRowIndex.ToString()).ToString();
writer.Write(CleanXml(_newRow.OuterXml, endPrefix));
}
}

}
}
}
Expand Down

0 comments on commit e1b7951

Please sign in to comment.