使用jxl保存excel文件
public void writeExcel(String filepath, String filename) throws RowsExceededException, WriteException{
//开始写入excel,创建模型文件头
String[] titleA = {"name","lng","lat","area","ppl"};
//创建Excel文件,B库CD表文件
File fileA = new File(filepath + filename);
if(fileA.exists()){
//如果文件存在就删除
fileA.delete();
}
try {
fileA.createNewFile();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
创建工作簿
WritableWorkbook workbookA;
try {
workbookA = Workbook.createWorkbook(fileA);
//创建sheet
WritableSheet sheetA = workbookA.createSheet("sheet1", 0);
Label labelA = null;
//设置列名
for(int i = 0; i < titleA.length; i++)
{
labelA = new Label(i,0,titleA[i]);
sheetA.addCell(labelA);
}
//获取数据源
for(int i = 1; i < 10; i++)
{
labelA = new Label(0,i,i+" ");
sheetA.addCell(labelA);
labelA = new Label(1,i,"20180101" + i);
sheetA.addCell(labelA);
labelA = new Label(2,i,"开发00"+i);
sheetA.addCell(labelA);
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}