前台://把上传的 文件发送到相应Action
function upload(){
var tml = document.getElementById("fileId");
if(tml.value == ''){
Ext.MessageBox.alert('提示','请选择需要上传文件');
return;
}
Ext.Ajax.request({
url: '../manager/print!excelUpload.action',
form: Ext.fly('uploadForm'),
waitMsg: "正在保存数据...",
headers: {'Content-type':'multipart/form-data'},
isUpload: true,
success: function(response) {
var jsonObj = Ext.decode(response.responseText);
store.load();
},
failure: function (response) {
if(Ext.util.JSON.encode(response.status)==0){
Ext.MessageBox.alert('提示','无法连接到服务器,请检查网络是否正常');
} else {
Ext.MessageBox.alert('提示','操作出现异常,请与系统管理员联系');
}
}
});
这是后台:
public String excelUpload() throws FileNotFoundException, IOException {
//获取当前系统时间时分秒
SimpleDateFormat st = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String time = st.format(new Date());
//获取文件路径转换输入流
InputStream is =new FileInputStream(filenPathname);
//解析出来的 字符格式
WorkbookSettings workbookSettings = new WorkbookSettings();
workbookSettings.setEncoding("GBK");
try {
//创建工作薄对象 (Excel对象)
Workbook work =Workbook.getWorkbook(is,workbookSettings);
//获取工作薄中表
Sheet sheet =work.getSheet(0);
int rows = sheet.getRows();//获取总行数、
int cell =sheet.getColumns();//获取总列数
System.out.println(rows);
System.out.println(cell);
//循环所有行数
for (int i = 1; i < rows; i++) {
PtUploadOrderTmp pt= new PtUploadOrderTmp();
System.out.println("------------" + i);
String[] str = new String[cell];
//循环行下的每一列的值
//把每一行每一列的值循环出来
pt.setWaybillNo(sheet.getCell(0, i).getContents());
pt.setSenderAddress(sheet.getCell(1, i).getContents());
pt.setSenderCompany(sheet.getCell(2, i).getContents());
pt.setReceiverName(sheet.getCell(3, i).getContents());
pt.setReceiverPhone(sheet.getCell(4, i).getContents());
pt.setGoods(sheet.getCell(5, i).getContents());
pt.setPsc(BigDecimal.ONE); //件数 6
pt.setWeight(Double.valueOf(sheet.getCell(7, i).getContents()));//重量
pt.setVolume(BigDecimal.ZERO);//体积 8
pt.setCod(Double.valueOf(sheet.getCell(9, i).getContents()));//代收货款
pt.setPayment(sheet.getCell(10, i).getContents());//付款方式
try {
pt.setSendDate(new SimpleDateFormat("yyyy-MM-dd").parse(sheet.getCell(11, i).getContents()));
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}//发送时间
pt.setIsPrint(sheet.getCell(12, i).getContents().equals("是"));//是否打印
pt.setIsUpload(sheet.getCell(13, i).getContents().equals("是"));//是否上传
pt.setRemark1(sheet.getCell(14, i).getContents());//备注
pt.setBatchNo(time); //批次号
oderService.save(pt);
}
} catch (BiffException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return ajaxJson(time);
}