Java匯出Excel Sheet頁
1、問題背景
匯出Excel表格時,首先要產生Sheet頁,下面將介紹如何產生Sheet頁
2、實現源碼
/**
*
* @Project:
* @Title:ExcelExport.java
* @Package:report.utils
* @Description:
* @Author:YouHaiDong
* @Date:2015年11月2日 下午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;
/**
*
匯出Excel
* @ClassName:ExcelExport
* @Description:
* @Author:YouHaiDong
* @Date:2015年11月2日 下午6:29:22
*
*/
public class ExcelExport
{
/**
* @Title:ExcelExport
* @Description:
* @param args
* @Date:2015年11月2日 下午6:29:22
* @return: void
* @throws
*/
@SuppressWarnings({ “deprecation”, “resource” })
public static void main(String[] args)
{
HSSFWorkbook workbook = new HSSFWorkbook();
//設定sheet頁名稱
HSSFSheet sheet = workbook.createSheet(“學生表”);
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、實現結果