From f8dc9efc649392bf45a445b4da911cb7f58057f3 Mon Sep 17 00:00:00 2001 From: suppernovae Date: Tue, 5 Mar 2024 11:09:00 +0100 Subject: [PATCH 1/2] [Bug 68237] customHeight attribute of row for SXSSFWorkbook is wrong --- ooxml/XSSF/Streaming/SheetDataWriter.cs | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/ooxml/XSSF/Streaming/SheetDataWriter.cs b/ooxml/XSSF/Streaming/SheetDataWriter.cs index c8098be2f..86a814326 100644 --- a/ooxml/XSSF/Streaming/SheetDataWriter.cs +++ b/ooxml/XSSF/Streaming/SheetDataWriter.cs @@ -18,7 +18,6 @@ limitations under the License. using System.Globalization; using System.IO; using System.Text; -using NPOI.OpenXmlFormats.Spreadsheet; using NPOI.SS.UserModel; using NPOI.SS.Util; using NPOI.Util; @@ -29,7 +28,7 @@ namespace NPOI.XSSF.Streaming { public class SheetDataWriter { - private static POILogger logger = POILogFactory.GetLogger(typeof(SheetDataWriter)); + private static readonly POILogger logger = POILogFactory.GetLogger(typeof(SheetDataWriter)); protected FileInfo TemporaryFileInfo { get; set; } protected Stream OutputStream { get; private set; } @@ -43,8 +42,8 @@ public class SheetDataWriter * Table of strings shared across this workbook. * If two cells contain the same string, then the cell value is the same index into SharedStringsTable */ - private SharedStringsTable _sharedStringSource; - private StreamWriter _outputWriter; + private readonly SharedStringsTable _sharedStringSource; + private readonly StreamWriter _outputWriter; public SheetDataWriter() { @@ -79,7 +78,7 @@ public virtual Stream CreateWriter(FileInfo fd) { FileStream fos = new FileStream(fd.FullName, FileMode.OpenOrCreate, FileAccess.ReadWrite); - Stream outputStream = null; + Stream outputStream; try { outputStream = DecorateOutputStream(fos); @@ -228,13 +227,13 @@ private void BeginRow(int rownum, SXSSFRow row) if (row.HasCustomHeight()) { - WriteAsBytes(" customHeight=\"true\" ht=\""); + WriteAsBytes(" customHeight=\"1\" ht=\""); WriteAsBytes(row.HeightInPoints); WriteAsBytes("\""); } if (row.ZeroHeight) { - WriteAsBytes(" hidden=\"true\""); + WriteAsBytes(" hidden=\"1\""); } if (row.IsFormatted) { From 528895d4893ee3c178516544e4d30cd482ff8e21 Mon Sep 17 00:00:00 2001 From: suppernovae Date: Tue, 5 Mar 2024 11:19:51 +0100 Subject: [PATCH 2/2] Fix testcases --- testcases/ooxml/XSSF/Streaming/SheetDataWriterTests.cs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/testcases/ooxml/XSSF/Streaming/SheetDataWriterTests.cs b/testcases/ooxml/XSSF/Streaming/SheetDataWriterTests.cs index ca504036a..379ee7ada 100644 --- a/testcases/ooxml/XSSF/Streaming/SheetDataWriterTests.cs +++ b/testcases/ooxml/XSSF/Streaming/SheetDataWriterTests.cs @@ -65,8 +65,9 @@ public void IfCallingEmptyConstructorShouldCreateNonZippedTempFileNonDecoratedSt public void IfWritingRowWithCustomHeightShouldIncludeCustomHeightXml() { _objectToTest = new SheetDataWriter(); - var row = new SXSSFRow(null); - row.Height = 1; + var row = new SXSSFRow(null) { + Height = 1 + }; _objectToTest.WriteRow(0, row); _objectToTest.Close(); @@ -74,7 +75,7 @@ public void IfWritingRowWithCustomHeightShouldIncludeCustomHeightXml() var lines = File.ReadAllLines(_objectToTest.TemporaryFilePath()); Assert.True(lines.Length == 2); - Assert.AreEqual("", lines[0]); + Assert.AreEqual("", lines[0]); Assert.AreEqual("", lines[1]); @@ -94,7 +95,7 @@ public void IfWritingRowWithZeroHeightShouldIncludeHiddenAttributeXml() var lines = File.ReadAllLines(_objectToTest.TemporaryFilePath()); Assert.True(lines.Length == 2); - Assert.AreEqual("