
String name =
"xls\\hetongdaoqitixing.xls";

File file =
new File(name);
try {

Workbook wb = Workbook.getWorkbook(file);

WritableWorkbook book = Workbook.createWorkbook(
new File(
"xlsd\\hetongdaoqitixing.xls")

WritableSheet sheet = book.getSheet(0);
int cols = sheet.getColumns();

DB db =
new DB();

ResultSet rs = db.getCon().createStatement().executeQuery(
"select * from fcb_hetong where datediff(day,getDate(),止租日期)<=30 and datediff(day,getDate(),止租日期)>=0 and 合同状态='生效合同'");
while (rs.next()) {
int rows = sheet.getRows();
for (
int i = 0; i < cols; i++) {

sheet.addCell(
new Label(i,rows,rs.getString(i + 1).toString()));

}

}

book.write();

System.
out.println(
"成功");

book.close();

wb.close();

Runtime run=Runtime.getRuntime();

run.exec(
"C:\\Program Files\\Microsoft Office\\OFFICE11\\EXCEL.EXE xlsd\\hetongdaoqitixing.xls");

}
catch (Exception e1) {

e1.printStackTrace();

}
这个xls\\hetongdaoqitixing.xls这是自己建的EXCEL模版,建好之后要把导入的数据字段提前写在EXCEL中,负责导不进去!xlsd\\hetongdaoqitixing.xls这个建好以后就可以了!
转载于:https://blog.51cto.com/leelei/176686