Results 1 to 6 of 6
  1. #1
    mkbmbattu is offline Member
    Join Date
    May 2013
    Posts
    2
    Rep Power
    0

    Default How to lock first two rows of an excel and remaining rows editable.

    I want to lock first two rows of an excel and other rows should be editable for the user.

  2. #2
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default Re: How to lock first two rows of an excel and remaining rows editable.

    Does this have anything to do with Java (the focus of these forums)?

    Within Excel you can lock cells (if memory serves me well). But if this has something to do with Java libraries that process this spreadsheet format, it would be a good idea to say which library you are talking about.

  3. #3
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default Re: How to lock first two rows of an excel and remaining rows editable.

    Does this have anything to do with Java (the focus of these forums)?

    Within Excel you can lock cells (if memory serves me well). But if this has something to do with Java libraries that process this spreadsheet format, it would be a good idea to say which library you are talking about.

    [Edit] OK, I've just seen that this is in the POI forum. Apologies for not reading more closely.

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,945
    Rep Power
    19

    Default Re: How to lock first two rows of an excel and remaining rows editable.

    The Row interface allows you to set a CellStyle across the entire row.
    CellStyle has a setLocked() method.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  5. #5
    mkbmbattu is offline Member
    Join Date
    May 2013
    Posts
    2
    Rep Power
    0

    Default Re: How to lock first two rows of an excel and remaining rows editable.

    Below is the code i am trying to lock first two rows,
    But it is locking entire sheet,

    public static void main(String[] args) throws IOException {

    HSSFWorkbook workbook = new HSSFWorkbook();
    Sheet sheet=workbook.createSheet();
    org.apache.poi.ss.usermodel.Row row1=sheet.createRow(0);
    org.apache.poi.ss.usermodel.Row row2=sheet.createRow(1);
    CellStyle cellStyle=workbook.createCellStyle();
    cellStyle.setLocked(true);
    row1.setRowStyle(cellStyle);
    row2.setRowStyle(cellStyle);
    sheet.protectSheet("ads");
    FileOutputStream fos = null;
    try {
    fos = new FileOutputStream(new File("CreateExcelDemo.xls"));
    workbook.write(fos);
    } catch (IOException e) {
    e.printStackTrace();
    } finally {
    if (fos != null) {
    try {
    fos.flush();
    fos.close();
    } catch (IOException e) {
    e.printStackTrace();
    }
    }
    }
    }

  6. #6
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,945
    Rep Power
    19

    Default Re: How to lock first two rows of an excel and remaining rows editable.

    Looks like Excel defaults all cells to "locked". You can see that if you just create a new workbook in Excel (not via POI).
    You might have to dig around and see if there's a way of changing that?
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. I am getting problem read excel file with 30000 rows using hssf
    By satyendra.kumar in forum Advanced Java
    Replies: 4
    Last Post: 06-29-2011, 02:43 PM
  2. Jtable rows
    By riddhishah28 in forum AWT / Swing
    Replies: 3
    Last Post: 02-18-2011, 06:24 AM
  3. Replies: 2
    Last Post: 03-16-2010, 08:24 PM
  4. How To Add More Rows To Excel Sheet In Java
    By JMartins in forum New To Java
    Replies: 0
    Last Post: 12-30-2009, 11:30 PM
  5. Counting Rows and Columns from Excel Sheet
    By Anish in forum Advanced Java
    Replies: 3
    Last Post: 12-24-2008, 06:56 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •