金蝶纯java代码Exce上传数据l

来源:互联网 发布:手机淘宝怎么跟踪物流 编辑:程序博客网 时间:2024/06/08 19:19
ArrayList<String> sqlList = new ArrayList<String>(); 
String sql=null;
int result = 0;
String path = null;
JFileChooser fileChooser = new JFileChooser();
FileSystemView fsv = FileSystemView.getFileSystemView();
fileChooser.setCurrentDirectory(fsv.getHomeDirectory());
fileChooser.setDialogTitle("请选择要上传的文件...");
fileChooser.setApproveButtonText("确定");
fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
result = fileChooser.showOpenDialog(btnImport);

if (JFileChooser.APPROVE_OPTION == result) {
path=fileChooser.getSelectedFile().getPath();
Workbook rwb = null;
InputStream is = new FileInputStream(path);
rwb = Workbook.getWorkbook(is);
Sheet rs = rwb.getSheet(0);
try {
for (int k = 1; k < rs.getRows(); k++){
String fnume=rs.getCell(0, k).getContents();
String ftitle=rs.getCell(1, k).getContents();
String fauditStatus=rs.getCell(2, k).getContents();
String fauditResult=rs.getCell(3, k).getContents();
String fauditBeginTime=rs.getCell(4, k).getContents();
String fauditDitfinishTime=rs.getCell(5, k).getContents();
String fbeginnerId=rs.getCell(6, k).getContents();
String fbeginner=rs.getCell(7, k).getContents();
String fbeginDept=rs.getCell(8, k).getContents();
String fauditrEcord=rs.getCell(10, k).getContents();
String fproposer=rs.getCell(13, k).getContents();
String fproposerID=rs.getCell(14, k).getContents();
String fcompany=rs.getCell(16, k).getContents();
String fbank=rs.getCell(17, k).getContents();
String fcardNumber=rs.getCell(18, k).getContents();
String fcostDept=rs.getCell(21, k).getContents();
String fcostBu=rs.getCell(23, k).getContents();
String fcostDate=rs.getCell(25, k).getContents();
String fcostType=rs.getCell(26, k).getContents();
String fcostDescription=rs.getCell(27, k).getContents();
String famount=rs.getCell(28, k).getContents();
String famountTotal=rs.getCell(31, k).getContents();
String fproportionDept=rs.getCell(33, k).getContents();
String fproportionSubDept=rs.getCell(34, k).getContents();
String fproportionAmount=rs.getCell(35, k).getContents();
String fproportionType=rs.getCell(36, k).getContents();
sql ="/*dialect*/ INSERT INTO T_DingCost_SourceData(fid,FNUMBER,ftitle,fauditStatus,fauditResult,fauditBeginTime,FAUDITFINISHTIME," +
"fbeginnerId,fbeginner,fbeginDept,fauditrEcord,fproposer,fproposerID,fcompany,fbank,fcardNumber,fcostDept," +
"fcostBu,fcostDate,fcostType,fcostDescription,famount,famountTotal,fproportionDept,fproportionSubDept," +
"fproportionAmount,fproportionType,ffileName) VALUES (GET_ID(),'"+fnume+"','"+ftitle+"','"+fauditStatus+"','"+fauditResult+"',to_date('"+fauditBeginTime+"','yyyy-MM-dd HH24:MI:SS'),to_date('"+fauditDitfinishTime+"','yyyy-MM-dd HH24:MI:SS'),'"+fbeginnerId+"','"+fbeginner+"','"+fbeginDept+
"','"+fauditrEcord+"','"+fproposer+"','"+fproposerID+"','"+fcompany+"','"+fbank+"','"+fcardNumber+"','"+fcostDept+"','"+fcostBu+"',to_date('"+fcostDate+"','yyyy-MM-dd'),'"+fcostType+"','"+fcostDescription+"','"+famount+
"','"+famountTotal+"','"+fproportionDept+"','"+fproportionSubDept+"','"+fproportionAmount+"','"+fproportionType+"','"+path+"')";
sqlList.add(sql);
}
DingFeeDepartmentFactory.getRemoteInstance().getImport(sqlList);
MsgBox.showInfo("导入成功。");