导出excel

来源:互联网 发布:南阳理工软件 编辑:程序博客网 时间:2024/06/07 22:24

记录ExcelUtils.java测试函数

------------------------------------------------------------------------------------------------------------------

public static void main(String[] args) {
HSSFWorkbook workbook = new HSSFWorkbook();
    ExcelUtils excelTool = new ExcelUtils(workbook);
    excelTool.setSheetName("成绩表");
    excelTool.setSheetDesc("测试数据");
    
    String[]columns = new String[2];
columns[0] = "清运证编号";
columns[1] = "所属区域";
excelTool.setFieldNames(columns);
String [][] datas = new String [2][2];
datas[0][0] = "110";
datas[0][1] = "河西区";

datas[1][0] = "120";
datas[1][1] = "河东区";
File outFile = new File("C://text.xls");
try {
excelTool.setDatas(datas);
excelTool.buildExcelDocument();
FileOutputStream stream = new FileOutputStream(outFile);
workbook.write(stream);
stream.flush();
stream.close();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}