I'm new to this group, so I apologize if this question has already been 
answered. Thanks in advance for any assistance.

Question:

I'm using the POI 3.6-XSSF API<http://poi.apache.org/spreadsheet/index.html> to 
write Excel 2007 documents, and i'm having trouble getting specific user edit 
actions of a given sheet to lock (i.e. lockDeleteRows). The API says 
that<http://poi.apache.org/apidocs/org/apache/poi/xssf/usermodel/XSSFSheet.html#lockDeleteColumns%28%29>
 you need to call enableLocking() on the sheet but when I do that it locks 
everything and ignores my specific locking settings (example below). When I 
don't call it nothing is locked.



It seems this should work given the fact that specific methods are provided to 
give one this granular locking control at a sheet level. So how can I lock 
specific user edit actions of a workbook/worksheet using this API?


XSSFWorkbook wb = new XSSFWorkbook();
XSSFSheet sheet = wb.createSheet("Sheet1");
XSSFCell cell;

XSSFRow row = sheet.createRow(0);
cell = row.createCell(0, XSSFCell.CELL_TYPE_STRING); cell.setCellValue("Sku");
cell = row.createCell(1, XSSFCell.CELL_TYPE_STRING); 
cell.setCellValue("Category");
cell = row.createCell(2, XSSFCell.CELL_TYPE_STRING); 
cell.setCellValue("SubCategory");
cell = row.createCell(3, XSSFCell.CELL_TYPE_STRING); cell.setCellValue("Name");
cell = row.createCell(4, XSSFCell.CELL_TYPE_STRING); 
cell.setCellValue("DATE_ADDED");
cell = row.createCell(5, XSSFCell.CELL_TYPE_STRING); 
cell.setCellValue("SEO_DESCRIPTION");

row = sheet.createRow(1);
cell = row.createCell(0, XSSFCell.CELL_TYPE_STRING); 
cell.setCellValue("4bd2c24571534e098589");
cell = row.createCell(1, XSSFCell.CELL_TYPE_STRING); cell.setCellValue("CLUBS");
cell = row.createCell(2, XSSFCell.CELL_TYPE_STRING); 
cell.setCellValue("DRIVERS");
cell = row.createCell(3, XSSFCell.CELL_TYPE_STRING); cell.setCellValue("1112222 
-- ASFASDF");
cell = row.createCell(4, XSSFCell.CELL_TYPE_STRING); cell.setCellValue(new 
Date());
cell = row.createCell(5, XSSFCell.CELL_TYPE_STRING); 
cell.setCellValue("asdfhavsdvf absdfhvbashdv asvdfhavsfasdf");

sheet.lockDeleteColumns();
sheet.lockInsertColumns();
sheet.lockDeleteRows();

sheet.enableLocking(); // why does this call ignore the last 3 lock settings i 
just set???????????

OutputStream out;
try {
    out = new FileOutputStream("c:\\temp\\TestWB.xlsx", false);
    wb.write(out);
} catch (Exception e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}





Reply via email to