提交 0c08215d 编写于 作者: T Tony Qu

Merge branch 'master' of https://github.com/nissl-lab/npoi

...@@ -30,7 +30,7 @@ public static CT_CellProtection Parse(XmlNode node, XmlNamespaceManager namespac ...@@ -30,7 +30,7 @@ public static CT_CellProtection Parse(XmlNode node, XmlNamespaceManager namespac
if (node == null) if (node == null)
return null; return null;
CT_CellProtection ctObj = new CT_CellProtection(); CT_CellProtection ctObj = new CT_CellProtection();
ctObj.locked = XmlHelper.ReadBool(node.Attributes["locked"]); ctObj.locked = XmlHelper.ReadBool(node.Attributes["locked"], true);
ctObj.hidden = XmlHelper.ReadBool(node.Attributes["hidden"]); ctObj.hidden = XmlHelper.ReadBool(node.Attributes["hidden"]);
return ctObj; return ctObj;
} }
......
...@@ -310,8 +310,8 @@ public NPOIFSFileSystem(Stream stream) ...@@ -310,8 +310,8 @@ public NPOIFSFileSystem(Stream stream)
data.Write(headerBuffer.Buffer); data.Write(headerBuffer.Buffer);
data.Position = headerBuffer.Length; data.Position = headerBuffer.Length;
//IOUtils.ReadFully(channel, data); //IOUtils.ReadFully(channel, data.Buffer);
data.Position += IOUtils.ReadFully(channel, data.Buffer, data.Position, (int)channel.Length); data.Position += IOUtils.ReadFully(channel, data.Buffer, data.Position, (int)maxSize);
success = true; success = true;
// Turn it into a DataSource // Turn it into a DataSource
......
...@@ -178,19 +178,18 @@ public static int ReadFully(Stream stream, byte[] b) ...@@ -178,19 +178,18 @@ public static int ReadFully(Stream stream, byte[] b)
/// <summary> /// <summary>
/// Same as the normal InputStream#read(byte[], int, int), but tries to ensure /// 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() /// that the entire len number of bytes is read
/// returns 0. ///
/// If the end of file is reached before any bytes are Read, returns -1. /// 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 /// 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 /// 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 /// buffer has no more remaining capacity, will return len bytes
/// that were read.
/// </summary> /// </summary>
/// <param name="stream">the stream from which the data is read.</param> /// <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="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="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> /// <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) public static int ReadFully(Stream stream, byte[] b, int off, int len)
{ {
int total = 0; int total = 0;
......
...@@ -418,6 +418,15 @@ public ICell CopyCellTo(int targetIndex) ...@@ -418,6 +418,15 @@ public ICell CopyCellTo(int targetIndex)
public void RemoveCellComment() 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); RemoveProperty(Property.COMMENT);
} }
......
...@@ -806,7 +806,6 @@ public bool IsLocked ...@@ -806,7 +806,6 @@ public bool IsLocked
{ {
get get
{ {
if (!_cellXf.IsSetProtection()) if (!_cellXf.IsSetProtection())
{ {
return true; return true;
......
...@@ -1473,5 +1473,12 @@ public void TestWriteToNewFile() ...@@ -1473,5 +1473,12 @@ public void TestWriteToNewFile()
Assert.AreEqual(3, wb.NumberOfSheets); Assert.AreEqual(3, wb.NumberOfSheets);
wb.Close(); wb.Close();
} }
[Test]
public void TestBug854()
{
Assert.DoesNotThrow(() => HSSFTestDataSamples.OpenSampleWorkbook("ATM.xls"));
}
} }
} }
...@@ -724,9 +724,24 @@ public void TestGetSetLocked() ...@@ -724,9 +724,24 @@ public void TestGetSetLocked()
cellStyle.IsLocked = (false); cellStyle.IsLocked = (false);
Assert.IsFalse(cellStyle.IsLocked); Assert.IsFalse(cellStyle.IsLocked);
} }
[Test]
public void TestBug738()
{
XSSFWorkbook wb = XSSFTestDataSamples.OpenSampleWorkbook("738.xlsx");
ISheet sheet = wb.GetSheet("Sheet1");
IRow row = sheet.GetRow(0);
ICell cell = row.GetCell(0);
Assert.IsTrue(cell.CellStyle.IsLocked);
cell.CellStyle.IsLocked = true;
Assert.IsTrue(cell.CellStyle.IsLocked);
Assert.IsTrue(cell.CellStyle.IsHidden);
}
[Test] [Test]
public void TestGetSetIndent() public void TestGetSetIndent()
{ {
Assert.AreEqual((short)0, cellStyle.Indention); Assert.AreEqual((short)0, cellStyle.Indention);
cellStyle.Indention = ((short)3); cellStyle.Indention = ((short)3);
Assert.AreEqual((short)3, cellStyle.Indention); Assert.AreEqual((short)3, cellStyle.Indention);
......
...@@ -316,6 +316,109 @@ public void Bug57838DeleteRowsWthCommentsBug() ...@@ -316,6 +316,109 @@ public void Bug57838DeleteRowsWthCommentsBug()
wb.Close(); 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();
}
}
} }
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册