Java读写Excel文件需要第三方jar包jxl.jar,下载地址如下:
http://download.youkuaiyun.com/detail/m0_37241851/9824192
直接上写excel文件的Demo,其中用到的test.xls文件需要提前创建
public static void main(String[] args) {
try {
OutputStream os = new FileOutputStream("d:\\test.xls");
//创建workbook
WritableWorkbook wwb = Workbook.createWorkbook(os);
//创建Excel工作表 指定名称和位置
WritableSheet ws = wwb.createSheet("sheettest",0);
// 将要写的内容加入到ws
for(int i=0;i<10;i++){
for(int j=0;j<10;j++){
Label label = new Label(i, j, "在位置:"+ i+","+j +"写入数据");
ws.addCell(label);
}
}
//写入工作表
wwb.write();
//关闭资源
wwb.close();
}catch (Exception e) {
e.printStackTrace();
}
}