Java POI action Excel add locked cell protection

Source: Internet
Author: User

Excel book protection is very common, mainly do not want to let others modify Excel when used. This avoids malicious modification of data and increases the credibility of the data.

Here is a Java POI for setting book Protection:

You can use the Protectsheet (password) method of the Hssfsheet class.

The specific code is as follows:

 PackageCom.util;ImportJava.io.FileOutputStream;ImportOrg.apache.poi.hssf.usermodel.HSSFCell;ImportOrg.apache.poi.hssf.usermodel.HSSFRow;ImportOrg.apache.poi.hssf.usermodel.HSSFSheet;ImportOrg.apache.poi.hssf.usermodel.HSSFWorkbook; Public classPoicreateexcel { Public Static voidMain (string[] args)throwsException {//Create an Excel Workbook that corresponds to an Excel documentHssfworkbook WB =NewHssfworkbook (); Hssfsheet sheet= Wb.createsheet ("Sheet1"); //Sheet adding protection CodeSheet.protectsheet ("123"); //Create a line of sheet for ExcelHssfrow row = Sheet.createrow (0); //Create CellsHssfcell cell = Row.createcell (0); //assigning values to cells in ExcelCell.setcellvalue ("Hello World"); FileOutputStream OS=NewFileOutputStream ("G:\\workbook.xls");        Wb.write (OS);    Os.close (); }}

Java POI action Excel add locked cell protection

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.