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();
}
}
}