use of org.apache.poi.ss.util.CellAddress in project poi by apache.
the class TestXSSFSheetShiftRows method testBug57828_OnlyOneCommentShiftedInRow.
/** Shifting rows with cell comments only shifts comments from first such cell. Other cell comments not shifted */
@Test
public void testBug57828_OnlyOneCommentShiftedInRow() throws IOException {
XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("57828.xlsx");
XSSFSheet sheet = wb.getSheetAt(0);
Comment comment1 = sheet.getCellComment(new CellAddress(2, 1));
assertNotNull(comment1);
Comment comment2 = sheet.getCellComment(new CellAddress(2, 2));
assertNotNull(comment2);
Comment comment3 = sheet.getCellComment(new CellAddress(1, 1));
assertNull("NO comment in (1,1) and it should be null", comment3);
sheet.shiftRows(2, 2, -1);
comment3 = sheet.getCellComment(new CellAddress(1, 1));
assertNotNull("Comment in (2,1) moved to (1,1) so its not null now.", comment3);
comment1 = sheet.getCellComment(new CellAddress(2, 1));
assertNull("No comment currently in (2,1) and hence it is null", comment1);
comment2 = sheet.getCellComment(new CellAddress(1, 2));
assertNotNull("Comment in (2,2) should have moved as well because of shift rows. But its not", comment2);
wb.close();
}
use of org.apache.poi.ss.util.CellAddress in project poi by apache.
the class TestXSSFSheetShiftRows method testBug56017.
/** Shifting rows with comment result - Unreadable content error and comment deletion */
@Test
public void testBug56017() throws IOException {
Workbook wb = XSSFTestDataSamples.openSampleWorkbook("56017.xlsx");
Sheet sheet = wb.getSheetAt(0);
Comment comment = sheet.getCellComment(new CellAddress(0, 0));
assertNotNull(comment);
assertEquals("Amdocs", comment.getAuthor());
assertEquals("Amdocs:\ntest\n", comment.getString().getString());
sheet.shiftRows(0, 1, 1);
// comment in row 0 is gone
comment = sheet.getCellComment(new CellAddress(0, 0));
assertNull(comment);
// comment is now in row 1
comment = sheet.getCellComment(new CellAddress(1, 0));
assertNotNull(comment);
assertEquals("Amdocs", comment.getAuthor());
assertEquals("Amdocs:\ntest\n", comment.getString().getString());
Workbook wbBack = XSSFTestDataSamples.writeOutAndReadBack(wb);
wb.close();
assertNotNull(wbBack);
Sheet sheetBack = wbBack.getSheetAt(0);
// comment in row 0 is gone
comment = sheetBack.getCellComment(new CellAddress(0, 0));
assertNull(comment);
// comment is now in row 1
comment = sheetBack.getCellComment(new CellAddress(1, 0));
assertNotNull(comment);
assertEquals("Amdocs", comment.getAuthor());
assertEquals("Amdocs:\ntest\n", comment.getString().getString());
wbBack.close();
}
use of org.apache.poi.ss.util.CellAddress in project poi by apache.
the class TestXSSFSheet method getActiveCell.
@Test
public void getActiveCell() throws IOException {
XSSFWorkbook workbook = new XSSFWorkbook();
XSSFSheet sheet = workbook.createSheet();
CellAddress R5 = new CellAddress("R5");
sheet.setActiveCell(R5);
assertEquals(R5, sheet.getActiveCell());
workbook.close();
}
use of org.apache.poi.ss.util.CellAddress in project poi by apache.
the class BaseTestCellComment method getAddress.
@Test
public void getAddress() {
Workbook wb = _testDataProvider.createWorkbook();
Sheet sh = wb.createSheet();
CreationHelper factory = wb.getCreationHelper();
Drawing<?> patriarch = sh.createDrawingPatriarch();
Comment comment = patriarch.createCellComment(factory.createClientAnchor());
assertEquals(CellAddress.A1, comment.getAddress());
Cell C2 = sh.createRow(1).createCell(2);
C2.setCellComment(comment);
assertEquals(new CellAddress("C2"), comment.getAddress());
}
use of org.apache.poi.ss.util.CellAddress in project poi by apache.
the class BaseTestCellComment method create.
@Test
public final void create() throws IOException {
String cellText = "Hello, World";
String commentText = "We can set comments in POI";
String commentAuthor = "Apache Software Foundation";
int cellRow = 3;
int cellColumn = 1;
Workbook wb1 = _testDataProvider.createWorkbook();
CreationHelper factory = wb1.getCreationHelper();
Sheet sheet = wb1.createSheet();
assertNull(sheet.getCellComment(new CellAddress(cellRow, cellColumn)));
Cell cell = sheet.createRow(cellRow).createCell(cellColumn);
cell.setCellValue(factory.createRichTextString(cellText));
assertNull(cell.getCellComment());
assertNull(sheet.getCellComment(new CellAddress(cellRow, cellColumn)));
Drawing<?> patr = sheet.createDrawingPatriarch();
ClientAnchor anchor = factory.createClientAnchor();
anchor.setCol1(2);
anchor.setCol2(5);
anchor.setRow1(1);
anchor.setRow2(2);
Comment comment = patr.createCellComment(anchor);
assertFalse(comment.isVisible());
comment.setVisible(true);
assertTrue(comment.isVisible());
RichTextString string1 = factory.createRichTextString(commentText);
comment.setString(string1);
comment.setAuthor(commentAuthor);
cell.setCellComment(comment);
assertNotNull(cell.getCellComment());
assertNotNull(sheet.getCellComment(new CellAddress(cellRow, cellColumn)));
//verify our settings
assertEquals(commentAuthor, comment.getAuthor());
assertEquals(commentText, comment.getString().getString());
assertEquals(cellRow, comment.getRow());
assertEquals(cellColumn, comment.getColumn());
Workbook wb2 = _testDataProvider.writeOutAndReadBack(wb1);
wb1.close();
sheet = wb2.getSheetAt(0);
cell = sheet.getRow(cellRow).getCell(cellColumn);
comment = cell.getCellComment();
assertNotNull(comment);
assertEquals(commentAuthor, comment.getAuthor());
assertEquals(commentText, comment.getString().getString());
assertEquals(cellRow, comment.getRow());
assertEquals(cellColumn, comment.getColumn());
assertTrue(comment.isVisible());
// Change slightly, and re-test
comment.setString(factory.createRichTextString("New Comment Text"));
comment.setVisible(false);
Workbook wb3 = _testDataProvider.writeOutAndReadBack(wb2);
wb2.close();
sheet = wb3.getSheetAt(0);
cell = sheet.getRow(cellRow).getCell(cellColumn);
comment = cell.getCellComment();
assertNotNull(comment);
assertEquals(commentAuthor, comment.getAuthor());
assertEquals("New Comment Text", comment.getString().getString());
assertEquals(cellRow, comment.getRow());
assertEquals(cellColumn, comment.getColumn());
assertFalse(comment.isVisible());
// Test Comment.equals and Comment.hashCode
assertEquals(comment, cell.getCellComment());
assertEquals(comment.hashCode(), cell.getCellComment().hashCode());
wb3.close();
}
Aggregations