Bug 55723: Make HSSFSheet.setAutoFilter() behave equal to XSSF, also make XSSF work when setAutoFilter is called multiple times
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1554688 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
5e77641784
commit
d714d0da65
@ -2056,8 +2056,6 @@ public final class HSSFSheet implements org.apache.poi.ss.usermodel.Sheet {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public HSSFAutoFilter setAutoFilter(CellRangeAddress range) {
|
public HSSFAutoFilter setAutoFilter(CellRangeAddress range) {
|
||||||
|
|
||||||
|
|
||||||
InternalWorkbook workbook = _workbook.getWorkbook();
|
InternalWorkbook workbook = _workbook.getWorkbook();
|
||||||
int sheetIndex = _workbook.getSheetIndex(this);
|
int sheetIndex = _workbook.getSheetIndex(this);
|
||||||
|
|
||||||
@ -2067,8 +2065,15 @@ public final class HSSFSheet implements org.apache.poi.ss.usermodel.Sheet {
|
|||||||
name = workbook.createBuiltInName(NameRecord.BUILTIN_FILTER_DB, sheetIndex + 1);
|
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.
|
// 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(),
|
range.getFirstColumn(), range.getLastColumn(),
|
||||||
false, false, false, false, sheetIndex);
|
false, false, false, false, sheetIndex);
|
||||||
name.setNameDefinition(new Ptg[]{ptg});
|
name.setNameDefinition(new Ptg[]{ptg});
|
||||||
@ -2084,7 +2089,7 @@ public final class HSSFSheet implements org.apache.poi.ss.usermodel.Sheet {
|
|||||||
HSSFPatriarch p = createDrawingPatriarch();
|
HSSFPatriarch p = createDrawingPatriarch();
|
||||||
for (int col = range.getFirstColumn(); col <= range.getLastColumn(); col++) {
|
for (int col = range.getFirstColumn(); col <= range.getLastColumn(); col++) {
|
||||||
p.createComboBox(new HSSFClientAnchor(0, 0, 0, 0,
|
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);
|
return new HSSFAutoFilter(this);
|
||||||
|
@ -3194,12 +3194,13 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
|
|||||||
XSSFName name = wb.getBuiltInName(XSSFName.BUILTIN_FILTER_DB, sheetIndex);
|
XSSFName name = wb.getBuiltInName(XSSFName.BUILTIN_FILTER_DB, sheetIndex);
|
||||||
if (name == null) {
|
if (name == null) {
|
||||||
name = wb.createBuiltInName(XSSFName.BUILTIN_FILTER_DB, sheetIndex);
|
name = wb.createBuiltInName(XSSFName.BUILTIN_FILTER_DB, sheetIndex);
|
||||||
|
}
|
||||||
|
|
||||||
name.getCTName().setHidden(true);
|
name.getCTName().setHidden(true);
|
||||||
CellReference r1 = new CellReference(getSheetName(), range.getFirstRow(), range.getFirstColumn(), true, true);
|
CellReference r1 = new CellReference(getSheetName(), range.getFirstRow(), range.getFirstColumn(), true, true);
|
||||||
CellReference r2 = new CellReference(null, range.getLastRow(), range.getLastColumn(), true, true);
|
CellReference r2 = new CellReference(null, range.getLastRow(), range.getLastColumn(), true, true);
|
||||||
String fmla = r1.formatAsString() + ":" + r2.formatAsString();
|
String fmla = r1.formatAsString() + ":" + r2.formatAsString();
|
||||||
name.setRefersToFormula(fmla);
|
name.setRefersToFormula(fmla);
|
||||||
}
|
|
||||||
|
|
||||||
return new XSSFAutoFilter(this);
|
return new XSSFAutoFilter(this);
|
||||||
}
|
}
|
||||||
|
@ -21,6 +21,7 @@ import java.util.List;
|
|||||||
|
|
||||||
import org.apache.poi.hssf.HSSFTestDataSamples;
|
import org.apache.poi.hssf.HSSFTestDataSamples;
|
||||||
import org.apache.poi.hssf.record.PasswordRecord;
|
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.BaseTestSheet;
|
||||||
import org.apache.poi.ss.usermodel.Cell;
|
import org.apache.poi.ss.usermodel.Cell;
|
||||||
import org.apache.poi.ss.usermodel.CreationHelper;
|
import org.apache.poi.ss.usermodel.CreationHelper;
|
||||||
@ -1228,4 +1229,30 @@ public final class TestXSSFSheet extends BaseTestSheet {
|
|||||||
assertEquals("Sheet should contain 8 tables", 8, tables.size());
|
assertEquals("Sheet should contain 8 tables", 8, tables.size());
|
||||||
assertNotNull("Sheet should contain a comments table", sheet.getCommentsTable(false));
|
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());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -35,6 +35,7 @@ import org.apache.poi.hssf.record.aggregates.WorksheetProtectionBlock;
|
|||||||
import org.apache.poi.hssf.usermodel.RecordInspector.RecordCollector;
|
import org.apache.poi.hssf.usermodel.RecordInspector.RecordCollector;
|
||||||
import org.apache.poi.ss.formula.ptg.Area3DPtg;
|
import org.apache.poi.ss.formula.ptg.Area3DPtg;
|
||||||
import org.apache.poi.ss.formula.ptg.Ptg;
|
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.BaseTestSheet;
|
||||||
import org.apache.poi.ss.usermodel.DataValidation;
|
import org.apache.poi.ss.usermodel.DataValidation;
|
||||||
import org.apache.poi.ss.usermodel.DataValidationConstraint;
|
import org.apache.poi.ss.usermodel.DataValidationConstraint;
|
||||||
@ -1066,4 +1067,20 @@ public final class TestHSSFSheet extends BaseTestSheet {
|
|||||||
sheet.dumpDrawingRecords(true);*/
|
sheet.dumpDrawingRecords(true);*/
|
||||||
assertNull(sheet.getDrawingEscherAggregate());
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -21,6 +21,7 @@ import java.util.Iterator;
|
|||||||
|
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
|
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
||||||
import org.apache.poi.hssf.util.PaneInformation;
|
import org.apache.poi.hssf.util.PaneInformation;
|
||||||
import org.apache.poi.ss.ITestDataProvider;
|
import org.apache.poi.ss.ITestDataProvider;
|
||||||
import org.apache.poi.ss.SpreadsheetVersion;
|
import org.apache.poi.ss.SpreadsheetVersion;
|
||||||
@ -800,4 +801,39 @@ public abstract class BaseTestSheet extends TestCase {
|
|||||||
Sheet sheet = wb.createSheet();
|
Sheet sheet = wb.createSheet();
|
||||||
sheet.showInPane(2, 3);
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user