生成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