prevent cells in excel sheet from being selected through java

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Ramya28
    New Member
    • Mar 2010
    • 9

    prevent cells in excel sheet from being selected through java

    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

    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");
            }
        } 
       
      }
  • Ramya28
    New Member
    • Mar 2010
    • 9

    #2
    Is there any way to disable cells in excel sheet being selected??

    And can it be done by coding through Java??

    Comment

    • jkmyoung
      Recognized Expert Top Contributor
      • Mar 2006
      • 2057

      #3
      I would write a vbmacro that checks the onSelection event.
      Detect if any of the Selection overlaps with forbidden cells.
      If so, reset selection to some other cell, eg, A1, and possibly flash a prompt saying that the cell can not be selected.

      Add this macro to your sheet. I am unfamiliar with the HSSFWorkbook class structure.

      Comment

      • Ramya28
        New Member
        • Mar 2010
        • 9

        #4
        Hi,

        Lets forget HSSF..
        Other than Vb macro .. is there any way to prevent selection in excel or prevent copying?
        be it in , Jsp, java.. using any api , even JXL ..
        Am breaking my head...
        any help ???

        Comment

        • jkmyoung
          Recognized Expert Top Contributor
          • Mar 2006
          • 2057

          #5
          What do you really want? Prevent people from selecting, or prevent people from copying?

          It may be possible with cell/worksheet properties if you protect the sheet before hand.

          Excel only uses VB for the most part. You could try some backdoor method through an add-in .dll, but that seems like more work than necessary.

          Comment

          • Ramya28
            New Member
            • Mar 2010
            • 9

            #6
            Originally posted by jkmyoung
            What do you really want? Prevent people from selecting, or prevent people from copying?

            It may be possible with cell/worksheet properties if you protect the sheet before hand.

            Excel only uses VB for the most part. You could try some backdoor method through an add-in .dll, but that seems like more work than necessary.
            yeah...
            I ve protected the sheet..that means noone can edit it as such.(password protected using jxl Api)
            But I don want anyone to use ctrl+a n copy it in a new exel n edit my contents,.. So it would be better if selection itself is disabled..so I need help there..

            Comment

            Working...