<changes>
<release version="3.8-beta1" date="2010-??-??">
+ <action dev="poi-developers" type="add">50315 - Avoid crashing Excel when sorting XSSFSheet autofilter</action>
<action dev="poi-developers" type="add">50076 - Allow access from XSSFReader to sheet comments and headers/footers</action>
<action dev="poi-developers" type="add">50076 - Refactor XSSFEventBasedExcelExtractor to make it easier for you to have control over outputting the cell contents</action>
<action dev="poi-developers" type="fix">50258 - avoid corruption of XSSFWorkbook after applying XSSFRichTextRun#applyFont</action>
* <li> This defined name refers to a range to which an AutoFilter has been
* applied
*/
- public final static String BUILTIN_FILTER_DB = "_xlnm._FilterDatabase:";
+ public final static String BUILTIN_FILTER_DB = "_xlnm._FilterDatabase";
/**
* A built-in defined name that refers to a consolidation area
String ref = norm.formatAsString();
af.setRef(ref);
+ XSSFWorkbook wb = getWorkbook();
+ int sheetIndex = getWorkbook().getSheetIndex(this);
+ XSSFName name = wb.getBuiltInName(XSSFName.BUILTIN_FILTER_DB, sheetIndex);
+ if (name == null) {
+ name = wb.createBuiltInName(XSSFName.BUILTIN_FILTER_DB, sheetIndex);
+ name.getCTName().setHidden(true);
+ CellReference r1 = new CellReference(getSheetName(), range.getFirstRow(), range.getFirstColumn(), true, true);
+ CellReference r2 = new CellReference(null, range.getLastRow(), range.getLastColumn(), true, true);
+ String fmla = r1.formatAsString() + ":" + r2.formatAsString();
+ name.setRefersToFormula(fmla);
+ }
+
return new XSSFAutoFilter(this);
}
}
XSSFName name = getBuiltInName(XSSFName.BUILTIN_PRINT_AREA, sheetIndex);
if (name == null) {
name = createBuiltInName(XSSFName.BUILTIN_PRINT_AREA, sheetIndex);
- namedRanges.add(name);
}
//short externSheetIndex = getWorkbook().checkExternSheet(sheetIndex);
//name.setExternSheetNumber(externSheetIndex);
}
if (name == null) {
name = createBuiltInName(XSSFName.BUILTIN_PRINT_TITLE, sheetIndex);
- namedRanges.add(name);
}
String reference = getReferenceBuiltInRecord(name.getSheetName(), startColumn, endColumn, startRow, endRow);
return "$" + colRef.getCellRefParts()[2] + "$" + colRef.getCellRefParts()[1] + ":$" + colRef2.getCellRefParts()[2] + "$" + colRef2.getCellRefParts()[1];
}
- private XSSFName getBuiltInName(String builtInCode, int sheetNumber) {
+ XSSFName getBuiltInName(String builtInCode, int sheetNumber) {
for (XSSFName name : namedRanges) {
if (name.getNameName().equalsIgnoreCase(builtInCode) && name.getSheetIndex() == sheetNumber) {
return name;
* @throws IllegalArgumentException if sheetNumber is invalid
* @throws POIXMLException if such a name already exists in the workbook
*/
- private XSSFName createBuiltInName(String builtInName, int sheetNumber) {
+ XSSFName createBuiltInName(String builtInName, int sheetNumber) {
validateSheetIndex(sheetNumber);
CTDefinedNames names = workbook.getDefinedNames() == null ? workbook.addNewDefinedNames() : workbook.getDefinedNames();
+ ") already exists for sheet (" + sheetNumber + ")");
}
+ namedRanges.add(name);
return name;
}
public void testSetAutoFilter() {
XSSFWorkbook wb = new XSSFWorkbook();
- XSSFSheet sheet = wb.createSheet();
+ XSSFSheet sheet = wb.createSheet("new sheet");
sheet.setAutoFilter(CellRangeAddress.valueOf("A1:D100"));
assertEquals("A1:D100", sheet.getCTWorksheet().getAutoFilter().getRef());
+
+ // auto-filter must be registered in workboook.xml, see Bugzilla 50315
+ XSSFName nm = wb.getBuiltInName(XSSFName.BUILTIN_FILTER_DB, 0);
+ assertNotNull(nm);
+
+ assertEquals(0, nm.getCTName().getLocalSheetId());
+ assertEquals(true, nm.getCTName().getHidden());
+ assertEquals("_xlnm._FilterDatabase", nm.getCTName().getName());
+ assertEquals("'new sheet'!$A$1:$D$100", nm.getCTName().getStringValue());
}
public void testProtectSheet_lowlevel() {