poi导入excel
2023-09-14 09:04:39 时间
import org.apache.commons.beanutils.PropertyUtils;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.apa
【POI框架实战】——POI设置Excel单元格格式 “这个excel中的数据怎么不能做加法啊?”、“标头这一行的字体怎么这么小啊,我都看不清”、“这一列能不能换个颜色,明显一些”、“你把这一列的数据给我留两个小数位。”、“这些数据能不能以货币的类型展示啊,就每个三位一个小逗号那种……”
EasyPoi导入Excel EasyPoi的导出Excel功能和导入功能同样简单。我之前强调过,EasyPoi的原理本质就是Poi,正如MyBatis Plus的本质原理就是MyBatis。POI导入功能可以参考如下地址:https://blog.csdn.net/justinqin/article/details/78769789POI导出功能可以参考如下地址:关于EasyPoi导出Excel 首先说下,我为什么要用到导入Excel功能? 因为业务需要有一个Excel表格里面装有数据,然后通过文件上传的形式,直接动态批量录入数据。
POI实现Excel导入导出 我们知道要创建一张excel你得知道excel由什么组成,比如说sheet也就是一个工作表格,例如一行,一个单元格,单元格格式,单元格内容格式…这些都对应着poi里面的一个类。 一个excel表格:
请看excel分类,其他的博客,下面的博客写的比较早,没啥太大利用价值,纯粹是复制代码
贴代码:
import org.apache.commons.beanutils.PropertyUtils; import org.apache.commons.io.FileUtils; import org.apache.commons.io.IOUtils; import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.Row; import org.apache.poi.ss.usermodel.Sheet; import org.apache.poi.ss.usermodel.Workbook; import org.apache.poi.xssf.usermodel.XSSFWorkbook;
@Override public List String upload(PProduct product, InputStream is,String lastName)throws Exception { HqlBean hqlBean = HqlBeanCacheUtil.gethqlBeanCache().get("cn.digitalpublishing.dao.PProductDao").get("getList"); String statusYes = DicCache.getIdByCode(DicConstants.DIC_STATUS, DicConstants.DATA_STATUS_AVAILABLE); Map String, Object condition = new HashMap String, Object Map String, Object params = new HashMap String, Object List String isbnList = new ArrayList String byte[] excelByte = IOUtils.toByteArray(is); Workbook xwb = null; try { if(lastName.equals("xlsx")){ xwb = new XSSFWorkbook(new ByteArrayInputStream(excelByte)); }else{ xwb = new HSSFWorkbook(new ByteArrayInputStream(excelByte)); Sheet sheet = xwb.getSheetAt(0); for (int i = sheet.getFirstRowNum() + 1; i = sheet.getPhysicalNumberOfRows(); i++) { condition.clear(); Row row = sheet.getRow(i); if (row != null) { Cell isbn = row.getCell(0); Cell title = row.getCell(1); Cell publish = row.getCell(2); Cell price = row.getCell(3); Cell firstAuthor = row.getCell(4); Cell translator = row.getCell(5); Cell size = row.getCell(6); Cell binding = row.getCell(7); Cell pubDate = row.getCell(8); String isDiagiTal = DicCache.getIdByCode(DicConstants.ISDIGITAL, DicConstants.ISDIGITAL_0); int packageNum = 4; int bookNum = 4; String isTeaching = "";//DicCache.getIdByCode(DicConstants.DIC_STATUS, DicConstants.DATA_STATUS_AVAILABLE)
if ((isbn != null)||title != null||publish != null||price != null||firstAuthor != null) { params.put("isbn", isbn.toString()); params.put("title", title.toString()); //params.put("publish", publish.toString()); 出版社 BigDecimal _price = new BigDecimal(price.toString()); params.put("price", _price); params.put("firstAuthor", firstAuthor.toString()); //PProduct _product = this.daoFacade.getProductDao().getList(params, "", hqlBean).get(0); List PProduct _listProduct = this.daoFacade.getProductDao().getList(params, "", hqlBean); if(_listProduct.size()==0){ ServiceFactory service = new ServiceFactoryImpl(); PProductTypeService saleItemService = service.getPProductTypeService(); PProductType productTypeByCode = saleItemService.getProductTypeByCode("book"); PProduct _proLine = new PProduct(); _proLine.setIsbn(isbn.toString()); _proLine.setTitle(title.toString()); _proLine.setPublish(publish.toString()); _proLine.setPrice(_price); _proLine.setFirstAuthor(firstAuthor.toString()); _proLine.setTranslator(translator.toString()); _proLine.setSize(size.toString()); _proLine.setBinding(binding.toString()); /*String _date = pubDate.toString(); SimpleDateFormat sdf=new SimpleDateFormat("yyyy-mm-dd"); Date cd=sdf.parse(_date); _proLine.setPubDate(cd);*/ _proLine.setIsDiagiTal(isDiagiTal); _proLine.setPackageNum(packageNum); _proLine.setBookNum(bookNum); _proLine.setIsTeaching(isTeaching); _proLine.setProductType(productTypeByCode); _proLine.setOwnerFlag(DicCache.getIdByCode(DicConstants.PRODUCT_OWNER_FLAG, DicConstants.PRODUCT_OWNER_FLAG_OTHER)); _proLine.setStatus(DicCache.getIdByCode(DicConstants.DIC_STATUS, DicConstants.DATA_STATUS_AVAILABLE)); _proLine.setCreateOn(new Date()); /*String projectCode = EditorailSerialCode.getCode(Integer.valueOf(DicConstants.CODE_TYPE_PROJECT), crmCorpTypeRelationship.getCorp().getCode()); _proLine.setCode(projectCode); _proLine.setProductIntegerNum(projectCode);*/ this.insertProduct(_proLine); }else{ isbnList.add(title.toString()); }else{ throw new RuntimeException("第"+i+"行数据不完整,请认真填写"); } catch (Exception e) { e.printStackTrace(); return isbnList; }
【POI框架实战】——POI设置Excel单元格格式 “这个excel中的数据怎么不能做加法啊?”、“标头这一行的字体怎么这么小啊,我都看不清”、“这一列能不能换个颜色,明显一些”、“你把这一列的数据给我留两个小数位。”、“这些数据能不能以货币的类型展示啊,就每个三位一个小逗号那种……”
EasyPoi导入Excel EasyPoi的导出Excel功能和导入功能同样简单。我之前强调过,EasyPoi的原理本质就是Poi,正如MyBatis Plus的本质原理就是MyBatis。POI导入功能可以参考如下地址:https://blog.csdn.net/justinqin/article/details/78769789POI导出功能可以参考如下地址:关于EasyPoi导出Excel 首先说下,我为什么要用到导入Excel功能? 因为业务需要有一个Excel表格里面装有数据,然后通过文件上传的形式,直接动态批量录入数据。
POI实现Excel导入导出 我们知道要创建一张excel你得知道excel由什么组成,比如说sheet也就是一个工作表格,例如一行,一个单元格,单元格格式,单元格内容格式…这些都对应着poi里面的一个类。 一个excel表格:
相关文章
- C#.NET将数组导入Excel源代码
- asp.net采用OLEDB方式导入Excel数据时提示:未在本地计算机上注册"Microsoft.Jet.OLEDB.4.0" 提供程序"
- CI框架--Excel导入与导出(引入php_Excel这个类)
- Office EXCEL 如何保留一位小数,并且单击这个单元格的时候没有一大串小数
- SQL server 导入数据 (excel导入到SQL server数据库)
- SQL server 导入数据 (excel导入到SQL server数据库)
- 关于Excel导入的问题记录
- 解决PHP生成UTF-8编码的CSV文件用Excel打开乱码的问题
- 【基于WinForm+Access局域网共享数据库的项目总结】之篇二:WinForm开发扇形图统计和Excel数据导出
- 根据XML配置规则导入Excel数据(五)ExcelReader XLS解析类
- fastadmin 中 Excel导入失败的原因
- SAP UI5 表格数据如何导出成 Excel 文件(Table Export As Excel)
- SAP CRM和Cloud for Customer的Excel导出功能比较
- 如何通过 Excel import 的方式导入测试数据到 SAP Commerce Cloud 服务器
- Atitit 学习方法 -------体系化学习方法 Excel 科目,分类,专业 三级分类。。 知识点。。 课程就是每一个知识点的详细化。。 比如经济学 类别专业xx概论知识点 3、金
- piap.excel 微软 时间戳转换mssql sql server文件时间戳转换unix 导入mysql
- Excel-开发者工具(WPS)
- 太强了,用 Python+Excel 制作天气预报表!
- 数据库导入Excel-从基础做起
- LabVIEW操作Excel报表时会丢失所有的非文本数据
- FastAdmin 导入 Excel 相关资料收集 (2018-08-14)
- JAVA操作Excel表格:模板的使用---生成导入模板_设置列宽及标题
- SpringBoot中使用Easyexcel实现Excel导入导出功能(一)
- SpringBoot中使用Easyexcel实现Excel导入导出功能(三)
- springboot使用jxls导出excel___(万能通用模板)--- SpringBoot导入、导出Excel文件___SpringBoot整合EasyExcel模板导出Excel
- ssm导出Excel____IE、chrom、Firefox文件中文乱码问题