`
helloboy077
  • 浏览: 5464 次
  • 性别: Icon_minigender_1
  • 来自: 上海
最近访客 更多访客>>
文章分类
社区版块
存档分类
最新评论

auto generate

 
阅读更多
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();
		}
	}
}
  • jxl.jar (586.2 KB)
  • 下载次数: 1
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics