}
public HSSFAutoFilter setAutoFilter(CellRangeAddress range) {
-
-
InternalWorkbook workbook = _workbook.getWorkbook();
int sheetIndex = _workbook.getSheetIndex(this);
name = workbook.createBuiltInName(NameRecord.BUILTIN_FILTER_DB, sheetIndex + 1);
}
+ int firstRow = range.getFirstRow();
+
+ // if row was not given when constructing the range...
+ if(firstRow == -1) {
+ firstRow = 0;
+ }
+
// The built-in name must consist of a single Area3d Ptg.
- Area3DPtg ptg = new Area3DPtg(range.getFirstRow(), range.getLastRow(),
+ Area3DPtg ptg = new Area3DPtg(firstRow, range.getLastRow(),
range.getFirstColumn(), range.getLastColumn(),
false, false, false, false, sheetIndex);
name.setNameDefinition(new Ptg[]{ptg});
HSSFPatriarch p = createDrawingPatriarch();
for (int col = range.getFirstColumn(); col <= range.getLastColumn(); col++) {
p.createComboBox(new HSSFClientAnchor(0, 0, 0, 0,
- (short) col, range.getFirstRow(), (short) (col + 1), range.getFirstRow() + 1));
+ (short) col, firstRow, (short) (col + 1), firstRow + 1));
}
return new HSSFAutoFilter(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);
}
+
+ 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);
}
import org.apache.poi.hssf.HSSFTestDataSamples;
import org.apache.poi.hssf.record.PasswordRecord;
+import org.apache.poi.ss.usermodel.AutoFilter;
import org.apache.poi.ss.usermodel.BaseTestSheet;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CreationHelper;
assertEquals("Sheet should contain 8 tables", 8, tables.size());
assertNotNull("Sheet should contain a comments table", sheet.getCommentsTable(false));
}
+
+ public void testBug55723b(){
+ XSSFWorkbook wb = new XSSFWorkbook();
+ Sheet sheet = wb.createSheet();
+
+ // stored with a special name
+ assertNull(wb.getBuiltInName(XSSFName.BUILTIN_FILTER_DB, 0));
+
+ CellRangeAddress range = CellRangeAddress.valueOf("A:B");
+ AutoFilter filter = sheet.setAutoFilter(range);
+ assertNotNull(filter);
+
+ // stored with a special name
+ XSSFName name = wb.getBuiltInName(XSSFName.BUILTIN_FILTER_DB, 0);
+ assertNotNull(name);
+ assertEquals("Sheet0!$A:$B", name.getRefersToFormula());
+
+ range = CellRangeAddress.valueOf("B:C");
+ filter = sheet.setAutoFilter(range);
+ assertNotNull(filter);
+
+ // stored with a special name
+ name = wb.getBuiltInName(XSSFName.BUILTIN_FILTER_DB, 0);
+ assertNotNull(name);
+ assertEquals("Sheet0!$B:$C", name.getRefersToFormula());
+ }
}
import org.apache.poi.hssf.usermodel.RecordInspector.RecordCollector;
import org.apache.poi.ss.formula.ptg.Area3DPtg;
import org.apache.poi.ss.formula.ptg.Ptg;
+import org.apache.poi.ss.usermodel.AutoFilter;
import org.apache.poi.ss.usermodel.BaseTestSheet;
import org.apache.poi.ss.usermodel.DataValidation;
import org.apache.poi.ss.usermodel.DataValidationConstraint;
sheet.dumpDrawingRecords(true);*/
assertNull(sheet.getDrawingEscherAggregate());
}
+
+ public void testBug55723b() {
+ HSSFWorkbook wb = new HSSFWorkbook();
+ Sheet sheet = wb.createSheet();
+
+ // stored with a special name
+ assertNull(wb.getWorkbook().getSpecificBuiltinRecord(NameRecord.BUILTIN_FILTER_DB, 1));
+
+ CellRangeAddress range = CellRangeAddress.valueOf("A:B");
+ AutoFilter filter = sheet.setAutoFilter(range);
+ assertNotNull(filter);
+
+ // stored with a special name
+ NameRecord record = wb.getWorkbook().getSpecificBuiltinRecord(NameRecord.BUILTIN_FILTER_DB, 1);
+ assertNotNull(record);
+ }
}
import junit.framework.TestCase;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.util.PaneInformation;
import org.apache.poi.ss.ITestDataProvider;
import org.apache.poi.ss.SpreadsheetVersion;
Sheet sheet = wb.createSheet();
sheet.showInPane(2, 3);
}
+
+
+ public void testBug55723(){
+ Workbook wb = _testDataProvider.createWorkbook();
+ Sheet sheet = wb.createSheet();
+
+ CellRangeAddress range = CellRangeAddress.valueOf("A:B");
+ AutoFilter filter = sheet.setAutoFilter(range);
+ assertNotNull(filter);
+ // there seems to be currently no generic way to check the setting...
+
+ range = CellRangeAddress.valueOf("B:C");
+ filter = sheet.setAutoFilter(range);
+ assertNotNull(filter);
+ // there seems to be currently no generic way to check the setting...
+ }
+
+ public void testBug55723_Rows() {
+ HSSFWorkbook wb = new HSSFWorkbook();
+ Sheet sheet = wb.createSheet();
+
+ CellRangeAddress range = CellRangeAddress.valueOf("A4:B55000");
+ AutoFilter filter = sheet.setAutoFilter(range);
+ assertNotNull(filter);
+ }
+
+
+ public void testBug55723d_RowsOver65k() {
+ HSSFWorkbook wb = new HSSFWorkbook();
+ Sheet sheet = wb.createSheet();
+
+ CellRangeAddress range = CellRangeAddress.valueOf("A4:B75000");
+ AutoFilter filter = sheet.setAutoFilter(range);
+ assertNotNull(filter);
+ }
}