文件名称:java解析excel到mysql代码存档.txt
文件大小:4KB
文件格式:JAVA
更新时间:2013-11-10 15:02:01
java解析excel到mysql代码存档.txt
package importEx;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import jxl.Cell;
import jxl.Sheet;
import jxl.Workbook;
import jxl.read.biff.BiffException;
public class ImportExcelTest {
/**
*
* 只能插入单选题和多选题
*
* @param args
* @throws BiffException
* @throws IOException
*/
public static void main(String[] args) throws BiffException, IOException {
//文件路径
InputStream is=new FileInputStream("d:\\c.xls");
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection conn = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/exam", "root", "aaaaaa");
PreparedStatement prep = conn.prepareStatement("insert into t_exam_question values (null,null,null,?,null,?,?,?,?,?,?,?,?,?,?,null,null)");
Workbook wb = Workbook.getWorkbook(is);
Sheet sheet = wb.getSheet(0); //第几张表格 从零开始
String sheetName = sheet.getName();
System.out.println("sheet表名(工作薄名): "+sheetName);
String question_content = ""; //题目内容
String question_type= ""; //题目类型
//用来得到单元格的内容
String choice_A = ""; //A
String choice_B=""; //B
String choice_C=""; //C
String choice_D=""; //D
String choice_E=""; //E
String choice_F=""; //F
String difficulty =""; //难度
String answer=""; //答案
String knowledge_type=""; //知识结构
if(sheet!=null)
{
// 获取表格总列数
int rsColumns = sheet.getColumns();
System.out.println("表格总列数rsColumns = " + rsColumns);
// 获取表格总行数
int rsRows = sheet.getRows();
System.out.println("表格总行数 rsRows = " + rsRows);
for(int rowNum = 1;rowNum