Bug 61648: Test Sheet.setArrayFormula for SXSSF

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1819770 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Dominik Stadler 2018-01-01 14:39:15 +00:00
parent bc4eb140c5
commit 33d5bf0961
2 changed files with 80 additions and 8 deletions

View File

@ -970,8 +970,7 @@ public class SXSSFSheet implements Sheet
*/ */
@NotImplemented @NotImplemented
@Override @Override
public void shiftRows(int startRow, int endRow, int n) public void shiftRows(int startRow, int endRow, int n) {
{
throw new RuntimeException("NotImplemented"); throw new RuntimeException("NotImplemented");
} }
@ -1730,9 +1729,12 @@ public class SXSSFSheet implements Sheet
* @return the {@link CellRange} of cells affected by this change * @return the {@link CellRange} of cells affected by this change
*/ */
@Override @Override
public CellRange<? extends Cell> setArrayFormula(String formula, CellRangeAddress range) public CellRange<? extends Cell> setArrayFormula(String formula, CellRangeAddress range) {
{ // the simple approach via _sh does not work as it creates rows in the XSSFSheet and thus causes
return _sh.setArrayFormula(formula, range); // corrupted .xlsx files as rows appear multiple times in the resulting sheetX.xml files
// return _sh.setArrayFormula(formula, range);
throw new RuntimeException("NotImplemented");
} }
/** /**
@ -1742,9 +1744,12 @@ public class SXSSFSheet implements Sheet
* @return the {@link CellRange} of cells affected by this change * @return the {@link CellRange} of cells affected by this change
*/ */
@Override @Override
public CellRange<? extends Cell> removeArrayFormula(Cell cell) public CellRange<? extends Cell> removeArrayFormula(Cell cell) {
{ // the simple approach via _sh does not work as it creates rows in the XSSFSheet and thus causes
return _sh.removeArrayFormula(cell); // corrupted .xlsx files as rows appear multiple times in the resulting sheetX.xml files
// return _sh.removeArrayFormula(cell);
throw new RuntimeException("NotImplemented");
} }
@Override @Override

View File

@ -18,15 +18,22 @@
package org.apache.poi.xssf.usermodel; package org.apache.poi.xssf.usermodel;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.fail;
import java.io.IOException; import java.io.IOException;
import org.apache.poi.ss.ITestDataProvider;
import org.apache.poi.ss.usermodel.BaseTestBugzillaIssues; import org.apache.poi.ss.usermodel.BaseTestBugzillaIssues;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellType;
import org.apache.poi.ss.usermodel.PrintSetup; import org.apache.poi.ss.usermodel.PrintSetup;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet; import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook; import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.util.CellRangeAddress; import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.xssf.SXSSFITestDataProvider; import org.apache.poi.xssf.SXSSFITestDataProvider;
import org.apache.poi.xssf.XSSFITestDataProvider;
import org.apache.poi.xssf.streaming.SXSSFWorkbook; import org.apache.poi.xssf.streaming.SXSSFWorkbook;
import org.junit.Ignore; import org.junit.Ignore;
import org.junit.Test; import org.junit.Test;
@ -99,4 +106,64 @@ public final class TestSXSSFBugs extends BaseTestBugzillaIssues {
} }
} }
} }
@Test
public void bug61648() throws Exception {
// works as expected
writeWorkbook(new XSSFWorkbook(), "/tmp/61648.xlsx", XSSFITestDataProvider.instance);
// does not work
try {
writeWorkbook(new SXSSFWorkbook(), "/tmp/61648s.xlsx", SXSSFITestDataProvider.instance);
fail("Should catch exception here");
} catch (RuntimeException e) {
// this is not implemented yet
}
}
void writeWorkbook(Workbook wb, String filename, ITestDataProvider testDataProvider) throws IOException {
Sheet sheet = wb.createSheet("array formula test");
int rowIndex = 0;
int colIndex = 0;
Row row = sheet.createRow(rowIndex++);
Cell cell = row.createCell(colIndex++);
cell.setCellType(CellType.STRING);
cell.setCellValue("multiple");
cell = row.createCell(colIndex++);
cell.setCellType(CellType.STRING);
cell.setCellValue("unique");
writeRow(sheet, rowIndex++, 80d, "INDEX(A2:A7, MATCH(FALSE, ISBLANK(A2:A7), 0))");
writeRow(sheet, rowIndex++, 30d, "IFERROR(INDEX(A2:A7, MATCH(1, (COUNTIF(B2:B2, A2:A7) = 0) * (NOT(ISBLANK(A2:A7))), 0)), \"\")");
writeRow(sheet, rowIndex++, 30d, "IFERROR(INDEX(A2:A7, MATCH(1, (COUNTIF(B2:B3, A2:A7) = 0) * (NOT(ISBLANK(A2:A7))), 0)), \"\")");
writeRow(sheet, rowIndex++, 2d, "IFERROR(INDEX(A2:A7, MATCH(1, (COUNTIF(B2:B4, A2:A7) = 0) * (NOT(ISBLANK(A2:A7))), 0)), \"\")");
writeRow(sheet, rowIndex++, 30d, "IFERROR(INDEX(A2:A7, MATCH(1, (COUNTIF(B2:B5, A2:A7) = 0) * (NOT(ISBLANK(A2:A7))), 0)), \"\")");
writeRow(sheet, rowIndex++, 2d, "IFERROR(INDEX(A2:A7, MATCH(1, (COUNTIF(B2:B6, A2:A7) = 0) * (NOT(ISBLANK(A2:A7))), 0)), \"\")");
/*FileOutputStream fileOut = new FileOutputStream(filename);
wb.write(fileOut);
fileOut.close();*/
Workbook wbBack = testDataProvider.writeOutAndReadBack(wb);
assertNotNull(wbBack);
wbBack.close();
wb.close();
}
void writeRow(Sheet sheet, int rowIndex, Double col0Value, String col1Value) {
int colIndex = 0;
Row row = sheet.createRow(rowIndex);
// numeric value cell
Cell cell = row.createCell(colIndex++);
cell.setCellType(CellType.NUMERIC);
cell.setCellValue(col0Value);
// formula value cell
CellRangeAddress range = new CellRangeAddress(rowIndex, rowIndex, colIndex, colIndex);
sheet.setArrayFormula(col1Value, range);
}
} }