Facade 层 实现类 (@Service("samePeriodModelImportFacade"))
1、 获取cells 的方法
public Cells getCells(File file){
Cells cells = null;
License license = new License();
InputStream licenseStream = this.getClass().getResourceAsStream("/aspose.lic");
try{
license.setLicense(licenseStream);
FileInputStream fr = new FileInputStream(file);
Workbook wb = new Workbook(fr); Worksheet worksheet = wb.getWorksheets().get(0); cells = worksheet.getCells();}catch(Exception e){
e.printStackTrace();
}
return cells;
}
2、解析excel 的方法
public String analyExcel(File file){
String dis_no=null;
String dis_mp=null;
List<Object[ ]> insertParamList =new ArrayList<Object[ ]>();
Cells cells = this.getCells( file);
for(int i=1;i<cells.getMaxDataRow()+1;i++){ // 获取要数据的最大的行数
for(int j=0; j<35;j++){ //获取列数 例如35列
String cellsValue = cells.getRows().get(i).get(j).getStringValue(); // 获取的每一个单元格的数据 返回的是String 类型
if(j==0){
dis_no =cellsValue; // i=1 j=0
}
if( j==23){
dis_mp=cellsValue; // i =1 j=23
}
}
insertParamList.add(new Object[] {dis_no,dis_mp});
}
samePeriodModelImportDomainService.insertPspCellModel(insertParamList);
return "success";
}
service层实现类@Repository("samePeriodModelImportDomainService")
//批量插入数据库
public void insertPspCellModel(List<Object[]> insertParamList) {
String sql = "insert into psp_model(dis_no,dis_mp) values(?,?)";
this.getJdbcTemplate().batchUpdate(sql, insertCellParamList);
}
aspose.lic
<License>
<Data> <Products> <Product>Aspose.Total for Java</Product> <Product>Aspose.Words for Java</Product> </Products> <EditionType>Enterprise</EditionType> <SubscriptionExpiry>20991231</SubscriptionExpiry> <LicenseExpiry>20991231</LicenseExpiry> <SerialNumber>8bfe198c-7f0c-4ef8-8ff0-acc3237bf0d7</SerialNumber> </Data> <Signature>sNLLKGMUdF0r8O1kKilWAGdgfs2BvJb/2Xp8p5iuDVfZXmhppo+d0Ran1P9TKdjV4ABwAgKXxJ3jcQTqE/2IRfqwnPf8itN8aFZlV3TJPYeD3yWE7IT55Gz6EijUpC7aKeoohTb4w2fpox58wWoF3SNp6sK6jDfiAUGEHYJ9pjU=</Signature></License>