我使用Aspose-Cells和java在我的系统中导出excel模板。
在这种特殊情况下,我将生成一个电子表格,其中有两个我想要保护的表。在其中一个,我需要让用户只编辑4个单元格。其余的都应该受到保护。最简单的实现应该是:
问题是,我搜索是为了检查是否有可能这样做(保护整个工作表,只解锁几个单元格),而这似乎是不可能的。请..。告诉我我错了,有办法做到这一点,否则我将不得不锁定所有现存的单元格,并且只解锁其中的4个。就我使用另一个库(PHPExcel)的经验而言,它在性能上似乎非常昂贵(我必须将它应用于1000行以上的40列,所以它确实很昂贵)。
发布于 2013-08-05 07:13:26
使用Aspose.Cells for Java可以很容易地做到这一点。你可以的
见下面的样本。
String dataDir = "D:\\data\\";
// Create or load workbook
Workbook book = new Workbook();
// Get the first worksheet
Worksheet sheet = book.getWorksheets().get(0);
Style style;
StyleFlag flag = new StyleFlag();
// First lock all columns
for (int iCol=0 ; iCol<255 ; iCol++)
{
// Get style of the column
style = sheet.getCells().getColumns().get(iCol).getStyle();
// Apply locking to the style
style.setLocked(true);
flag.setLocked(true);
sheet.getCells().getColumns().get(iCol).applyStyle(style, flag);
}
// Get the range of cells, which we want to unlock
Range rangeUnlocked = sheet.getCells().createRange("A1:D4");
// Add a new style
int styleIndex = book.getStyles().add();
Style styleUnlocked = book.getStyles().get(styleIndex);
// Unlock cells
styleUnlocked.setLocked(false);
rangeUnlocked.setStyle(styleUnlocked);
// Protect the sheet
sheet.protect(ProtectionType.ALL);
//Save the Excel file
book.save(dataDir + "protectedrange.xlsx");我在Aspose工作,做一个开发人员,布道者。
https://stackoverflow.com/questions/17996913
复制相似问题