设置filter
String lastIndexString = CellReference.convertNumToColString(lastStakeholderColNum);
//in this format , initial value is 1.Filer and sort region should be same.
String sqref = "A" + DATA_RECORD_START_ROW + ":" + lastIndexString + (validationRange+1);
impactDataSheet.setAutoFilter(CellRangeAddress.valueOf(sqref));
impactDataSheet.lockAutoFilter(false);
impactDataSheet.lockFormatColumns(false);
impactDataSheet.lockFormatRows(false);
impactDataSheet.lockFormatCells(false);
设置sort
CTProtectedRange protectedRange = impactDataSheet.getCTWorksheet().addNewProtectedRanges().addNewProtectedRange();
protectedRange.setName("enableSorting");
protectedRange.setSqref(Arrays.asList(sqref));
CTSheetProtection sheetProtection = impactDataSheet.getCTWorksheet().getSheetProtection();
sheetProtection.setSort(false);
impactDataSheet.protectSheet("");
设置protect之后,未被sort覆盖的范围都不可编辑。
filter与sort的范围域需要相同,否则会不可编辑,sort是一个改变值的操作,没有被sort覆盖到的区域将不会根据行内sort功能的使用而变化,且会将cell的属性变为可编辑。
pom 中引入CTProtectedRange类的包:
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>ooxml-schemas</artifactId>
<version>1.3</version>
</dependency>
网友评论