Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug 68237] CustomHeight attribute of row for SXSSFWorkbook is wrong #1282

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -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)
{
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 @@ -65,16 +65,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]);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will it be better to use InvariantCulture instead of comma to point replacement?

Assert.AreEqual("</row>", lines[1]);


Expand All @@ -94,7 +95,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
Loading