Reformat code somewhat
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1795962 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
7881d05743
commit
8564aa7bb6
@ -110,7 +110,7 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Named ranges had the right reference, but
|
* Named ranges had the right reference, but
|
||||||
* the wrong sheet name
|
* the wrong sheet name
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void bug45430() throws IOException {
|
public void bug45430() throws IOException {
|
||||||
@ -224,9 +224,9 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Excel will sometimes write a button with a textbox
|
* Excel will sometimes write a button with a textbox
|
||||||
* containing >br< (not closed!).
|
* containing >br< (not closed!).
|
||||||
* Clearly Excel shouldn't do this, but test that we can
|
* Clearly Excel shouldn't do this, but test that we can
|
||||||
* read the file despite the naughtyness
|
* read the file despite the naughtyness
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void bug49020() throws IOException {
|
public void bug49020() throws IOException {
|
||||||
@ -247,7 +247,7 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Names which are defined with a Sheet
|
* Names which are defined with a Sheet
|
||||||
* should return that sheet index properly
|
* should return that sheet index properly
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void bug48923() throws IOException {
|
public void bug48923() throws IOException {
|
||||||
@ -284,10 +284,10 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Problem with evaluation formulas due to
|
* Problem with evaluation formulas due to
|
||||||
* NameXPtgs.
|
* NameXPtgs.
|
||||||
* Blows up on:
|
* Blows up on:
|
||||||
* IF(B6= (ROUNDUP(B6,0) + ROUNDDOWN(B6,0))/2, MROUND(B6,2),ROUND(B6,0))
|
* IF(B6= (ROUNDUP(B6,0) + ROUNDDOWN(B6,0))/2, MROUND(B6,2),ROUND(B6,0))
|
||||||
*
|
* <p>
|
||||||
* TODO: delete this test case when MROUND and VAR are implemented
|
* TODO: delete this test case when MROUND and VAR are implemented
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
@ -299,14 +299,14 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
|
|||||||
|
|
||||||
// Try each cell individually
|
// Try each cell individually
|
||||||
XSSFFormulaEvaluator eval = new XSSFFormulaEvaluator(wb);
|
XSSFFormulaEvaluator eval = new XSSFFormulaEvaluator(wb);
|
||||||
for(int i=0; i<wb.getNumberOfSheets(); i++) {
|
for (int i = 0; i < wb.getNumberOfSheets(); i++) {
|
||||||
Sheet s = wb.getSheetAt(i);
|
Sheet s = wb.getSheetAt(i);
|
||||||
for(Row r : s) {
|
for (Row r : s) {
|
||||||
for(Cell c : r) {
|
for (Cell c : r) {
|
||||||
if(c.getCellTypeEnum() == CellType.FORMULA) {
|
if (c.getCellTypeEnum() == CellType.FORMULA) {
|
||||||
CellValue cv = eval.evaluate(c);
|
CellValue cv = eval.evaluate(c);
|
||||||
|
|
||||||
if(cv.getCellTypeEnum() == CellType.NUMERIC) {
|
if (cv.getCellTypeEnum() == CellType.NUMERIC) {
|
||||||
// assert that the calculated value agrees with
|
// assert that the calculated value agrees with
|
||||||
// the cached formula result calculated by Excel
|
// the cached formula result calculated by Excel
|
||||||
String formula = c.getCellFormula();
|
String formula = c.getCellFormula();
|
||||||
@ -328,7 +328,7 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Foreground colours should be found even if
|
* Foreground colours should be found even if
|
||||||
* a theme is used
|
* a theme is used
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void bug48779() throws IOException {
|
public void bug48779() throws IOException {
|
||||||
@ -368,7 +368,7 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Ensure General and @ format are working properly
|
* Ensure General and @ format are working properly
|
||||||
* for integers
|
* for integers
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void bug47490() throws IOException {
|
public void bug47490() throws IOException {
|
||||||
@ -406,12 +406,12 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
|
|||||||
* output as an .xlsx file) that have two issues:
|
* output as an .xlsx file) that have two issues:
|
||||||
* 1. The Content Type part name is lower-case: [content_types].xml
|
* 1. The Content Type part name is lower-case: [content_types].xml
|
||||||
* 2. The file appears to use backslashes as path separators
|
* 2. The file appears to use backslashes as path separators
|
||||||
*
|
* <p>
|
||||||
* The OPC spec tolerates both of these peculiarities, so does POI
|
* The OPC spec tolerates both of these peculiarities, so does POI
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void bug49609() throws IOException {
|
public void bug49609() throws IOException {
|
||||||
XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("49609.xlsx");
|
XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("49609.xlsx");
|
||||||
assertEquals("FAM", wb.getSheetName(0));
|
assertEquals("FAM", wb.getSheetName(0));
|
||||||
assertEquals("Cycle", wb.getSheetAt(0).getRow(0).getCell(1).getStringCellValue());
|
assertEquals("Cycle", wb.getSheetAt(0).getRow(0).getCell(1).getStringCellValue());
|
||||||
wb.close();
|
wb.close();
|
||||||
@ -420,7 +420,7 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void bug49783() throws IOException {
|
public void bug49783() throws IOException {
|
||||||
Workbook wb = XSSFTestDataSamples.openSampleWorkbook("49783.xlsx");
|
Workbook wb = XSSFTestDataSamples.openSampleWorkbook("49783.xlsx");
|
||||||
Sheet sheet = wb.getSheetAt(0);
|
Sheet sheet = wb.getSheetAt(0);
|
||||||
FormulaEvaluator evaluator = wb.getCreationHelper().createFormulaEvaluator();
|
FormulaEvaluator evaluator = wb.getCreationHelper().createFormulaEvaluator();
|
||||||
Cell cell;
|
Cell cell;
|
||||||
@ -447,10 +447,10 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Creating a rich string of "hello world" and applying
|
* Creating a rich string of "hello world" and applying
|
||||||
* a font to characters 1-5 means we have two strings,
|
* a font to characters 1-5 means we have two strings,
|
||||||
* "hello" and " world". As such, we need to apply
|
* "hello" and " world". As such, we need to apply
|
||||||
* preserve spaces to the 2nd bit, lest we end up
|
* preserve spaces to the 2nd bit, lest we end up
|
||||||
* with something like "helloworld" !
|
* with something like "helloworld" !
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void bug49941() throws IOException {
|
public void bug49941() throws IOException {
|
||||||
@ -544,7 +544,7 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
|
|||||||
wb.write(b2);
|
wb.write(b2);
|
||||||
wb.write(b3);
|
wb.write(b3);
|
||||||
|
|
||||||
for(byte[] data : new byte[][] {
|
for (byte[] data : new byte[][]{
|
||||||
b1.toByteArray(), b2.toByteArray(), b3.toByteArray()
|
b1.toByteArray(), b2.toByteArray(), b3.toByteArray()
|
||||||
}) {
|
}) {
|
||||||
ByteArrayInputStream bais = new ByteArrayInputStream(data);
|
ByteArrayInputStream bais = new ByteArrayInputStream(data);
|
||||||
@ -631,9 +631,9 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void validateCells(XSSFSheet sheet) {
|
private void validateCells(XSSFSheet sheet) {
|
||||||
for(Row row : sheet) {
|
for (Row row : sheet) {
|
||||||
// trigger handling
|
// trigger handling
|
||||||
((XSSFRow)row).onDocumentWrite();
|
((XSSFRow) row).onDocumentWrite();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -643,9 +643,9 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
|
|||||||
FormulaEvaluator formulaEvaluator = wb.getCreationHelper().createFormulaEvaluator();
|
FormulaEvaluator formulaEvaluator = wb.getCreationHelper().createFormulaEvaluator();
|
||||||
|
|
||||||
Sheet sheet = wb.getSheetAt(0);
|
Sheet sheet = wb.getSheetAt(0);
|
||||||
for(Row row : sheet){
|
for (Row row : sheet) {
|
||||||
for(Cell cell : row){
|
for (Cell cell : row) {
|
||||||
if(cell.getCellTypeEnum() == CellType.FORMULA){
|
if (cell.getCellTypeEnum() == CellType.FORMULA) {
|
||||||
formulaEvaluator.evaluateInCell(cell); // caused NPE on some cells
|
formulaEvaluator.evaluateInCell(cell); // caused NPE on some cells
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -741,8 +741,8 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* When the cell background colour is set with one of the first
|
* When the cell background colour is set with one of the first
|
||||||
* two columns of the theme colour palette, the colours are
|
* two columns of the theme colour palette, the colours are
|
||||||
* shades of white or black.
|
* shades of white or black.
|
||||||
* For those cases, ensure we don't break on reading the colour
|
* For those cases, ensure we don't break on reading the colour
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
@ -750,12 +750,12 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
|
|||||||
Workbook wb = XSSFTestDataSamples.openSampleWorkbook("50299.xlsx");
|
Workbook wb = XSSFTestDataSamples.openSampleWorkbook("50299.xlsx");
|
||||||
|
|
||||||
// Check all the colours
|
// Check all the colours
|
||||||
for(int sn=0; sn<wb.getNumberOfSheets(); sn++) {
|
for (int sn = 0; sn < wb.getNumberOfSheets(); sn++) {
|
||||||
Sheet s = wb.getSheetAt(sn);
|
Sheet s = wb.getSheetAt(sn);
|
||||||
for(Row r : s) {
|
for (Row r : s) {
|
||||||
for(Cell c : r) {
|
for (Cell c : r) {
|
||||||
CellStyle cs = c.getCellStyle();
|
CellStyle cs = c.getCellStyle();
|
||||||
if(cs != null) {
|
if (cs != null) {
|
||||||
cs.getFillForegroundColor();
|
cs.getFillForegroundColor();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -766,9 +766,9 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
|
|||||||
// Check that we get back foreground=0 for the theme colours,
|
// Check that we get back foreground=0 for the theme colours,
|
||||||
// and background=64 for the auto colouring
|
// and background=64 for the auto colouring
|
||||||
Sheet s = wb.getSheetAt(0);
|
Sheet s = wb.getSheetAt(0);
|
||||||
assertEquals(0, s.getRow(0).getCell(8).getCellStyle().getFillForegroundColor());
|
assertEquals(0, s.getRow(0).getCell(8).getCellStyle().getFillForegroundColor());
|
||||||
assertEquals(64, s.getRow(0).getCell(8).getCellStyle().getFillBackgroundColor());
|
assertEquals(64, s.getRow(0).getCell(8).getCellStyle().getFillBackgroundColor());
|
||||||
assertEquals(0, s.getRow(1).getCell(8).getCellStyle().getFillForegroundColor());
|
assertEquals(0, s.getRow(1).getCell(8).getCellStyle().getFillForegroundColor());
|
||||||
assertEquals(64, s.getRow(1).getCell(8).getCellStyle().getFillBackgroundColor());
|
assertEquals(64, s.getRow(1).getCell(8).getCellStyle().getFillBackgroundColor());
|
||||||
|
|
||||||
wb.close();
|
wb.close();
|
||||||
@ -798,7 +798,7 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* If the border colours are set with themes, then we
|
* If the border colours are set with themes, then we
|
||||||
* should still be able to get colours
|
* should still be able to get colours
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void bug50846() throws IOException {
|
public void bug50846() throws IOException {
|
||||||
@ -827,8 +827,8 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Fonts where their colours come from the theme rather
|
* Fonts where their colours come from the theme rather
|
||||||
* then being set explicitly still should allow the
|
* then being set explicitly still should allow the
|
||||||
* fetching of the RGB.
|
* fetching of the RGB.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void bug50784() throws IOException {
|
public void bug50784() throws IOException {
|
||||||
@ -838,28 +838,28 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
|
|||||||
|
|
||||||
// Column 1 has a font with regular colours
|
// Column 1 has a font with regular colours
|
||||||
XSSFCell cr = r.getCell(1);
|
XSSFCell cr = r.getCell(1);
|
||||||
XSSFFont fr = wb.getFontAt( cr.getCellStyle().getFontIndex() );
|
XSSFFont fr = wb.getFontAt(cr.getCellStyle().getFontIndex());
|
||||||
XSSFColor colr = fr.getXSSFColor();
|
XSSFColor colr = fr.getXSSFColor();
|
||||||
// No theme, has colours
|
// No theme, has colours
|
||||||
assertEquals(0, colr.getTheme());
|
assertEquals(0, colr.getTheme());
|
||||||
assertNotNull( colr.getRGB() );
|
assertNotNull(colr.getRGB());
|
||||||
|
|
||||||
// Column 0 has a font with colours from a theme
|
// Column 0 has a font with colours from a theme
|
||||||
XSSFCell ct = r.getCell(0);
|
XSSFCell ct = r.getCell(0);
|
||||||
XSSFFont ft = wb.getFontAt( ct.getCellStyle().getFontIndex() );
|
XSSFFont ft = wb.getFontAt(ct.getCellStyle().getFontIndex());
|
||||||
XSSFColor colt = ft.getXSSFColor();
|
XSSFColor colt = ft.getXSSFColor();
|
||||||
// Has a theme, which has the colours on it
|
// Has a theme, which has the colours on it
|
||||||
assertEquals(9, colt.getTheme());
|
assertEquals(9, colt.getTheme());
|
||||||
XSSFColor themeC = wb.getTheme().getThemeColor(colt.getTheme());
|
XSSFColor themeC = wb.getTheme().getThemeColor(colt.getTheme());
|
||||||
assertNotNull( themeC.getRGB() );
|
assertNotNull(themeC.getRGB());
|
||||||
assertNotNull( colt.getRGB() );
|
assertNotNull(colt.getRGB());
|
||||||
assertEquals( themeC.getARGBHex(), colt.getARGBHex() ); // The same colour
|
assertEquals(themeC.getARGBHex(), colt.getARGBHex()); // The same colour
|
||||||
wb.close();
|
wb.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* New lines were being eaten when setting a font on
|
* New lines were being eaten when setting a font on
|
||||||
* a rich text string
|
* a rich text string
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void bug48877() throws IOException {
|
public void bug48877() throws IOException {
|
||||||
@ -873,7 +873,7 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
|
|||||||
font1.setColor((short) 20);
|
font1.setColor((short) 20);
|
||||||
Font font2 = wb1.createFont();
|
Font font2 = wb1.createFont();
|
||||||
font2.setColor(Font.COLOR_RED);
|
font2.setColor(Font.COLOR_RED);
|
||||||
Font font3 = wb1.getFontAt((short)0);
|
Font font3 = wb1.getFontAt((short) 0);
|
||||||
|
|
||||||
XSSFRow row = sheet.createRow(2);
|
XSSFRow row = sheet.createRow(2);
|
||||||
XSSFCell cell = row.createCell(2);
|
XSSFCell cell = row.createCell(2);
|
||||||
@ -907,14 +907,14 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
|
|||||||
|
|
||||||
// Now add a 2nd, and check again
|
// Now add a 2nd, and check again
|
||||||
int fontAt = text.indexOf("\n", 6);
|
int fontAt = text.indexOf("\n", 6);
|
||||||
cell.getRichStringCellValue().applyFont(10, fontAt+1, font2);
|
cell.getRichStringCellValue().applyFont(10, fontAt + 1, font2);
|
||||||
assertEquals(text, cell.getStringCellValue());
|
assertEquals(text, cell.getStringCellValue());
|
||||||
|
|
||||||
assertEquals(4, cell.getRichStringCellValue().numFormattingRuns());
|
assertEquals(4, cell.getRichStringCellValue().numFormattingRuns());
|
||||||
assertEquals("Use", cell.getRichStringCellValue().getCTRst().getRArray(0).getT());
|
assertEquals("Use", cell.getRichStringCellValue().getCTRst().getRArray(0).getT());
|
||||||
|
|
||||||
String r3 = cell.getRichStringCellValue().getCTRst().getRArray(2).getT();
|
String r3 = cell.getRichStringCellValue().getCTRst().getRArray(2).getT();
|
||||||
assertEquals("line.\n", r3.substring(r3.length()-6));
|
assertEquals("line.\n", r3.substring(r3.length() - 6));
|
||||||
|
|
||||||
// Save and re-check
|
// Save and re-check
|
||||||
XSSFWorkbook wb3 = XSSFTestDataSamples.writeOutAndReadBack(wb2);
|
XSSFWorkbook wb3 = XSSFTestDataSamples.writeOutAndReadBack(wb2);
|
||||||
@ -1053,7 +1053,7 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Setting repeating rows and columns shouldn't break
|
* Setting repeating rows and columns shouldn't break
|
||||||
* any print settings that were there before
|
* any print settings that were there before
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void bug49253() throws IOException {
|
public void bug49253() throws IOException {
|
||||||
@ -1106,7 +1106,7 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
|
|||||||
XSSFWorkbook wb = new XSSFWorkbook();
|
XSSFWorkbook wb = new XSSFWorkbook();
|
||||||
XSSFSheet s = wb.createSheet();
|
XSSFSheet s = wb.createSheet();
|
||||||
|
|
||||||
CellStyle defaultStyle = wb.getCellStyleAt((short)0);
|
CellStyle defaultStyle = wb.getCellStyleAt((short) 0);
|
||||||
assertEquals(0, defaultStyle.getIndex());
|
assertEquals(0, defaultStyle.getIndex());
|
||||||
|
|
||||||
CellStyle blueStyle = wb.createCellStyle();
|
CellStyle blueStyle = wb.createCellStyle();
|
||||||
@ -1268,7 +1268,7 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Add comments to Sheet 1, when Sheet 2 already has
|
* Add comments to Sheet 1, when Sheet 2 already has
|
||||||
* comments (so /xl/comments1.xml is taken)
|
* comments (so /xl/comments1.xml is taken)
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void bug51850() throws IOException {
|
public void bug51850() throws IOException {
|
||||||
@ -1354,7 +1354,7 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Sum across multiple workbooks
|
* Sum across multiple workbooks
|
||||||
* eg =SUM($Sheet1.C1:$Sheet4.C1)
|
* eg =SUM($Sheet1.C1:$Sheet4.C1)
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void bug48703() throws IOException {
|
public void bug48703() throws IOException {
|
||||||
@ -1390,7 +1390,7 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
|
|||||||
public void bug51710() throws IOException {
|
public void bug51710() throws IOException {
|
||||||
Workbook wb = XSSFTestDataSamples.openSampleWorkbook("51710.xlsx");
|
Workbook wb = XSSFTestDataSamples.openSampleWorkbook("51710.xlsx");
|
||||||
|
|
||||||
final String[] columns = {"A","B","C","D","E","F","G","H","I","J","K","L","M","N"};
|
final String[] columns = {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N"};
|
||||||
final int rowMax = 500; // bug triggers on row index 59
|
final int rowMax = 500; // bug triggers on row index 59
|
||||||
|
|
||||||
Sheet sheet = wb.getSheetAt(0);
|
Sheet sheet = wb.getSheetAt(0);
|
||||||
@ -1432,7 +1432,7 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
|
|||||||
|
|
||||||
// KY: SUM(B1: IZ1)
|
// KY: SUM(B1: IZ1)
|
||||||
/*double ky1Value =*/
|
/*double ky1Value =*/
|
||||||
evaluator.evaluate(wb.getSheetAt(0).getRow(0).getCell(310)).getNumberValue();
|
evaluator.evaluate(wb.getSheetAt(0).getRow(0).getCell(310)).getNumberValue();
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
assertEquals(259.0, a1Value, 0.0);
|
assertEquals(259.0, a1Value, 0.0);
|
||||||
@ -1442,7 +1442,7 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
|
|||||||
@Test
|
@Test
|
||||||
public void bug54436() throws IOException {
|
public void bug54436() throws IOException {
|
||||||
Workbook wb = XSSFTestDataSamples.openSampleWorkbook("54436.xlsx");
|
Workbook wb = XSSFTestDataSamples.openSampleWorkbook("54436.xlsx");
|
||||||
if(!WorkbookEvaluator.getSupportedFunctionNames().contains("GETPIVOTDATA")){
|
if (!WorkbookEvaluator.getSupportedFunctionNames().contains("GETPIVOTDATA")) {
|
||||||
Function func = new Function() {
|
Function func = new Function() {
|
||||||
@Override
|
@Override
|
||||||
public ValueEval evaluate(ValueEval[] args, int srcRowIndex, int srcColumnIndex) {
|
public ValueEval evaluate(ValueEval[] args, int srcRowIndex, int srcColumnIndex) {
|
||||||
@ -1458,13 +1458,13 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Password Protected .xlsx files should give a helpful
|
* Password Protected .xlsx files should give a helpful
|
||||||
* error message when called via WorkbookFactory with no password
|
* error message when called via WorkbookFactory with no password
|
||||||
*/
|
*/
|
||||||
@Test(expected=EncryptedDocumentException.class)
|
@Test(expected = EncryptedDocumentException.class)
|
||||||
public void bug55692_poifs() throws IOException {
|
public void bug55692_poifs() throws IOException {
|
||||||
// Via a POIFSFileSystem
|
// Via a POIFSFileSystem
|
||||||
POIFSFileSystem fsP = new POIFSFileSystem(
|
POIFSFileSystem fsP = new POIFSFileSystem(
|
||||||
POIDataSamples.getPOIFSInstance().openResourceAsStream("protect.xlsx"));
|
POIDataSamples.getPOIFSInstance().openResourceAsStream("protect.xlsx"));
|
||||||
try {
|
try {
|
||||||
WorkbookFactory.create(fsP);
|
WorkbookFactory.create(fsP);
|
||||||
} finally {
|
} finally {
|
||||||
@ -1545,8 +1545,8 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
|
|||||||
// dates stored.
|
// dates stored.
|
||||||
// We try to do a loop until the current second changes in order to avoid problems with some date information that is written to the ZIP and thus
|
// We try to do a loop until the current second changes in order to avoid problems with some date information that is written to the ZIP and thus
|
||||||
// causes differences
|
// causes differences
|
||||||
long start = System.currentTimeMillis()/1000;
|
long start = System.currentTimeMillis() / 1000;
|
||||||
while(System.currentTimeMillis()/1000 == start) {
|
while (System.currentTimeMillis() / 1000 == start) {
|
||||||
Thread.sleep(10);
|
Thread.sleep(10);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1669,7 +1669,7 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
|
|||||||
|
|
||||||
saveAndReloadReport(wb, xlsOutput);
|
saveAndReloadReport(wb, xlsOutput);
|
||||||
|
|
||||||
newCell.setCellValue("new Cell in row "+newRow.getRowNum());
|
newCell.setCellValue("new Cell in row " + newRow.getRowNum());
|
||||||
|
|
||||||
saveAndReloadReport(wb, xlsOutput);
|
saveAndReloadReport(wb, xlsOutput);
|
||||||
|
|
||||||
@ -1679,14 +1679,14 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
|
|||||||
// NOTE: another negative shift on another group of rows is successful, provided no new rows in
|
// NOTE: another negative shift on another group of rows is successful, provided no new rows in
|
||||||
// place of previously shifted rows were attempted to be created as explained above.
|
// place of previously shifted rows were attempted to be created as explained above.
|
||||||
testSheet.shiftRows(6, 7, 1); // -- CHANGE the shift to positive once the behaviour of
|
testSheet.shiftRows(6, 7, 1); // -- CHANGE the shift to positive once the behaviour of
|
||||||
// the above has been tested
|
// the above has been tested
|
||||||
|
|
||||||
saveAndReloadReport(wb, xlsOutput);
|
saveAndReloadReport(wb, xlsOutput);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* XSSFCell.typeMismatch on certain blank cells when formatting
|
* XSSFCell.typeMismatch on certain blank cells when formatting
|
||||||
* with DataFormatter
|
* with DataFormatter
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void bug56702() throws IOException {
|
public void bug56702() throws IOException {
|
||||||
@ -1712,7 +1712,7 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Formulas which reference named ranges, either in other
|
* Formulas which reference named ranges, either in other
|
||||||
* sheets, or workbook scoped but in other workbooks.
|
* sheets, or workbook scoped but in other workbooks.
|
||||||
* Used to fail with with errors like
|
* Used to fail with with errors like
|
||||||
* org.apache.poi.ss.formula.FormulaParseException: Cell reference expected after sheet name at index 9
|
* org.apache.poi.ss.formula.FormulaParseException: Cell reference expected after sheet name at index 9
|
||||||
* org.apache.poi.ss.formula.FormulaParseException: Parse error near char 0 '[' in specified formula '[0]!NR_Global_B2'. Expected number, string, or defined name
|
* org.apache.poi.ss.formula.FormulaParseException: Parse error near char 0 '[' in specified formula '[0]!NR_Global_B2'. Expected number, string, or defined name
|
||||||
@ -1744,7 +1744,7 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
|
|||||||
// Try to evaluate them
|
// Try to evaluate them
|
||||||
FormulaEvaluator eval = wb.getCreationHelper().createFormulaEvaluator();
|
FormulaEvaluator eval = wb.getCreationHelper().createFormulaEvaluator();
|
||||||
assertEquals("Test A1", eval.evaluate(cRefSName).getStringValue());
|
assertEquals("Test A1", eval.evaluate(cRefSName).getStringValue());
|
||||||
assertEquals(142, (int)eval.evaluate(cRefWName).getNumberValue());
|
assertEquals(142, (int) eval.evaluate(cRefWName).getNumberValue());
|
||||||
|
|
||||||
// Try to evaluate everything
|
// Try to evaluate everything
|
||||||
eval.evaluateAll();
|
eval.evaluateAll();
|
||||||
@ -1755,9 +1755,9 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
|
|||||||
// run some method on the font to verify if it is "disconnected" already
|
// run some method on the font to verify if it is "disconnected" already
|
||||||
//for(short i = 0;i < 256;i++)
|
//for(short i = 0;i < 256;i++)
|
||||||
{
|
{
|
||||||
Font font = wb.getFontAt((short)0);
|
Font font = wb.getFontAt((short) 0);
|
||||||
if(font instanceof XSSFFont) {
|
if (font instanceof XSSFFont) {
|
||||||
XSSFFont xfont = (XSSFFont) wb.getFontAt((short)0);
|
XSSFFont xfont = (XSSFFont) wb.getFontAt((short) 0);
|
||||||
CTFontImpl ctFont = (CTFontImpl) xfont.getCTFont();
|
CTFontImpl ctFont = (CTFontImpl) xfont.getCTFont();
|
||||||
assertEquals(0, ctFont.sizeOfBArray());
|
assertEquals(0, ctFont.sizeOfBArray());
|
||||||
}
|
}
|
||||||
@ -1774,11 +1774,11 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
|
|||||||
try {
|
try {
|
||||||
Workbook newWB = null;
|
Workbook newWB = null;
|
||||||
try {
|
try {
|
||||||
if(wb instanceof XSSFWorkbook) {
|
if (wb instanceof XSSFWorkbook) {
|
||||||
newWB = new XSSFWorkbook(is);
|
newWB = new XSSFWorkbook(is);
|
||||||
} else if(wb instanceof HSSFWorkbook) {
|
} else if (wb instanceof HSSFWorkbook) {
|
||||||
newWB = new HSSFWorkbook(is);
|
newWB = new HSSFWorkbook(is);
|
||||||
} else if(wb instanceof SXSSFWorkbook) {
|
} else if (wb instanceof SXSSFWorkbook) {
|
||||||
newWB = new SXSSFWorkbook(new XSSFWorkbook(is));
|
newWB = new SXSSFWorkbook(new XSSFWorkbook(is));
|
||||||
} else {
|
} else {
|
||||||
throw new IllegalStateException("Unknown workbook: " + wb);
|
throw new IllegalStateException("Unknown workbook: " + wb);
|
||||||
@ -1830,7 +1830,7 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* New hyperlink with no initial cell reference, still need
|
* New hyperlink with no initial cell reference, still need
|
||||||
* to be able to change it
|
* to be able to change it
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testBug56527() throws IOException {
|
public void testBug56527() throws IOException {
|
||||||
@ -1903,7 +1903,7 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
|
|||||||
try {
|
try {
|
||||||
new XSSFWorkbook(pkg).close();
|
new XSSFWorkbook(pkg).close();
|
||||||
fail("Should fail as too much expansion occurs");
|
fail("Should fail as too much expansion occurs");
|
||||||
} catch(POIXMLException e) {
|
} catch (POIXMLException e) {
|
||||||
// Expected
|
// Expected
|
||||||
}
|
}
|
||||||
pkg.close();
|
pkg.close();
|
||||||
@ -1912,7 +1912,7 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
|
|||||||
try {
|
try {
|
||||||
XSSFTestDataSamples.openSamplePackage("54764-2.xlsx").close();
|
XSSFTestDataSamples.openSamplePackage("54764-2.xlsx").close();
|
||||||
fail("Should fail as too much expansion occurs");
|
fail("Should fail as too much expansion occurs");
|
||||||
} catch(Exception e) {
|
} catch (Exception e) {
|
||||||
// Expected
|
// Expected
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1924,7 +1924,7 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* CTDefinedNamesImpl should be included in the smaller
|
* CTDefinedNamesImpl should be included in the smaller
|
||||||
* poi-ooxml-schemas jar
|
* poi-ooxml-schemas jar
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void bug57176() throws IOException {
|
public void bug57176() throws IOException {
|
||||||
@ -1941,7 +1941,7 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* .xlsb files are not supported, but we should generate a helpful
|
* .xlsb files are not supported, but we should generate a helpful
|
||||||
* error message if given one
|
* error message if given one
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void bug56800_xlsb() throws IOException, InvalidFormatException {
|
public void bug56800_xlsb() throws IOException, InvalidFormatException {
|
||||||
@ -1990,7 +1990,7 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
|
|||||||
public void testBug57196() throws IOException {
|
public void testBug57196() throws IOException {
|
||||||
Workbook wb = XSSFTestDataSamples.openSampleWorkbook("57196.xlsx");
|
Workbook wb = XSSFTestDataSamples.openSampleWorkbook("57196.xlsx");
|
||||||
Sheet sheet = wb.getSheet("Feuil1");
|
Sheet sheet = wb.getSheet("Feuil1");
|
||||||
Row mod=sheet.getRow(1);
|
Row mod = sheet.getRow(1);
|
||||||
mod.getCell(1).setCellValue(3);
|
mod.getCell(1).setCellValue(3);
|
||||||
HSSFFormulaEvaluator.evaluateAllFormulaCells(wb);
|
HSSFFormulaEvaluator.evaluateAllFormulaCells(wb);
|
||||||
// FileOutputStream fileOutput = new FileOutputStream("/tmp/57196.xlsx");
|
// FileOutputStream fileOutput = new FileOutputStream("/tmp/57196.xlsx");
|
||||||
@ -2099,7 +2099,7 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
|
|||||||
|
|
||||||
wb.close();
|
wb.close();
|
||||||
} finally {
|
} finally {
|
||||||
if(previousLogger == null) {
|
if (previousLogger == null) {
|
||||||
System.clearProperty("org.apache.poi.util.POILogger");
|
System.clearProperty("org.apache.poi.util.POILogger");
|
||||||
} else {
|
} else {
|
||||||
System.setProperty("org.apache.poi.util.POILogger", previousLogger);
|
System.setProperty("org.apache.poi.util.POILogger", previousLogger);
|
||||||
@ -2110,12 +2110,12 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* A .xlsx file with no Shared Strings table should open fine
|
* A .xlsx file with no Shared Strings table should open fine
|
||||||
* in read-only mode
|
* in read-only mode
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("resource")
|
@SuppressWarnings("resource")
|
||||||
@Test
|
@Test
|
||||||
public void bug57482() throws IOException, InvalidFormatException {
|
public void bug57482() throws IOException, InvalidFormatException {
|
||||||
for (PackageAccess access : new PackageAccess[] {
|
for (PackageAccess access : new PackageAccess[]{
|
||||||
PackageAccess.READ_WRITE, PackageAccess.READ
|
PackageAccess.READ_WRITE, PackageAccess.READ
|
||||||
}) {
|
}) {
|
||||||
File file = HSSFTestDataSamples.getSampleFile("57482-OnlyNumeric.xlsx");
|
File file = HSSFTestDataSamples.getSampleFile("57482-OnlyNumeric.xlsx");
|
||||||
@ -2128,13 +2128,13 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
|
|||||||
|
|
||||||
DataFormatter fmt = new DataFormatter();
|
DataFormatter fmt = new DataFormatter();
|
||||||
XSSFSheet s = wb1.getSheetAt(0);
|
XSSFSheet s = wb1.getSheetAt(0);
|
||||||
assertEquals("1", fmt.formatCellValue(s.getRow(0).getCell(0)));
|
assertEquals("1", fmt.formatCellValue(s.getRow(0).getCell(0)));
|
||||||
assertEquals("11", fmt.formatCellValue(s.getRow(0).getCell(1)));
|
assertEquals("11", fmt.formatCellValue(s.getRow(0).getCell(1)));
|
||||||
assertEquals("5", fmt.formatCellValue(s.getRow(4).getCell(0)));
|
assertEquals("5", fmt.formatCellValue(s.getRow(4).getCell(0)));
|
||||||
|
|
||||||
// Add a text cell
|
// Add a text cell
|
||||||
s.getRow(0).createCell(3).setCellValue("Testing");
|
s.getRow(0).createCell(3).setCellValue("Testing");
|
||||||
assertEquals("Testing", fmt.formatCellValue(s.getRow(0).getCell(3)));
|
assertEquals("Testing", fmt.formatCellValue(s.getRow(0).getCell(3)));
|
||||||
|
|
||||||
// Try to write-out and read again, should only work
|
// Try to write-out and read again, should only work
|
||||||
// in read-write mode, not read-only mode
|
// in read-write mode, not read-only mode
|
||||||
@ -2147,10 +2147,10 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
|
|||||||
|
|
||||||
// Check again
|
// Check again
|
||||||
s = wb2.getSheetAt(0);
|
s = wb2.getSheetAt(0);
|
||||||
assertEquals("1", fmt.formatCellValue(s.getRow(0).getCell(0)));
|
assertEquals("1", fmt.formatCellValue(s.getRow(0).getCell(0)));
|
||||||
assertEquals("11", fmt.formatCellValue(s.getRow(0).getCell(1)));
|
assertEquals("11", fmt.formatCellValue(s.getRow(0).getCell(1)));
|
||||||
assertEquals("5", fmt.formatCellValue(s.getRow(4).getCell(0)));
|
assertEquals("5", fmt.formatCellValue(s.getRow(4).getCell(0)));
|
||||||
assertEquals("Testing", fmt.formatCellValue(s.getRow(0).getCell(3)));
|
assertEquals("Testing", fmt.formatCellValue(s.getRow(0).getCell(3)));
|
||||||
|
|
||||||
} catch (InvalidOperationException e) {
|
} catch (InvalidOperationException e) {
|
||||||
if (access == PackageAccess.READ_WRITE) {
|
if (access == PackageAccess.READ_WRITE) {
|
||||||
@ -2226,13 +2226,11 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void removeAllSheetsBut(int sheetIndex, Workbook wb)
|
private static void removeAllSheetsBut(int sheetIndex, Workbook wb) {
|
||||||
{
|
|
||||||
int sheetNb = wb.getNumberOfSheets();
|
int sheetNb = wb.getNumberOfSheets();
|
||||||
// Move this sheet at the first position
|
// Move this sheet at the first position
|
||||||
wb.setSheetOrder(wb.getSheetName(sheetIndex), 0);
|
wb.setSheetOrder(wb.getSheetName(sheetIndex), 0);
|
||||||
for (int sn = sheetNb - 1; sn > 0; sn--)
|
for (int sn = sheetNb - 1; sn > 0; sn--) {
|
||||||
{
|
|
||||||
wb.removeSheetAt(sn);
|
wb.removeSheetAt(sn);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2255,7 +2253,7 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Expected:
|
* Expected:
|
||||||
|
* <p>
|
||||||
* [ 0][ 2][ 4]
|
* [ 0][ 2][ 4]
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
@ -2283,7 +2281,7 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Expected:
|
* Expected:
|
||||||
|
* <p>
|
||||||
* [ 0] <- number
|
* [ 0] <- number
|
||||||
* [ 2] <- formula
|
* [ 2] <- formula
|
||||||
* [ 4] <- formula
|
* [ 4] <- formula
|
||||||
@ -2328,7 +2326,7 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
|
|||||||
}
|
}
|
||||||
|
|
||||||
} finally {
|
} finally {
|
||||||
wb.close();
|
wb.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2376,11 +2374,11 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
|
|||||||
XSSFRow destRow = newSheet.createRow(0);
|
XSSFRow destRow = newSheet.createRow(0);
|
||||||
XSSFCell newCell = destRow.createCell(0);
|
XSSFCell newCell = destRow.createCell(0);
|
||||||
|
|
||||||
//newCell.getCellStyle().cloneStyleFrom(cellStyle);
|
//newCell.getCellStyle().cloneStyleFrom(cellStyle);
|
||||||
CellStyle newCellStyle = targetWorkbook.createCellStyle();
|
CellStyle newCellStyle = targetWorkbook.createCellStyle();
|
||||||
newCellStyle.cloneStyleFrom(cellStyle);
|
newCellStyle.cloneStyleFrom(cellStyle);
|
||||||
newCell.setCellStyle(newCellStyle);
|
newCell.setCellStyle(newCellStyle);
|
||||||
checkStyle(newCell.getCellStyle());
|
checkStyle(newCell.getCellStyle());
|
||||||
newCell.setCellValue(oldCell.getStringCellValue());
|
newCell.setCellValue(oldCell.getStringCellValue());
|
||||||
|
|
||||||
// OutputStream os = new FileOutputStream("output.xlsm");
|
// OutputStream os = new FileOutputStream("output.xlsm");
|
||||||
@ -2400,7 +2398,7 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Paragraph with property BuFont but none of the properties
|
* Paragraph with property BuFont but none of the properties
|
||||||
* BuNone, BuChar, and BuAutoNum, used to trigger a NPE
|
* BuNone, BuChar, and BuAutoNum, used to trigger a NPE
|
||||||
* Excel treats this as not-bulleted, so now do we
|
* Excel treats this as not-bulleted, so now do we
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
@ -2417,7 +2415,7 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
|
|||||||
assertEquals(1, shapes.size());
|
assertEquals(1, shapes.size());
|
||||||
assertTrue(shapes.get(0) instanceof XSSFSimpleShape);
|
assertTrue(shapes.get(0) instanceof XSSFSimpleShape);
|
||||||
|
|
||||||
XSSFSimpleShape shape = (XSSFSimpleShape)shapes.get(0);
|
XSSFSimpleShape shape = (XSSFSimpleShape) shapes.get(0);
|
||||||
|
|
||||||
// Used to throw a NPE
|
// Used to throw a NPE
|
||||||
String text = shape.getText();
|
String text = shape.getText();
|
||||||
@ -2428,20 +2426,20 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
|
|||||||
workbook.close();
|
workbook.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkStyle(XSSFCellStyle cellStyle) {
|
private void checkStyle(XSSFCellStyle cellStyle) {
|
||||||
assertNotNull(cellStyle);
|
assertNotNull(cellStyle);
|
||||||
assertEquals(0, cellStyle.getFillForegroundColor());
|
assertEquals(0, cellStyle.getFillForegroundColor());
|
||||||
assertNotNull(cellStyle.getFillForegroundXSSFColor());
|
assertNotNull(cellStyle.getFillForegroundXSSFColor());
|
||||||
XSSFColor fgColor = cellStyle.getFillForegroundColorColor();
|
XSSFColor fgColor = cellStyle.getFillForegroundColorColor();
|
||||||
assertNotNull(fgColor);
|
assertNotNull(fgColor);
|
||||||
assertEquals("FF00FFFF", fgColor.getARGBHex());
|
assertEquals("FF00FFFF", fgColor.getARGBHex());
|
||||||
|
|
||||||
assertEquals(0, cellStyle.getFillBackgroundColor());
|
assertEquals(0, cellStyle.getFillBackgroundColor());
|
||||||
assertNotNull(cellStyle.getFillBackgroundXSSFColor());
|
assertNotNull(cellStyle.getFillBackgroundXSSFColor());
|
||||||
XSSFColor bgColor = cellStyle.getFillBackgroundColorColor();
|
XSSFColor bgColor = cellStyle.getFillBackgroundColorColor();
|
||||||
assertNotNull(bgColor);
|
assertNotNull(bgColor);
|
||||||
assertEquals("FF00FFFF", fgColor.getARGBHex());
|
assertEquals("FF00FFFF", fgColor.getARGBHex());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void bug57642() throws IOException {
|
public void bug57642() throws IOException {
|
||||||
@ -2463,14 +2461,14 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* .xlsx supports 64000 cell styles, the style indexes after
|
* .xlsx supports 64000 cell styles, the style indexes after
|
||||||
* 32,767 must not be -32,768, then -32,767, -32,766
|
* 32,767 must not be -32,768, then -32,767, -32,766
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("resource")
|
@SuppressWarnings("resource")
|
||||||
@Test
|
@Test
|
||||||
public void bug57880() throws IOException {
|
public void bug57880() throws IOException {
|
||||||
int numStyles = 33000;
|
int numStyles = 33000;
|
||||||
XSSFWorkbook wb = new XSSFWorkbook();
|
XSSFWorkbook wb = new XSSFWorkbook();
|
||||||
for (int i=1; i<numStyles; i++) {
|
for (int i = 1; i < numStyles; i++) {
|
||||||
// Create a style and use it
|
// Create a style and use it
|
||||||
XSSFCellStyle style = wb.createCellStyle();
|
XSSFCellStyle style = wb.createCellStyle();
|
||||||
assertEquals(i, style.getUIndex());
|
assertEquals(i, style.getUIndex());
|
||||||
@ -2493,7 +2491,7 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
|
|||||||
//If XSSFWorkbooks ever implicitly optimize/consolidate cell styles (such as when the workbook is written to disk)
|
//If XSSFWorkbooks ever implicitly optimize/consolidate cell styles (such as when the workbook is written to disk)
|
||||||
//then this unit test should be updated
|
//then this unit test should be updated
|
||||||
assertEquals(numStyles, wb.getNumCellStyles());
|
assertEquals(numStyles, wb.getNumCellStyles());
|
||||||
for (int i=1; i<numStyles; i++) {
|
for (int i = 1; i < numStyles; i++) {
|
||||||
XSSFCellStyle style = wb.getCellStyleAt(i);
|
XSSFCellStyle style = wb.getCellStyleAt(i);
|
||||||
assertNotNull(style);
|
assertNotNull(style);
|
||||||
assertEquals(i, style.getUIndex());
|
assertEquals(i, style.getUIndex());
|
||||||
@ -2516,16 +2514,16 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
|
|||||||
|
|
||||||
Map<String, Object[]> data;
|
Map<String, Object[]> data;
|
||||||
data = new TreeMap<String, Object[]>();
|
data = new TreeMap<String, Object[]>();
|
||||||
data.put("1", new Object[] {"ID", "NAME", "LASTNAME"});
|
data.put("1", new Object[]{"ID", "NAME", "LASTNAME"});
|
||||||
data.put("2", new Object[] {2, "Amit", "Shukla"});
|
data.put("2", new Object[]{2, "Amit", "Shukla"});
|
||||||
data.put("3", new Object[] {1, "Lokesh", "Gupta"});
|
data.put("3", new Object[]{1, "Lokesh", "Gupta"});
|
||||||
data.put("4", new Object[] {4, "John", "Adwards"});
|
data.put("4", new Object[]{4, "John", "Adwards"});
|
||||||
data.put("5", new Object[] {2, "Brian", "Schultz"});
|
data.put("5", new Object[]{2, "Brian", "Schultz"});
|
||||||
|
|
||||||
int rownum = 1;
|
int rownum = 1;
|
||||||
for (Map.Entry<String,Object[]> me : data.entrySet()) {
|
for (Map.Entry<String, Object[]> me : data.entrySet()) {
|
||||||
final Row row;
|
final Row row;
|
||||||
if(createRow) {
|
if (createRow) {
|
||||||
row = sheet.createRow(rownum++);
|
row = sheet.createRow(rownum++);
|
||||||
} else {
|
} else {
|
||||||
row = sheet.getRow(rownum++);
|
row = sheet.getRow(rownum++);
|
||||||
@ -2535,28 +2533,28 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
|
|||||||
int cellnum = 0;
|
int cellnum = 0;
|
||||||
for (Object obj : me.getValue()) {
|
for (Object obj : me.getValue()) {
|
||||||
Cell cell = row.getCell(cellnum);
|
Cell cell = row.getCell(cellnum);
|
||||||
if(cell == null){
|
if (cell == null) {
|
||||||
cell = row.createCell(cellnum);
|
cell = row.createCell(cellnum);
|
||||||
} else {
|
} else {
|
||||||
if(cell.getCellTypeEnum() == CellType.FORMULA) {
|
if (cell.getCellTypeEnum() == CellType.FORMULA) {
|
||||||
cell.setCellFormula(null);
|
cell.setCellFormula(null);
|
||||||
cell.getCellStyle().setDataFormat((short) 0);
|
cell.getCellStyle().setDataFormat((short) 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(obj instanceof String) {
|
if (obj instanceof String) {
|
||||||
cell.setCellValue((String)obj);
|
cell.setCellValue((String) obj);
|
||||||
} else if(obj instanceof Integer) {
|
} else if (obj instanceof Integer) {
|
||||||
cell.setCellValue((Integer)obj);
|
cell.setCellValue((Integer) obj);
|
||||||
}
|
}
|
||||||
cellnum++;
|
cellnum++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
XSSFFormulaEvaluator.evaluateAllFormulaCells((XSSFWorkbook) wb);
|
XSSFFormulaEvaluator.evaluateAllFormulaCells((XSSFWorkbook) wb);
|
||||||
wb.getCreationHelper().createFormulaEvaluator().evaluateAll();
|
wb.getCreationHelper().createFormulaEvaluator().evaluateAll();
|
||||||
|
|
||||||
CalculationChain chain = ((XSSFWorkbook)wb).getCalculationChain();
|
CalculationChain chain = ((XSSFWorkbook) wb).getCalculationChain();
|
||||||
for(CTCalcCell calc : chain.getCTCalcChain().getCList()) {
|
for (CTCalcCell calc : chain.getCTCalcChain().getCList()) {
|
||||||
// A2 to A6 should be gone
|
// A2 to A6 should be gone
|
||||||
assertFalse(calc.getR().equals("A2"));
|
assertFalse(calc.getR().equals("A2"));
|
||||||
assertFalse(calc.getR().equals("A3"));
|
assertFalse(calc.getR().equals("A3"));
|
||||||
@ -2569,8 +2567,8 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
|
|||||||
Sheet sheetBack = wbBack.getSheet("Func");
|
Sheet sheetBack = wbBack.getSheet("Func");
|
||||||
assertNotNull(sheetBack);
|
assertNotNull(sheetBack);
|
||||||
|
|
||||||
chain = ((XSSFWorkbook)wbBack).getCalculationChain();
|
chain = ((XSSFWorkbook) wbBack).getCalculationChain();
|
||||||
for(CTCalcCell calc : chain.getCTCalcChain().getCList()) {
|
for (CTCalcCell calc : chain.getCTCalcChain().getCList()) {
|
||||||
// A2 to A6 should be gone
|
// A2 to A6 should be gone
|
||||||
assertFalse(calc.getR().equals("A2"));
|
assertFalse(calc.getR().equals("A2"));
|
||||||
assertFalse(calc.getR().equals("A3"));
|
assertFalse(calc.getR().equals("A3"));
|
||||||
@ -2608,8 +2606,7 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
|
|||||||
if (null == expectedResultOrNull) {
|
if (null == expectedResultOrNull) {
|
||||||
assertEquals(CellType.ERROR, intF.getCachedFormulaResultTypeEnum());
|
assertEquals(CellType.ERROR, intF.getCachedFormulaResultTypeEnum());
|
||||||
expectedResultOrNull = "#VALUE!";
|
expectedResultOrNull = "#VALUE!";
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
assertEquals(CellType.NUMERIC, intF.getCachedFormulaResultTypeEnum());
|
assertEquals(CellType.NUMERIC, intF.getCachedFormulaResultTypeEnum());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2632,7 +2629,7 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
|
|||||||
|
|
||||||
// color index
|
// color index
|
||||||
assertEquals(64, style.getFillBackgroundColor());
|
assertEquals(64, style.getFillBackgroundColor());
|
||||||
XSSFColor color = ((XSSFCellStyle)style).getFillBackgroundXSSFColor();
|
XSSFColor color = ((XSSFCellStyle) style).getFillBackgroundXSSFColor();
|
||||||
assertNotNull(color);
|
assertNotNull(color);
|
||||||
|
|
||||||
// indexed color
|
// indexed color
|
||||||
@ -2649,9 +2646,9 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
|
|||||||
public void test50755_workday_formula_example() throws IOException {
|
public void test50755_workday_formula_example() throws IOException {
|
||||||
Workbook wb = XSSFTestDataSamples.openSampleWorkbook("50755_workday_formula_example.xlsx");
|
Workbook wb = XSSFTestDataSamples.openSampleWorkbook("50755_workday_formula_example.xlsx");
|
||||||
Sheet sheet = wb.getSheet("Sheet1");
|
Sheet sheet = wb.getSheet("Sheet1");
|
||||||
for(Row aRow : sheet) {
|
for (Row aRow : sheet) {
|
||||||
Cell cell = aRow.getCell(1);
|
Cell cell = aRow.getCell(1);
|
||||||
if(cell.getCellTypeEnum() == CellType.FORMULA) {
|
if (cell.getCellTypeEnum() == CellType.FORMULA) {
|
||||||
String formula = cell.getCellFormula();
|
String formula = cell.getCellFormula();
|
||||||
//System.out.println("formula: " + formula);
|
//System.out.println("formula: " + formula);
|
||||||
assertNotNull(formula);
|
assertNotNull(formula);
|
||||||
@ -2752,9 +2749,9 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
|
|||||||
Cell cellA2 = sheet.getRow(1).getCell(0);
|
Cell cellA2 = sheet.getRow(1).getCell(0);
|
||||||
|
|
||||||
assertEquals(0, cellA1.getCellStyle().getFillForegroundColor());
|
assertEquals(0, cellA1.getCellStyle().getFillForegroundColor());
|
||||||
assertEquals("FFFDFDFD", ((XSSFColor)cellA1.getCellStyle().getFillForegroundColorColor()).getARGBHex());
|
assertEquals("FFFDFDFD", ((XSSFColor) cellA1.getCellStyle().getFillForegroundColorColor()).getARGBHex());
|
||||||
assertEquals(0, cellA2.getCellStyle().getFillForegroundColor());
|
assertEquals(0, cellA2.getCellStyle().getFillForegroundColor());
|
||||||
assertEquals("FFFDFDFD", ((XSSFColor)cellA2.getCellStyle().getFillForegroundColorColor()).getARGBHex());
|
assertEquals("FFFDFDFD", ((XSSFColor) cellA2.getCellStyle().getFillForegroundColorColor()).getARGBHex());
|
||||||
|
|
||||||
SheetConditionalFormatting cond = sheet.getSheetConditionalFormatting();
|
SheetConditionalFormatting cond = sheet.getSheetConditionalFormatting();
|
||||||
assertEquals(2, cond.getNumConditionalFormattings());
|
assertEquals(2, cond.getNumConditionalFormattings());
|
||||||
@ -2762,12 +2759,12 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
|
|||||||
assertEquals(1, cond.getConditionalFormattingAt(0).getNumberOfRules());
|
assertEquals(1, cond.getConditionalFormattingAt(0).getNumberOfRules());
|
||||||
assertEquals(64, cond.getConditionalFormattingAt(0).getRule(0).getPatternFormatting().getFillForegroundColor());
|
assertEquals(64, cond.getConditionalFormattingAt(0).getRule(0).getPatternFormatting().getFillForegroundColor());
|
||||||
assertEquals("ISEVEN(ROW())", cond.getConditionalFormattingAt(0).getRule(0).getFormula1());
|
assertEquals("ISEVEN(ROW())", cond.getConditionalFormattingAt(0).getRule(0).getFormula1());
|
||||||
assertNull(((XSSFColor)cond.getConditionalFormattingAt(0).getRule(0).getPatternFormatting().getFillForegroundColorColor()).getARGBHex());
|
assertNull(((XSSFColor) cond.getConditionalFormattingAt(0).getRule(0).getPatternFormatting().getFillForegroundColorColor()).getARGBHex());
|
||||||
|
|
||||||
assertEquals(1, cond.getConditionalFormattingAt(1).getNumberOfRules());
|
assertEquals(1, cond.getConditionalFormattingAt(1).getNumberOfRules());
|
||||||
assertEquals(64, cond.getConditionalFormattingAt(1).getRule(0).getPatternFormatting().getFillForegroundColor());
|
assertEquals(64, cond.getConditionalFormattingAt(1).getRule(0).getPatternFormatting().getFillForegroundColor());
|
||||||
assertEquals("ISEVEN(ROW())", cond.getConditionalFormattingAt(1).getRule(0).getFormula1());
|
assertEquals("ISEVEN(ROW())", cond.getConditionalFormattingAt(1).getRule(0).getFormula1());
|
||||||
assertNull(((XSSFColor)cond.getConditionalFormattingAt(1).getRule(0).getPatternFormatting().getFillForegroundColorColor()).getARGBHex());
|
assertNull(((XSSFColor) cond.getConditionalFormattingAt(1).getRule(0).getPatternFormatting().getFillForegroundColorColor()).getARGBHex());
|
||||||
|
|
||||||
wb.close();
|
wb.close();
|
||||||
}
|
}
|
||||||
@ -2778,13 +2775,11 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
|
|||||||
|
|
||||||
Set<String> sheetNames = new HashSet<String>();
|
Set<String> sheetNames = new HashSet<String>();
|
||||||
|
|
||||||
for (int sheetNum = 0; sheetNum < wb.getNumberOfSheets(); sheetNum++)
|
for (int sheetNum = 0; sheetNum < wb.getNumberOfSheets(); sheetNum++) {
|
||||||
{
|
|
||||||
sheetNames.add(wb.getSheetName(sheetNum));
|
sheetNames.add(wb.getSheetName(sheetNum));
|
||||||
}
|
}
|
||||||
|
|
||||||
for (String sheetName : sheetNames)
|
for (String sheetName : sheetNames) {
|
||||||
{
|
|
||||||
int sheetIndex = wb.getSheetIndex(sheetName);
|
int sheetIndex = wb.getSheetIndex(sheetName);
|
||||||
|
|
||||||
wb.removeSheetAt(sheetIndex);
|
wb.removeSheetAt(sheetIndex);
|
||||||
@ -2872,11 +2867,11 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
|
|||||||
DataFormatter formatter = new DataFormatter(true);
|
DataFormatter formatter = new DataFormatter(true);
|
||||||
|
|
||||||
XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("57236.xlsx");
|
XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("57236.xlsx");
|
||||||
for(int sheetNum = 0;sheetNum < wb.getNumberOfSheets();sheetNum++) {
|
for (int sheetNum = 0; sheetNum < wb.getNumberOfSheets(); sheetNum++) {
|
||||||
Sheet sheet = wb.getSheetAt(sheetNum);
|
Sheet sheet = wb.getSheetAt(sheetNum);
|
||||||
for(int rowNum = sheet.getFirstRowNum();rowNum < sheet.getLastRowNum();rowNum++) {
|
for (int rowNum = sheet.getFirstRowNum(); rowNum < sheet.getLastRowNum(); rowNum++) {
|
||||||
Row row = sheet.getRow(rowNum);
|
Row row = sheet.getRow(rowNum);
|
||||||
for(int cellNum = row.getFirstCellNum();cellNum < row.getLastCellNum();cellNum++) {
|
for (int cellNum = row.getFirstCellNum(); cellNum < row.getLastCellNum(); cellNum++) {
|
||||||
Cell cell = row.getCell(cellNum);
|
Cell cell = row.getCell(cellNum);
|
||||||
String fmtCellValue = formatter.formatCellValue(cell);
|
String fmtCellValue = formatter.formatCellValue(cell);
|
||||||
|
|
||||||
@ -2890,8 +2885,7 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
|
|||||||
wb.close();
|
wb.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createXls() throws IOException
|
private void createXls() throws IOException {
|
||||||
{
|
|
||||||
Workbook workbook = new HSSFWorkbook();
|
Workbook workbook = new HSSFWorkbook();
|
||||||
FileOutputStream fileOut = new FileOutputStream("/tmp/rotated.xls");
|
FileOutputStream fileOut = new FileOutputStream("/tmp/rotated.xls");
|
||||||
Sheet sheet1 = workbook.createSheet();
|
Sheet sheet1 = workbook.createSheet();
|
||||||
@ -2947,7 +2941,7 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
|
|||||||
Row row = worksheet.getRow(2);
|
Row row = worksheet.getRow(2);
|
||||||
Cell cell = row.getCell(1);
|
Cell cell = row.getCell(1);
|
||||||
|
|
||||||
cell.setCellValue((String)null);
|
cell.setCellValue((String) null);
|
||||||
|
|
||||||
FormulaEvaluator evaluator = workbook.getCreationHelper().createFormulaEvaluator();
|
FormulaEvaluator evaluator = workbook.getCreationHelper().createFormulaEvaluator();
|
||||||
|
|
||||||
@ -3060,13 +3054,13 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Files produced by some scientific equipment neglect
|
* Files produced by some scientific equipment neglect
|
||||||
* to include the row number on the row tags
|
* to include the row number on the row tags
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void noRowNumbers59746() {
|
public void noRowNumbers59746() {
|
||||||
Workbook wb = XSSFTestDataSamples.openSampleWorkbook("59746_NoRowNums.xlsx");
|
Workbook wb = XSSFTestDataSamples.openSampleWorkbook("59746_NoRowNums.xlsx");
|
||||||
Sheet sheet = wb.getSheetAt(0);
|
Sheet sheet = wb.getSheetAt(0);
|
||||||
assertTrue("Last row num: "+sheet.getLastRowNum(), sheet.getLastRowNum()>20);
|
assertTrue("Last row num: " + sheet.getLastRowNum(), sheet.getLastRowNum() > 20);
|
||||||
assertEquals("Checked", sheet.getRow(0).getCell(0).getStringCellValue());
|
assertEquals("Checked", sheet.getRow(0).getCell(0).getStringCellValue());
|
||||||
assertEquals("Checked", sheet.getRow(9).getCell(2).getStringCellValue());
|
assertEquals("Checked", sheet.getRow(9).getCell(2).getStringCellValue());
|
||||||
assertEquals(false, sheet.getRow(70).getCell(8).getBooleanCellValue());
|
assertEquals(false, sheet.getRow(70).getCell(8).getBooleanCellValue());
|
||||||
@ -3089,7 +3083,7 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// This bug is currently open. When this bug is fixed, it should not throw an AssertionError
|
// This bug is currently open. When this bug is fixed, it should not throw an AssertionError
|
||||||
@Test(expected=AssertionError.class)
|
@Test(expected = AssertionError.class)
|
||||||
public void test55076_collapseColumnGroups() throws Exception {
|
public void test55076_collapseColumnGroups() throws Exception {
|
||||||
Workbook wb = new XSSFWorkbook();
|
Workbook wb = new XSSFWorkbook();
|
||||||
Sheet sheet = wb.createSheet();
|
Sheet sheet = wb.createSheet();
|
||||||
@ -3114,7 +3108,7 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
|
|||||||
|
|
||||||
// none of the columns should be hidden
|
// none of the columns should be hidden
|
||||||
// column group collapsing is a different concept
|
// column group collapsing is a different concept
|
||||||
for (int c=0; c<5; c++) {
|
for (int c = 0; c < 5; c++) {
|
||||||
assertFalse("Column " + c, sheet.isColumnHidden(c));
|
assertFalse("Column " + c, sheet.isColumnHidden(c));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3127,8 +3121,8 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Other things, including charts, may end up taking drawing part
|
* Other things, including charts, may end up taking drawing part
|
||||||
* numbers. (Uses a test file hand-crafted with an extra non-drawing
|
* numbers. (Uses a test file hand-crafted with an extra non-drawing
|
||||||
* part with a part number)
|
* part with a part number)
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void drawingNumbersAlreadyTaken_60255() throws Exception {
|
public void drawingNumbersAlreadyTaken_60255() throws Exception {
|
||||||
@ -3190,7 +3184,7 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
|
|||||||
str.close();
|
str.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
assertEquals("B2:I5", ((XSSFSheet)sheet).getCTWorksheet().getDimension().getRef());
|
assertEquals("B2:I5", ((XSSFSheet) sheet).getCTWorksheet().getDimension().getRef());
|
||||||
|
|
||||||
wb.close();
|
wb.close();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user