ASF Bugzilla – Attachment 31539 Details for
Bug 56424
Comments constructor doesn't set row and column of the VML shape
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
An example of problematic file creation.
POIXSSFBugTest.java (text/x-java-source), 3.23 KB, created by
Vincent Boulanger
on 2014-04-17 14:23:06 UTC
(
hide
)
Description:
An example of problematic file creation.
Filename:
MIME Type:
Creator:
Vincent Boulanger
Created:
2014-04-17 14:23:06 UTC
Size:
3.23 KB
patch
obsolete
>package org.apache.poi.xssf.usermodel; > >import java.io.File; >import java.io.FileInputStream; >import java.io.FileOutputStream; > >import org.apache.poi.openxml4j.opc.OPCPackage; >import org.apache.poi.ss.usermodel.Cell; >import org.apache.poi.ss.usermodel.ClientAnchor; >import org.apache.poi.ss.usermodel.Comment; >import org.apache.poi.ss.usermodel.CreationHelper; >import org.apache.poi.ss.usermodel.Drawing; >import org.apache.poi.ss.usermodel.RichTextString; >import org.apache.poi.ss.usermodel.Row; >import org.apache.poi.ss.usermodel.Sheet; >import org.apache.poi.xssf.streaming.SXSSFSheet; >import org.apache.poi.xssf.streaming.SXSSFWorkbook; >import org.junit.Assert; >import org.junit.Test; > >/** > * Cas de test pour un bug de commentaires sous POI 3.10 FINAL. > * > * @author VBG > */ >public class POIXSSFBugTest { > > private static final int LINE_WINDOW = 100; > > /** > * Test unitaire du service Element > */ > @Test > public void testInsertComments() throws Exception { > > SXSSFWorkbook workbook = new SXSSFWorkbook(LINE_WINDOW); > SXSSFSheet sheet = (SXSSFSheet) workbook.createSheet("0"); > > Drawing drawing = ((org.apache.poi.ss.usermodel.Sheet) sheet).createDrawingPatriarch(); > // Drawing drawing = sheet.createDrawingPatriarch(); > int noOfRows = 50; > String comment = "message "; > > for (int i = 0; i < noOfRows; i++) { > Row row = sheet.createRow(i); > Cell cell = row.createCell(0, Cell.CELL_TYPE_STRING); > insertComment(drawing, cell, comment + i); > } > > // assert the comments are created properly > for (int i = 0; i < noOfRows; i++) { > Assert.assertEquals(comment + i, sheet.getRow(i).getCell(0).getCellComment().getString().getString()); > } > > // save the workbook in a temporary file > File file = new File(System.getProperty("java.io.tmpdir") + File.separatorChar + "test_comments.xlsx"); > FileOutputStream fs = new FileOutputStream(file); > try { > // sheet.getWorkbook().write(fs); > workbook.write(fs); > } finally { > fs.close(); > } > workbook.dispose(); > > // recreate the workbook from the saved file > XSSFWorkbook savedWorkbook = new XSSFWorkbook(new FileInputStream(file)); > Sheet savedSheet = savedWorkbook.getSheetAt(0); > > OPCPackage pack = savedWorkbook.getPackage(); > // assert that the comments are saved properly > for (int i = 0; i < noOfRows; i++) { > Assert.assertEquals(comment + i, savedSheet.getRow(i).getCell(0).getCellComment().getString().getString()); > } > } > > private void insertComment(Drawing drawing, Cell cell, String message) { > CreationHelper factory = cell.getSheet().getWorkbook().getCreationHelper(); > > ClientAnchor anchor = factory.createClientAnchor(); > anchor.setCol1(cell.getColumnIndex()); > anchor.setCol2(cell.getColumnIndex() + 1); > anchor.setRow1(cell.getRowIndex()); > anchor.setRow2(cell.getRowIndex() + 1); > anchor.setDx1(100); > anchor.setDx2(100); > anchor.setDy1(100); > anchor.setDy2(100); > > Comment comment = drawing.createCellComment(anchor); > > RichTextString str = factory.createRichTextString(message); > comment.setString(str); > comment.setAuthor("toto"); > > // Not necessary in V3.9 > // comment.setColumn(cell.getColumnIndex()); > // comment.setRow(cell.getRowIndex()); > > cell.setCellComment(comment); > } >}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 56424
: 31539