excel导入数据库及反向导出Word文档下载推荐.docx
《excel导入数据库及反向导出Word文档下载推荐.docx》由会员分享,可在线阅读,更多相关《excel导入数据库及反向导出Word文档下载推荐.docx(12页珍藏版)》请在冰豆网上搜索。
/**
11.
*
得到sequence的nextval
12.
@param
sequenceName
13.
@return
14.
*/
15.
public
static
String
getSequence(String
sequenceName)
16.
nextval
=
"
;
17.
if(sequenceName
==
null
||
.equals(sequenceName))
18.
System.out.println("
name
is
null!
);
19.
return
null;
20.
}
else
21.
sequenceName.toUpperCase();
22.
sql
select
+
.nextval
nextid
from
user_sequences
where
sequence_name
'
23.
24.
25.
Statement
stmt
26.
Connection
conn
27.
ResultSet
rs
28.
29.
try
30.
TreatDB.getConnDB("
31.
if
(conn
!
null)
32.
conn.createStatement();
33.
stmt.executeQuery(sql);
34.
35.
if(rs
36.
while(rs.next())
37.
rs.getString("
nextid"
38.
39.
40.
41.
catch
(SQLException
e)
42.
SQLException
:
e);
43.
finally
44.
45.
rs.close();
46.
if(stmt
stmt.close();
47.
if(conn
conn.close();
48.
49.
//
TODO
Auto-generated
block
50.
51.
52.
nextval;
53.
54.
55./**
56.
一个插入、更新数据表的通用方法,传入一个sql脚本
57.
:
要进行操作的脚本
58.
发生变化的条数
59.
60.
int
updateSql(String
sql)
61.
dbName
62.
63.
64.
result
0;
65.
66.
TreatDB.getConnDB(dbName);
67.
68.
69.
//logger.info(sql);
70.
stmt.executeUpdate(sql);
71.
mit();
72.
73.
74.
75.
76.
conn.rollback();
77.
e1)
78.
update
error:
+e);
79.
80.
81.
82.
sql:
sql);
83.
84.
85.
(stmt
86.
87.
88.
89.
(Exception
ex)
90.
//do
nothing;
91.
92.
93.
94.
result;
95.
96.
97.}
导入EXCEL的程序代码:
1./**
2.
将Excel文件中的数据添加到数据库中
3.
新的监理信息 modify
by
heweiya
4.
5.
xlsFile,Excel文件
6.
7.
8.
addJLXlsForm(InputStream
is)
errStr
Workbook
rwb
Workbook.getWorkbook(is);
Workbook.getWorkbook(new
File(filePath+fileName));
获取第一张Sheet表
Sheet
sheet
rwb.getSheet(0);
获取总列数
rsColumns
sheet.getColumns();
rsColumns);
获取总行数
rsRows
sheet.getRows();
rsRows);
(rsColumns
<
19)
错误原因:
字段不全。
vErr.addElement(errStr);
i
startRows
1;
startColumn
while
(startRows
rsRows)
Hashtable
ht
new
Hashtable();
zj_id
DBOperate.getSequence("
S_JIANLI"
Cell
tmp
sheet.getCell(0,startRows);
sfzh
tmp.getContents();
sheet.getCell(1,startRows);
issueDate
issueDate_new
if(issueDate
&
issueDate.length()>
=6)
issueDate.substring(6)
issueDate.substring(3,5)
issueDate.substring(0,2);
sheet.getCell(2,startRows);
approveDate
approve_date_new
if(approveDate
approveDate.length()>
approveDate.substring(6)
approveDate.substring(3,5)
approveDate.substring(0,2);
sheet.getCell(3,startRows);
cerNo
55.
sheet.getCell(4,startRows);
jianliMajor
sheet.getCell(5,startRows);
department
sheet.getCell(6,startRows);
jianliName
sheet.getCell(7,startRows);
jianliSex
//毕业院校
sheet.getCell(8,startRows);
degree
//毕业时间
sheet.getCell(9,startRows);
cooleage
//所学专业
sheet.getCell(10,startRows);
company
//职务
sheet.getCell(11,startRows);
tech_post
84.//
工作单位
sheet.getCell(12,startRows);
address
88.//
职称
sheet.getCell(13,startRows);
postcode
sheet.getCell(14,startRows);
jianliTel
sheet.getCell(15,startRows);
mobile
97.
98.
sheet.getCell(16,startRows);
99.
email
100.
101.
sheet.getCell(17,startRows);
102.
birthday
103.
birthday_new
104.
if(birthday
birthday.length()>
birthday.substring(6)
birthday.substring(3,5)
birthday.substring(0,2);
105.
106.
107.
sheet.getCell(18,startRows);
108.
jianli_type
109.
//加入密码 modify
2007/05/17
110.
insert
into
jianli
values('
to_date('
'
yyyymmdd'
),to_date('
111.
approve_date_new