1. Background of the problem
When you export an Excel table, you first build the sheet page, and the following describes how to build the sheet page
2. Realize the source code
/**
*
* @Project:
* @Title: Excelexport.java
* @Package: Report.utils
* @Description:
* @Author: Youhaidong
* @Date: November 2, 2015 6:29:22
* @Version:
*/
Package report.utils;
Import java.io.FileNotFoundException;
Import Java.io.FileOutputStream;
Import java.io.IOException;
Import Org.apache.poi.hssf.usermodel.HSSFSheet;
Import Org.apache.poi.hssf.usermodel.HSSFWorkbook;
/**
*
Export Excel
* @ClassName: Excelexport
* @Description:
* @Author: Youhaidong
* @Date: November 2, 2015 6:29:22
*
*/
public class Excelexport
{
/**
* @Title: Excelexport
* @Description:
* @param args
* @Date: November 2, 2015 6:29:22
* @return: void
* @throws
*/
@SuppressWarnings ({"Deprecation", "resource"})
public static void Main (string[] args)
{
Hssfworkbook workbook = new Hssfworkbook ();
Set Sheet page name
Hssfsheet sheet = workbook.createsheet ("Student table");
Sheet.setdefaultcolumnwidth ((short) 15);
FileOutputStream stream; try { //导出Excel学生表 stream = new FileOutputStream("d:/student.xls"); workbook.write(stream); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
}
3. Achieve results
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Java Export Excel sheet page