Write a description of the POI read/write Excel

Source: Internet
Author: User
Tags try catch

Second, the POI write Excel file (in Excel2003 version for example, version 2007 is based on the file extension xlsx will hssfworkbook to Xssfworkbook, and its sheet, Row, cell and corresponding replacement)

1.//Create a work book

Hssfworkbook workbook = new Hssfworkbook ();

2.//Create Sheet page

Hssfsheet sheet = workbook.createsheet ("Sheet1");

3,//Create a row of data

Hssfrow firstrow = sheet.createrow (0);

4.//Create a cell on the first line

Hssfcell Firstrowcell = Firstrow.createcell (0);

5,//For cell assignment

Firstrowcell.setcellvalue ("abc");
6.//Create a File object

String Foldpath is the folder location to which you want to save the Excel file, not the full path to the file, and the Web site directly uses the virtual path to

File fold= new file (FilePath);

7,//Determine whether the folder exists, does not exist on the creation

if (!fold.exists ()) {fold.mkdirs ();}

8,///generally do not need to determine whether the file exists and create, because do not do other processing the new file will be created or overwrite the original file, the following is just a simple record for later use

File File = new file (FilePath, "Excel.xls");

File.createnewfile ();//Make sure the file is created with the folder present

9.//create file output stream

OutputStream outputstream = new FileOutputStream (filepath+ "/excel.xls");

10.//Write Workbook object to file stream

Workbook.write (OutputStream);

11.//Release Resources

Workbook.close ();
Outputstream.close ();

12, again, the above code is best to use try Catch

Write a description of the POI read/write Excel

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.