I need to prevent the cells in excel from being selected.and it shud be done through java code only.Is there any way to do it?
Here my program generates excel and I need that excel sheet to be protected and its cell from being selected and copied elsewhere.Someo ne can help??.
The below code helps in making excel read only, and prompts for password when being edited..So pwd protected.But i need the excel sheet to be protected from selection also
Here my program generates excel and I need that excel sheet to be protected and its cell from being selected and copied elsewhere.Someo ne can help??.
The below code helps in making excel read only, and prompts for password when being edited..So pwd protected.But i need the excel sheet to be protected from selection also
Code:
import java.io.*;
import org.apache.poi.hssf.usermodel.*;
public class PasswordProtectedExcelSheet {
public static void main(String arg[]) {
try{
FileOutputStream out = new FileOutputStream("c://Sample.xls");
HSSFWorkbook hssfworkbook = new HSSFWorkbook();
// hssfworkbook.writeProtectWorkbook("hai","hai"); --> shows same behaviour even if uncommented
HSSFSheet sheet = hssfworkbook.createSheet("welcome");
String N_NAME = "name";
HSSFRow row = sheet.createRow(0);
HSSFCell cell =row.createCell((short)0);
cell.setCellValue(N_NAME);
//Sets the password for the sheet
sheet.protectSheet("xyz");
hssfworkbook.write(out);
out.close();
} catch(Exception e){
e.printStackTrace();
System.out.println("Exception occured");
}
}
}
Comment