I am using apache-poi for generating the excel file. I need to make the 4th column read-only and the remaining 2 columns will be editable by the user.
I am using
Workbook wb = new HSSFWorkbook(); Sheet sheet =wb.createSheet(thismonth+" , "+thisYear); sheet.protectSheet("password");
the above makes the whole sheet un editable. if u want to make a particular column editable. assign a particular CellStyle to it. and make it editable by .setLocked(false);
Calendar cal = Calendar.getInstance();
int lastdate = cal.getActualMaximum(Calendar.DAY_OF_MONTH);
String[] monthName = {"January", "February",
"March", "April", "May", "June", "July",
"August", "September", "October", "November",
"December"};
String thismonth = monthName[cal.get(Calendar.MONTH)];
int thisYear = cal.get(Calendar.YEAR);
Workbook wb = new HSSFWorkbook();
Sheet sheet =wb.createSheet();
sheet.protectSheet("password");// making the sheet uneaditable.(password
protected)
CellStyle cs2 = wb.createCellStyle();
cs2.setLocked(false); //cells with this style will be editable.
cs2.setBorderBottom(BorderStyle.THICK);
cs2.setBorderTop(BorderStyle.THICK);
cs2.setBorderLeft(BorderStyle.THICK);
cs2.setBorderRight(BorderStyle.THICK);
cs2.setAlignment(HorizontalAlignment.CENTER);
cs2.setVerticalAlignment(VerticalAlignment.CENTER);
CellStyle cs3 = wb.createCellStyle();//cells with this style will not be editable
cs3.setBorderBottom(BorderStyle.THICK);
cs3.setBorderTop(BorderStyle.THICK);
cs3.setBorderLeft(BorderStyle.THICK);
cs3.setBorderRight(BorderStyle.THICK);
cs3.setAlignment(HorizontalAlignment.CENTER);
cs3.setVerticalAlignment(VerticalAlignment.CENTER);
for (int r=2;r