ASF Bugzilla – Attachment 36565 Details for
Bug 63402
XSSFSheet.removeTable corrupts the workbook
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
JUnit test case to illustrate bug 63401
file_63402.txt (text/plain), 4.38 KB, created by
David Gauntt
on 2019-05-04 17:17:35 UTC
(
hide
)
Description:
JUnit test case to illustrate bug 63401
Filename:
MIME Type:
Creator:
David Gauntt
Created:
2019-05-04 17:17:35 UTC
Size:
4.38 KB
patch
obsolete
>package org.apache.poi.ss.unfixedBugs; > >import static org.junit.Assert.assertEquals; >import static org.junit.Assert.assertTrue; > >import java.awt.Desktop; >import java.io.File; >import java.io.FileOutputStream; >import java.io.IOException; >import java.io.OutputStream; >import java.util.Locale; > >import org.apache.poi.ss.SpreadsheetVersion; >import org.apache.poi.ss.util.AreaReference; >import org.apache.poi.ss.util.CellReference; >import org.apache.poi.xssf.usermodel.XSSFCell; >import org.apache.poi.xssf.usermodel.XSSFName; >import org.apache.poi.xssf.usermodel.XSSFRow; >import org.apache.poi.xssf.usermodel.XSSFSheet; >import org.apache.poi.xssf.usermodel.XSSFTable; >import org.apache.poi.xssf.usermodel.XSSFWorkbook; >import org.junit.After; >import org.junit.Before; >import org.junit.Test; > >public class TestXSSFSheetRemoveTable { > final File resultDir=new File("build/custom-reports-test"); > XSSFWorkbook workbook=null; > XSSFSheet sheet0=null; > String fileName=null; > > public TestXSSFSheetRemoveTable() { > resultDir.mkdirs(); > } > > /** > * This creates a workbook with two worksheets. The second worksheet has > * a range named "Table1", and two tables named "Table2" and "Table3" > */ > @Before > public void setup() { > workbook = new XSSFWorkbook(); > sheet0 = workbook.createSheet(); > } > > > /** > * This method writes the workbook to resultDir/fileName. > */ > @After > public void cleanup() { > final String procName="TestXSSFSheetRemoveTable.cleanup"; > if (workbook == null) { > System.out.println(String.format(Locale.ROOT,"%s: workbook==null",procName)); > return; > } > > if(fileName==null) { > System.out.println(String.format(Locale.ROOT, "%s: fileName==null",procName)); > return; > } > > final File file=new File(resultDir,fileName); > try (OutputStream fileOut = new FileOutputStream(file)) { > workbook.write(fileOut); > System.out.println(String.format(Locale.ROOT, "%s: test file written to %s",procName,file.getAbsolutePath())); > } catch (Exception e) { > System.err.println(e.getMessage()); > } finally { > try { > workbook.close(); > } catch (IOException e) { > // TODO Auto-generated catch block > e.printStackTrace(); > } > } > } > > /** > * Delete table2, and create a named range in sheet0; it should automatically be assigned the name "Table4" > */ > @Test > public void testRemoveTable() { > final String procName="testTable"; > fileName=procName+".xlsx"; > > // Create the table > final XSSFTable table1=addTable(sheet0,3,0,2,4); > final XSSFTable table2=addTable(sheet0,7,1,3,5); > sheet0.removeTable(table1); > } > > /** > * Add a table in the specified location and size, and fill the cells with some values. > * <p> > * The header of the first column will be the name of the table > * > * @param sheet > * @param nRow > * @param nCol > * @param nNumRows > * @param nNumCols > * @return > */ > private static XSSFTable addTable(XSSFSheet sheet,int nRow, int nCol, int nNumRows, int nNumCols) { > final String procName="addTable"; > for (int i = 0; i < nNumRows; i++) { > XSSFRow row = sheet.createRow(i + nRow); > for (int j = 0; j < nNumCols; j++) { > XSSFCell localXSSFCell = row.createCell(j + nCol); > if (i == 0) { > localXSSFCell.setCellValue(String.format("Col%d", j + 1)); > } else { > localXSSFCell.setCellValue(String.format("(%d,%d)", i + 1, j + 1)); > } > } > } > final int nLastRow=nRow+nNumRows-1; > final int nLastCol=nCol+nNumCols-1; > final CellReference upperLeft = new CellReference(nRow,nCol); > final CellReference lowerRight = new CellReference(nLastRow,nLastCol ); > final AreaReference area = new AreaReference(upperLeft, lowerRight, SpreadsheetVersion.EXCEL2007); > final XSSFTable table= sheet.createTable(area); > sheet.getRow(nRow).getCell(nCol).setCellValue(table.getDisplayName()); > > return table; > } > > >}
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 63402
:
36565
|
36638