生成Excel文件到指定路径下


public class ExcelCreate{

    public static void main(String[] args){

        File gile =null;

        String headers={"ID","名字","性别","年龄","职业","地址"};

        try{

           gile = new File("C:/excelfile.xls");

            OutputStream os = new FileOutputStream(gile);

           //创建Excel文件

            WriteableWorkbook wwb = Workbook.createWokbook(gile);

            //设置样式

            WriteableCellFormat wcf = new WriteableCellFormat();//单元格定义

            wcf.setAlignment(jxf.format.Alignment.CENTER);//设置对齐方式

            wcf.setBorder(jxf.format.Border.ALL, jxf.format.BorderLineStyle.THIN);

 

            WriteableSheet ws = wwb.createSheet("sheetname", 0);//设置工作薄的名字

            //写入数据

            for(int i=0; i < headers.length; i++){

                Label label = new Label(i, 0, headera[i], wcf);

                ws.addCell(label);

            }

            wwb.write();

            os.flush();

        }catch(Exception e){

             e.printStackTrace();

        }finally{

            wwb.close();

            os.close();

        }

    }

}


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM