Allow common tests to do auto-sizing even on SXSSF

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1729848 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Nick Burch 2016-02-11 15:13:01 +00:00
parent 2aa39f5bdb
commit a3966df033
4 changed files with 24 additions and 0 deletions

View File

@ -30,7 +30,9 @@ import org.apache.poi.POIDataSamples;
import org.apache.poi.ss.ITestDataProvider; import org.apache.poi.ss.ITestDataProvider;
import org.apache.poi.ss.SpreadsheetVersion; import org.apache.poi.ss.SpreadsheetVersion;
import org.apache.poi.ss.usermodel.FormulaEvaluator; import org.apache.poi.ss.usermodel.FormulaEvaluator;
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.xssf.streaming.SXSSFSheet;
import org.apache.poi.xssf.streaming.SXSSFWorkbook; import org.apache.poi.xssf.streaming.SXSSFWorkbook;
import org.apache.poi.xssf.usermodel.XSSFFormulaEvaluator; import org.apache.poi.xssf.usermodel.XSSFFormulaEvaluator;
import org.apache.poi.xssf.usermodel.XSSFWorkbook; import org.apache.poi.xssf.usermodel.XSSFWorkbook;
@ -85,6 +87,13 @@ public final class SXSSFITestDataProvider implements ITestDataProvider {
return wb; return wb;
} }
@Override
public void trackColumnsForAutosizing(Sheet sheet, int...columns) {
for (int cn : columns) {
((SXSSFSheet)sheet).trackColumnForAutoSizing(cn);
}
}
@Override @Override
public FormulaEvaluator createFormulaEvaluator(Workbook wb) { public FormulaEvaluator createFormulaEvaluator(Workbook wb) {
return new XSSFFormulaEvaluator(((SXSSFWorkbook) wb).getXSSFWorkbook()); return new XSSFFormulaEvaluator(((SXSSFWorkbook) wb).getXSSFWorkbook());

View File

@ -21,6 +21,7 @@ import org.apache.poi.POIDataSamples;
import org.apache.poi.ss.ITestDataProvider; import org.apache.poi.ss.ITestDataProvider;
import org.apache.poi.ss.SpreadsheetVersion; import org.apache.poi.ss.SpreadsheetVersion;
import org.apache.poi.ss.usermodel.FormulaEvaluator; import org.apache.poi.ss.usermodel.FormulaEvaluator;
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.xssf.usermodel.XSSFFormulaEvaluator; import org.apache.poi.xssf.usermodel.XSSFFormulaEvaluator;
import org.apache.poi.xssf.usermodel.XSSFWorkbook; import org.apache.poi.xssf.usermodel.XSSFWorkbook;
@ -53,6 +54,9 @@ public final class XSSFITestDataProvider implements ITestDataProvider {
return new XSSFWorkbook(); return new XSSFWorkbook();
} }
@Override
public void trackColumnsForAutosizing(Sheet sheet, int...columns) {}
@Override @Override
public FormulaEvaluator createFormulaEvaluator(Workbook wb) { public FormulaEvaluator createFormulaEvaluator(Workbook wb) {
return new XSSFFormulaEvaluator((XSSFWorkbook) wb); return new XSSFFormulaEvaluator((XSSFWorkbook) wb);

View File

@ -25,6 +25,7 @@ import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.ITestDataProvider; import org.apache.poi.ss.ITestDataProvider;
import org.apache.poi.ss.SpreadsheetVersion; import org.apache.poi.ss.SpreadsheetVersion;
import org.apache.poi.ss.usermodel.FormulaEvaluator; import org.apache.poi.ss.usermodel.FormulaEvaluator;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook; import org.apache.poi.ss.usermodel.Workbook;
/** /**
@ -59,6 +60,9 @@ public final class HSSFITestDataProvider implements ITestDataProvider {
return new HSSFWorkbook(); return new HSSFWorkbook();
} }
@Override
public void trackColumnsForAutosizing(Sheet sheet, int...columns) {}
@Override @Override
public FormulaEvaluator createFormulaEvaluator(Workbook wb) { public FormulaEvaluator createFormulaEvaluator(Workbook wb) {
return new HSSFFormulaEvaluator((HSSFWorkbook) wb); return new HSSFFormulaEvaluator((HSSFWorkbook) wb);

View File

@ -18,6 +18,7 @@
package org.apache.poi.ss; package org.apache.poi.ss;
import org.apache.poi.ss.usermodel.FormulaEvaluator; import org.apache.poi.ss.usermodel.FormulaEvaluator;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook; import org.apache.poi.ss.usermodel.Workbook;
/** /**
@ -45,6 +46,12 @@ public interface ITestDataProvider {
* @return an instance of Workbook * @return an instance of Workbook
*/ */
Workbook createWorkbook(); Workbook createWorkbook();
/**
* Only matters for SXSSF - enables tracking of the column
* widths so that autosizing can work. No-op on others.
*/
void trackColumnsForAutosizing(Sheet sheet, int...columns);
/** /**
* Creates the corresponding {@link FormulaEvaluator} for the * Creates the corresponding {@link FormulaEvaluator} for the