| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- package UIM.WGJ;
- import org.apache.ibatis.session.SqlSession;
- import com.alibaba.excel.EasyExcel;
- import CoreFS.SA01.CoreIComponent;
- import CoreFS.SA06.CoreReturnObject;
- import QCM.COMMUNAL.VO.ExcelWGJ;
- import java.io.File;
- import java.io.FileInputStream;
- import java.io.FileNotFoundException;
- import java.io.FileOutputStream;
- import java.io.IOException;
- import java.io.InputStream;
- import java.net.URLDecoder;
- import java.text.DecimalFormat;
- import java.text.SimpleDateFormat;
- import java.util.ArrayList;
- import java.util.HashMap;
- import java.util.Iterator;
- import java.util.LinkedHashMap;
- import java.util.List;
- import java.util.Map;
-
- public class ImportEasyExcelUtil extends CoreIComponent{
- CoreReturnObject cro = new CoreReturnObject();
- SqlSession SqlSession =
- QCM.COMMUNAL.SqlSessionBuilder.openSqlSession();
- QCM.COMMUNAL.OrderSqMapper mapper = SqlSession.getMapper(QCM.COMMUNAL.OrderSqMapper.class);
-
- public CoreReturnObject dateImport(byte[] bdate,String fileUrl,String opman){
- CoreReturnObject cro = new CoreReturnObject();
- SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
- SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd");
- try{
- String fileName = fileUrl;
- if (!fileName.substring(fileName.lastIndexOf(".")).equals(".xls")
- && !fileName.substring(fileName.lastIndexOf(".")).equals(".xlsx")){
- cro.setV_errCode(-1);
- cro.setV_errMsg("请导入xls或者xlsx类型的EXCEL文件");
- throw new Exception("请导入xls或者xlsx类型的EXCEL文件");
- }
- String path = this.getClass().getClassLoader().getResource("/").getPath().replaceFirst("classes/", "excelConfig/");
- path =URLDecoder.decode(path,"utf-8");
- String pathFileName = null;
- if(fileName.substring(fileName.lastIndexOf(".")).equals(".xls")){
- pathFileName = path+"temp3.xls";
- }
- if(fileName.substring(fileName.lastIndexOf(".")).equals(".xlsx")){
- pathFileName = path+"temp3.xlsx";
- }
- File file = new File(pathFileName);
- FileOutputStream out = new FileOutputStream(file);
- out.write(bdate);
- out.close();
- EasyExcel.read(pathFileName,ExcelWGJ.class,new ExcelModelListener(opman)).sheet().doRead();
- }catch(Exception e){
- e.printStackTrace();
- SqlSession.rollback();
- SqlSession.close();
- cro.setV_errCode(-1);
- cro.setV_errMsg("导入外购卷失败"+e.getMessage());
- return cro;
- }
-
- cro.setV_errCode(1);
- return cro;
- }
- }
|