Skip to content

Commit

Permalink
Merge branch 'nissl-lab:master' into dg
Browse files Browse the repository at this point in the history
  • Loading branch information
mino-alpha authored Jul 31, 2023
2 parents b714481 + 3665a76 commit fc9f45d
Show file tree
Hide file tree
Showing 6 changed files with 126 additions and 8 deletions.
4 changes: 2 additions & 2 deletions main/POIFS/FileSystem/NPOIFSFileSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -310,8 +310,8 @@ public NPOIFSFileSystem(Stream stream)
data.Write(headerBuffer.Buffer);
data.Position = headerBuffer.Length;

//IOUtils.ReadFully(channel, data);
data.Position += IOUtils.ReadFully(channel, data.Buffer, data.Position, (int)channel.Length);
//IOUtils.ReadFully(channel, data.Buffer);
data.Position += IOUtils.ReadFully(channel, data.Buffer, data.Position, (int)maxSize);
success = true;

// Turn it into a DataSource
Expand Down
11 changes: 5 additions & 6 deletions main/Util/IOUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -178,19 +178,18 @@ public static int ReadFully(Stream stream, byte[] b)

/// <summary>
/// Same as the normal InputStream#read(byte[], int, int), but tries to ensure
/// that the buffer is filled completely if possible, i.e. b.remaining()
/// returns 0.
/// If the end of file is reached before any bytes are Read, returns -1.
/// that the entire len number of bytes is read
///
/// If the end of file is reached before any bytes are read, returns -1.
/// If the end of the file is reached after some bytes are read, returns the
/// number of bytes read. If the end of the file isn't reached before the
/// buffer has no more remaining capacity, will return the number of bytes
/// that were read.
/// buffer has no more remaining capacity, will return len bytes
/// </summary>
/// <param name="stream">the stream from which the data is read.</param>
/// <param name="b">the buffer into which the data is read.</param>
/// <param name="off">the start offset in array b at which the data is written.</param>
/// <param name="len">the maximum number of bytes to read.</param>
/// <returns></returns>
/// <returns>the number of bytes read or -1 if no bytes were read</returns>
public static int ReadFully(Stream stream, byte[] b, int off, int len)
{
int total = 0;
Expand Down
9 changes: 9 additions & 0 deletions ooxml/XSSF/Streaming/SXSSFCell.cs
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,15 @@ public ICell CopyCellTo(int targetIndex)

public void RemoveCellComment()
{
IComment comment = this.CellComment;
if (comment != null)
{
CellAddress ref1 = new CellAddress(RowIndex, ColumnIndex);
XSSFSheet sh = ((SXSSFSheet)Sheet)._sh;
sh.GetCommentsTable(false).RemoveComment(ref1);
sh.GetVMLDrawing(false).RemoveCommentShape(RowIndex, ColumnIndex);
}

RemoveProperty(Property.COMMENT);
}

Expand Down
7 changes: 7 additions & 0 deletions testcases/main/HSSF/UserModel/TestHSSFWorkbook.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1473,5 +1473,12 @@ public void TestWriteToNewFile()
Assert.AreEqual(3, wb.NumberOfSheets);
wb.Close();
}


[Test]
public void TestBug854()
{
Assert.DoesNotThrow(() => HSSFTestDataSamples.OpenSampleWorkbook("ATM.xls"));
}
}
}
103 changes: 103 additions & 0 deletions testcases/ooxml/XSSF/UserModel/TestXSSFComment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,109 @@ public void Bug57838DeleteRowsWthCommentsBug()
wb.Close();
}

[Test]
public void TestRemoveXSSFCellComment()
{
IWorkbook wb = new XSSFWorkbook();
try
{
ISheet sheet = wb.CreateSheet();
IRow row = sheet.CreateRow(1);
ICell cell = row.CreateCell(0);
cell.SetCellValue("test");

IDrawing drawing = sheet.CreateDrawingPatriarch();
ICreationHelper factory = wb.GetCreationHelper();
// When the comment box is visible, have it show in a 1x3 space
IClientAnchor anchor = factory.CreateClientAnchor();
anchor.Col1 = cell.ColumnIndex;
anchor.Col2 = cell.ColumnIndex + 1;
anchor.Row1 = row.RowNum;
anchor.Row2 = row.RowNum + 3;
// Create the comment and set the text+author
IComment comment = drawing.CreateCellComment(anchor);
IRichTextString str = factory.CreateRichTextString("Hello, World!");
comment.String = str;
comment.Author = "Apache POI";

cell.CellComment = comment;

var exCellComment = sheet.GetCellComment(new CellAddress(1, 0));
Assert.IsNotNull(exCellComment);
Assert.IsTrue(exCellComment.String.String.Equals("Hello, World!"));
Assert.IsTrue(exCellComment.Author.Equals("Apache POI"));

cell.RemoveCellComment();
exCellComment = sheet.GetCellComment(new CellAddress(1, 0));
Assert.IsNull(exCellComment);

IComment newComment = drawing.CreateCellComment(anchor);
newComment.String = str;
newComment.Author = "Apache POI";
cell.CellComment = newComment;

exCellComment = sheet.GetCellComment(new CellAddress(1, 0));
Assert.NotNull(exCellComment);
Assert.IsTrue(exCellComment.String.String.Equals("Hello, World!"));
Assert.IsTrue(exCellComment.Author.Equals("Apache POI"));
}
finally
{
wb.Close();
}
}

[Test]
public void TestRemoveSXSSFCellComment()
{
IWorkbook wb = new SXSSFWorkbook();
try
{
ISheet sheet = wb.CreateSheet();
IRow row = sheet.CreateRow(1);
ICell cell = row.CreateCell(0);
cell.SetCellValue("test");

IDrawing drawing = sheet.CreateDrawingPatriarch();
ICreationHelper factory = wb.GetCreationHelper();
// When the comment box is visible, have it show in a 1x3 space
IClientAnchor anchor = factory.CreateClientAnchor();
anchor.Col1 = cell.ColumnIndex;
anchor.Col2 = cell.ColumnIndex + 1;
anchor.Row1 = row.RowNum;
anchor.Row2 = row.RowNum + 3;
// Create the comment and set the text+author
IComment comment = drawing.CreateCellComment(anchor);
IRichTextString str = factory.CreateRichTextString("Hello, World!");
comment.String = str;
comment.Author = "Apache POI";

cell.CellComment = comment;

var exCellComment = sheet.GetCellComment(new CellAddress(1, 0));
Assert.IsNotNull(exCellComment);
Assert.IsTrue(exCellComment.String.String.Equals("Hello, World!"));
Assert.IsTrue(exCellComment.Author.Equals("Apache POI"));

cell.RemoveCellComment();
exCellComment = sheet.GetCellComment(new CellAddress(1, 0));
Assert.IsNull(exCellComment);

IComment newComment = drawing.CreateCellComment(anchor);
newComment.String = str;
newComment.Author = "Apache POI";
cell.CellComment = newComment;

exCellComment = sheet.GetCellComment(new CellAddress(1, 0));
Assert.NotNull(exCellComment);
Assert.IsTrue(exCellComment.String.String.Equals("Hello, World!"));
Assert.IsTrue(exCellComment.Author.Equals("Apache POI"));
}
finally
{
wb.Close();
}
}
}

}
Binary file added testcases/test-data/spreadsheet/ATM.xls
Binary file not shown.

0 comments on commit fc9f45d

Please sign in to comment.