Skip to content

Commit

Permalink
Merge pull request #1282 from superrnovae/fix_sxssf_customHeight_attr…
Browse files Browse the repository at this point in the history
…ibute

[Bug 68237] CustomHeight attribute of row for SXSSFWorkbook is wrong
  • Loading branch information
tonyqus authored May 5, 2024
2 parents 200c5d3 + 528895d commit e7b5b4e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
13 changes: 6 additions & 7 deletions ooxml/XSSF/Streaming/SheetDataWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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; }
Expand All @@ -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()
{
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -218,13 +217,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)
{
Expand Down
9 changes: 5 additions & 4 deletions testcases/ooxml/XSSF/Streaming/SheetDataWriterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,17 @@ 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();

var lines = File.ReadAllLines(_objectToTest.TemporaryFilePath());

Assert.True(lines.Length == 2);
Assert.AreEqual("<row r=\"" + 1 + "\" customHeight=\"true\" ht=\"" + row.HeightInPoints + "\">", lines[0]);
Assert.AreEqual("<row r=\"" + 1 + "\" customHeight=\"1\" ht=\"" + row.HeightInPoints.ToString().Replace(',', '.') + "\">", lines[0]);
Assert.AreEqual("</row>", lines[1]);


Expand All @@ -93,7 +94,7 @@ public void IfWritingRowWithZeroHeightShouldIncludeHiddenAttributeXml()
var lines = File.ReadAllLines(_objectToTest.TemporaryFilePath());

Assert.True(lines.Length == 2);
Assert.AreEqual("<row r=\"" + 1 + "\" hidden=\"true\">", lines[0]);
Assert.AreEqual("<row r=\"" + 1 + "\" hidden=\"1\">", lines[0]);
Assert.AreEqual("</row>", lines[1]);


Expand Down

0 comments on commit e7b5b4e

Please sign in to comment.