package com.test.excel;
import java.io.File;
import java.io.IOException;
import java.sql.SQLException;
import jxl.Cell;
import jxl.Sheet;
import jxl.Workbook;
import jxl.read.biff.BiffException;
public class JavaExcel {
private static final String INSERT_STR = "insert into cp_mm_lang_phrases(control, lbl_id, lang_id, lang_text,...) " +
"values( ?, ?, ?, ?,...);";
public static void main(String[] args) throws SQLException {
String insert = "insert into cp_mm_lang_phrases(control, lbl_id, lang_id, lang_text,...) " +
"values( ?, ?, ?, ?,...)";
String filePath = "test.xls";
try {
Workbook workbook = Workbook.getWorkbook(new File(filePath));
Sheet sheet = workbook.getSheet(0);
int row = sheet.getRows();
int col = sheet.getColumns();
for (int j = 1; j < row; j++) {
insert = INSERT_STR;
for(int idx = 1; idx < col;idx++){
Cell cell = sheet.getCell(idx, j);
String content = cell.getContents();
// System.out.print(content + "\t");
insert = insert.replaceFirst("\\?", "'" + content + "'");
}
System.out.println(insert);
}
} catch (BiffException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
auto generate
最新推荐文章于 2025-03-19 11:45:03 发布