array(2) { ["docs"]=> array(10) { [0]=> array(10) { ["id"]=> string(3) "428" ["text"]=> string(77) "Visual Studio 2017 单独启动MSDN帮助(Microsoft Help Viewer)的方法" ["intro"]=> string(288) "目录 ECharts 异步加载 ECharts 数据可视化在过去几年中取得了巨大进展。开发人员对可视化产品的期望不再是简单的图表创建工具,而是在交互、性能、数据处理等方面有更高的要求。 chart.setOption({ color: [ " ["username"]=> string(8) "DonetRen" ["tagsname"]=> string(55) "Visual Studio 2017|MSDN帮助|C#程序|.NET|Help Viewer" ["tagsid"]=> string(23) "[401,402,403,"300",404]" ["catesname"]=> string(0) "" ["catesid"]=> string(2) "[]" ["createtime"]=> string(10) "1511400964" ["_id"]=> string(3) "428" } [1]=> array(10) { ["id"]=> string(3) "427" ["text"]=> string(42) "npm -v;报错 cannot find module "wrapp"" ["intro"]=> string(288) "目录 ECharts 异步加载 ECharts 数据可视化在过去几年中取得了巨大进展。开发人员对可视化产品的期望不再是简单的图表创建工具,而是在交互、性能、数据处理等方面有更高的要求。 chart.setOption({ color: [ " ["username"]=> string(4) "zzty" ["tagsname"]=> string(50) "node.js|npm|cannot find module "wrapp“|node" ["tagsid"]=> string(19) "[398,"239",399,400]" ["catesname"]=> string(0) "" ["catesid"]=> string(2) "[]" ["createtime"]=> string(10) "1511400760" ["_id"]=> string(3) "427" } [2]=> array(10) { ["id"]=> string(3) "426" ["text"]=> string(54) "说说css中pt、px、em、rem都扮演了什么角色" ["intro"]=> string(288) "目录 ECharts 异步加载 ECharts 数据可视化在过去几年中取得了巨大进展。开发人员对可视化产品的期望不再是简单的图表创建工具,而是在交互、性能、数据处理等方面有更高的要求。 chart.setOption({ color: [ " ["username"]=> string(12) "zhengqiaoyin" ["tagsname"]=> string(0) "" ["tagsid"]=> string(2) "[]" ["catesname"]=> string(0) "" ["catesid"]=> string(2) "[]" ["createtime"]=> string(10) "1511400640" ["_id"]=> string(3) "426" } [3]=> array(10) { ["id"]=> string(3) "425" ["text"]=> string(83) "深入学习JS执行--创建执行上下文(变量对象,作用域链,this)" ["intro"]=> string(288) "目录 ECharts 异步加载 ECharts 数据可视化在过去几年中取得了巨大进展。开发人员对可视化产品的期望不再是简单的图表创建工具,而是在交互、性能、数据处理等方面有更高的要求。 chart.setOption({ color: [ " ["username"]=> string(7) "Ry-yuan" ["tagsname"]=> string(33) "Javascript|Javascript执行过程" ["tagsid"]=> string(13) "["169","191"]" ["catesname"]=> string(0) "" ["catesid"]=> string(2) "[]" ["createtime"]=> string(10) "1511399901" ["_id"]=> string(3) "425" } [4]=> array(10) { ["id"]=> string(3) "424" ["text"]=> string(30) "C# 排序技术研究与对比" ["intro"]=> string(288) "目录 ECharts 异步加载 ECharts 数据可视化在过去几年中取得了巨大进展。开发人员对可视化产品的期望不再是简单的图表创建工具,而是在交互、性能、数据处理等方面有更高的要求。 chart.setOption({ color: [ " ["username"]=> string(9) "vveiliang" ["tagsname"]=> string(0) "" ["tagsid"]=> string(2) "[]" ["catesname"]=> string(8) ".Net Dev" ["catesid"]=> string(5) "[199]" ["createtime"]=> string(10) "1511399150" ["_id"]=> string(3) "424" } [5]=> array(10) { ["id"]=> string(3) "423" ["text"]=> string(72) "【算法】小白的算法笔记:快速排序算法的编码和优化" ["intro"]=> string(288) "目录 ECharts 异步加载 ECharts 数据可视化在过去几年中取得了巨大进展。开发人员对可视化产品的期望不再是简单的图表创建工具,而是在交互、性能、数据处理等方面有更高的要求。 chart.setOption({ color: [ " ["username"]=> string(9) "penghuwan" ["tagsname"]=> string(6) "算法" ["tagsid"]=> string(7) "["344"]" ["catesname"]=> string(0) "" ["catesid"]=> string(2) "[]" ["createtime"]=> string(10) "1511398109" ["_id"]=> string(3) "423" } [6]=> array(10) { ["id"]=> string(3) "422" ["text"]=> string(64) "JavaScript数据可视化编程学习(二)Flotr2,雷达图" ["intro"]=> string(288) "目录 ECharts 异步加载 ECharts 数据可视化在过去几年中取得了巨大进展。开发人员对可视化产品的期望不再是简单的图表创建工具,而是在交互、性能、数据处理等方面有更高的要求。 chart.setOption({ color: [ " ["username"]=> string(7) "chengxs" ["tagsname"]=> string(28) "数据可视化|前端学习" ["tagsid"]=> string(9) "[396,397]" ["catesname"]=> string(18) "前端基本知识" ["catesid"]=> string(5) "[198]" ["createtime"]=> string(10) "1511397800" ["_id"]=> string(3) "422" } [7]=> array(10) { ["id"]=> string(3) "421" ["text"]=> string(36) "C#表达式目录树(Expression)" ["intro"]=> string(288) "目录 ECharts 异步加载 ECharts 数据可视化在过去几年中取得了巨大进展。开发人员对可视化产品的期望不再是简单的图表创建工具,而是在交互、性能、数据处理等方面有更高的要求。 chart.setOption({ color: [ " ["username"]=> string(4) "wwym" ["tagsname"]=> string(0) "" ["tagsid"]=> string(2) "[]" ["catesname"]=> string(4) ".NET" ["catesid"]=> string(7) "["119"]" ["createtime"]=> string(10) "1511397474" ["_id"]=> string(3) "421" } [8]=> array(10) { ["id"]=> string(3) "420" ["text"]=> string(47) "数据结构 队列_队列实例:事件处理" ["intro"]=> string(288) "目录 ECharts 异步加载 ECharts 数据可视化在过去几年中取得了巨大进展。开发人员对可视化产品的期望不再是简单的图表创建工具,而是在交互、性能、数据处理等方面有更高的要求。 chart.setOption({ color: [ " ["username"]=> string(7) "idreamo" ["tagsname"]=> string(40) "C语言|数据结构|队列|事件处理" ["tagsid"]=> string(23) "["246","247","248",395]" ["catesname"]=> string(12) "数据结构" ["catesid"]=> string(7) "["133"]" ["createtime"]=> string(10) "1511397279" ["_id"]=> string(3) "420" } [9]=> array(10) { ["id"]=> string(3) "419" ["text"]=> string(47) "久等了,博客园官方Android客户端发布" ["intro"]=> string(288) "目录 ECharts 异步加载 ECharts 数据可视化在过去几年中取得了巨大进展。开发人员对可视化产品的期望不再是简单的图表创建工具,而是在交互、性能、数据处理等方面有更高的要求。 chart.setOption({ color: [ " ["username"]=> string(3) "cmt" ["tagsname"]=> string(0) "" ["tagsid"]=> string(2) "[]" ["catesname"]=> string(0) "" ["catesid"]=> string(2) "[]" ["createtime"]=> string(10) "1511396549" ["_id"]=> string(3) "419" } } ["count"]=> int(200) } 222 POI 4.0 读取Excel - 爱码网

...

package POIXLS;

import java.io.File;
import java.io.FileInputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellType; 
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.ss.usermodel.WorkbookFactory;

import java.sql.*;

//import com.e6soft.base.service.JService;
//import com.e6soft.base.annotations.JCall;
//import com.e6soft.base.util.WebUtil;
 
public class CS  {
    
    public static List<Map<String, Object>> E() throws Exception{
        /*用户先上传文件至服务器的临时位置,然后写一个读取excel的方法,程序从服务器的临时位置读取excel文件;
         * 然后循环工作表和行,将单元格的内容存入集合;再上传至临时表(每次先清空),再根据sku(主键)更新正式数据库即可完成导入文件更新字段信息。*/
          
        String widz =  "C:\\Users\\killer\\Desktop\\参考\\工作簿1.xls"; // 文件在服务器的地址
        // 获得文件所在地
        File file = new File(widz);
        
        List<Map<String, Object>> qbsj = new ArrayList<Map<String,Object>>();
        // 读取文件
        try {  
            //同时支持Excel 2003、2007  
            //File excelFile = new File("F:\\MyEclipse 2017 CI\\SY\\src\\word\\aa.xls"); //创建文件对象  
            FileInputStream is = new FileInputStream(file); //文件流  
            Workbook workbook = WorkbookFactory.create(is); //这种方式 Excel 2003/2007/2010 都是可以处理的  
            int sheetCount = workbook.getNumberOfSheets();  //Sheet的数量  
            
            //遍历每个Sheet  
            //for (int s = 0; s < sheetCount; s++) {  
                Sheet sheet = workbook.getSheetAt(0);  
                int rowCount = sheet.getPhysicalNumberOfRows(); //获取总行数  
                //遍历每一行  // 前3行不读
                int jl = 0; // 记录上一行多少
                for (int r = 4; r < rowCount; r++) {  
                    Row row = sheet.getRow(r);  
                    int cellCount = row.getPhysicalNumberOfCells(); //获取总列数  
                    
                    //遍历每一个单元格  
                    for (int c = 0; c < cellCount; c++) {  
                        Cell cell = row.getCell(c);  // 序号
                        CellType cellType = cell.getCellType();   // STRING 
                        String cellValue = null;
                        
                        //在读取单元格内容前,设置所有单元格中内容都是字符串类型
                        // cell.setCellType(CellType.STRING); // //设置单元格类型
                        cell.setCellType(CellType.STRING); // //设置单元格类型
                        
                        //按照字符串类型读取单元格内数据
                        cellValue = cell.getStringCellValue();
                        
                        //在这里可以对每个单元格中的值进行二次操作转化
                        
                        System.out.println(">>>"+cellValue);  
                    }  
                    //
                    CellType BHcellType = row.getCell(0).getCellType();   // STRING 
                    row.getCell(0).setCellType(BHcellType.STRING); // //设置单元格类型
                    String bh =row.getCell(0).getStringCellValue();
                     
                    CellType XMMCcellType = row.getCell(1).getCellType();   // STRING 
                    row.getCell(1).setCellType(XMMCcellType.STRING); // //设置单元格类型
                    String xmmc =row.getCell(1).getStringCellValue();
                      
                    CellType HTMCcellType = row.getCell(2).getCellType();   // STRING 
                    row.getCell(2).setCellType(HTMCcellType.STRING); // //设置单元格类型
                    String htmc =row.getCell(2).getStringCellValue();
                     
                    CellType HTDSRcellType = row.getCell(3).getCellType();   // STRING 
                    row.getCell(3).setCellType(HTDSRcellType.STRING); // //设置单元格类型
                    String htdsr =row.getCell(3).getStringCellValue();
                     
                    CellType HTNRcellType = row.getCell(4).getCellType();   // STRING 
                    row.getCell(4).setCellType(HTNRcellType.STRING); // //设置单元格类型
                    String htnr =row.getCell(4).getStringCellValue();
                      
                    CellType WTFScellType = row.getCell(5).getCellType();   // STRING 
                    row.getCell(5).setCellType(WTFScellType.STRING); // //设置单元格类型
                    String wtfs =row.getCell(5).getStringCellValue();
                      
                    CellType HTJKcellType = row.getCell(6).getCellType();   // STRING 
                    row.getCell(6).setCellType(HTJKcellType.STRING); // //设置单元格类型
                    String htjk =row.getCell(6).getStringCellValue();
                      
                    CellType HTGQcellType = row.getCell(7).getCellType();   // STRING 
                    row.getCell(7).setCellType(HTGQcellType.STRING); // //设置单元格类型
                    String htgq =row.getCell(7).getStringCellValue();
                      
                    CellType QDSJcellType = row.getCell(8).getCellType();   // STRING 
                    row.getCell(8).setCellType(QDSJcellType.STRING); // //设置单元格类型
                    String qdsj =row.getCell(8).getStringCellValue();
                      
                    CellType XMZBBMcellType = row.getCell(9).getCellType();   // STRING 
                    row.getCell(9).setCellType(XMZBBMcellType.STRING); // //设置单元格类型
                    String xmzbbm =row.getCell(9).getStringCellValue();
                      
                    CellType XBRcellType = row.getCell(10).getCellType();   // STRING 
                    row.getCell(10).setCellType(XBRcellType.STRING); // //设置单元格类型
                    String xbr =row.getCell(10).getStringCellValue();
                      
                    CellType YJGDSJcellType = row.getCell(11).getCellType();   // STRING 
                    row.getCell(11).setCellType(YJGDSJcellType.STRING); // //设置单元格类型
                    String yjgdsj =row.getCell(11).getStringCellValue();
                      
                    CellType HTJXQKcellType = row.getCell(12).getCellType();   // STRING 
                    row.getCell(12).setCellType(HTJXQKcellType.STRING); // //设置单元格类型
                    String htjxqk =row.getCell(12).getStringCellValue();
                      
                    CellType YSRQcellType = row.getCell(13).getCellType();   // STRING 
                    row.getCell(13).setCellType(YSRQcellType.STRING); // //设置单元格类型
                    String ysrq =row.getCell(13).getStringCellValue();
                     /*
                    CellType NFcellType = row.getCell(14).getCellType();   // STRING 
                    row.getCell(14).setCellType(NFcellType.STRING); // //设置单元格类型
                    String nf =row.getCell(14).getStringCellValue();  */
                     
                    row.getCell(14).setCellType(row.getCell(14).getCellType().STRING); // //设置单元格类型
                    String nf =row.getCell(14).getStringCellValue();  
                    
                    Map<String,Object> dataMap = new HashMap<String,Object>();
                    
                    if(bh.equals("") && xmmc.equals("") && htmc.equals("")&& !htdsr.equals("")){ // 编号&项目&名称为空,    人不为空的情况
                        if(qbsj.get(jl-1).get("htdsr_y").equals("")){
                            qbsj.get(jl-1).put("htdsr_y",qbsj.get(jl-1).get("htdsr_y") + row.getCell(3).getStringCellValue());
                        }else{
                            qbsj.get(jl-1).put("htdsr_y",qbsj.get(jl-1).get("htdsr_y") +","+ row.getCell(3).getStringCellValue()); // 两个甲方,两个乙方 ,丙方,丁方,的情况
                        }
                    }else if(!bh.equals("") && xmmc.equals("") && htmc.equals("")){ // 合同编号不为空,项目名称    与合同名称为空的情况
                        // 
                         
                        dataMap.put("bh", bh); // gs
                        dataMap.put("xmmc", qbsj.get(jl-1).get("xmmc"));
                        dataMap.put("htmc", qbsj.get(jl-1).get("htmc"));
                        if(!htdsr.equals("")){
                            if(htdsr.substring(0,1).equals("乙")){// 编号不为空,项目与名称为空的情况       其甲方没有的情况 也是甲方在上层的情况
                                dataMap.put("htdsr_j", qbsj.get(jl-1).get("htdsr_j"));
                                dataMap.put("htdsr_y", htdsr);
                                
                            }else{
                                dataMap.put("htdsr_j", htdsr);
                                dataMap.put("htdsr_y", "");
                            }
                        }
                        // 是否为空的情况
                        if(htnr.equals("")){
                            dataMap.put("htnr", qbsj.get(jl-1).get("htnr"));
                        }else{
                            dataMap.put("htnr", htnr);
                        }
                        if(wtfs.equals("")){
                            dataMap.put("wtfs", qbsj.get(jl-1).get("wtfs"));
                        }else{
                            dataMap.put("wtfs", wtfs);
                        }
                        if(htjk.equals("")){
                            dataMap.put("htjk", qbsj.get(jl-1).get("htjk"));
                        }else{
                            dataMap.put("htjk", htjk);
                        }
                        if(htgq.equals("")){
                            dataMap.put("htgq", qbsj.get(jl-1).get("htgq"));
                        }else{
                            dataMap.put("htgq", htgq);
                        }
                        if(qdsj.equals("")){
                            dataMap.put("qdsj", qbsj.get(jl-1).get("qdsj"));
                        }else{
                            dataMap.put("qdsj", qdsj);
                        }
                        if(xmzbbm.equals("")){
                            dataMap.put("xmzbbm", qbsj.get(jl-1).get("xmzbbm"));//
                        }else{
                            dataMap.put("xmzbbm", xmzbbm);//
                        }
                        if(xbr.equals("")){
                            dataMap.put("xbr", qbsj.get(jl-1).get("xbr"));
                        }else{
                            dataMap.put("xbr", xbr);
                        }
                        if(yjgdsj.equals("")){
                            dataMap.put("yjgdsj", qbsj.get(jl-1).get("yjgdsj"));
                        }else{
                            dataMap.put("yjgdsj", yjgdsj);
                        }
                        if(htjxqk.equals("")){
                            dataMap.put("htjxqk", qbsj.get(jl-1).get("htjxqk"));
                        }else{
                            dataMap.put("htjxqk", htjxqk);
                        }
                        if(ysrq.equals("")){
                            dataMap.put("ysrq", qbsj.get(jl-1).get("ysrq"));
                        }else{
                            dataMap.put("ysrq", ysrq);
                        }
                        dataMap.put("nf", nf);  
                        qbsj.add(dataMap);
                        jl++;
                     // }else if(){ // 
                        
                    }else if(!bh.equals("") && xmmc.equals("") && !htmc.equals("")){ // 编号不为空,    项目为空,    名称不为空的情况
                         
                        dataMap.put("bh", bh); // gs
                        dataMap.put("xmmc", qbsj.get(jl-1).get("xmmc"));
                        dataMap.put("htmc", htmc);
                        dataMap.put("htdsr_j", htdsr);
                        dataMap.put("htdsr_y", "");
                        dataMap.put("htnr", htnr);
                        dataMap.put("wtfs", wtfs);
                        dataMap.put("htjk", htjk);
                        dataMap.put("htgq", htgq);
                        dataMap.put("qdsj", qdsj);
                        dataMap.put("xmzbbm", xmzbbm);//
                        dataMap.put("xbr", xbr);
                        dataMap.put("yjgdsj", yjgdsj);
                        dataMap.put("htjxqk", htjxqk);
                        dataMap.put("ysrq", ysrq);
                        dataMap.put("nf", nf); 
                        
                        qbsj.add(dataMap);jl++;
                        
                    }else if(bh.equals("") && !xmmc.equals("") && !htmc.equals("")){ //编号为空,项目与名称不为空的情况
                          
                        dataMap.put("bh", qbsj.get(jl-1).get("bh")); // gs
                        dataMap.put("xmmc", xmmc);
                        dataMap.put("htmc", htmc);
                        dataMap.put("htdsr_j", htdsr);
                        dataMap.put("htdsr_y", "");
                        dataMap.put("htnr", htnr);
                        dataMap.put("wtfs", wtfs);
                        dataMap.put("htjk", htjk);
                        dataMap.put("htgq", htgq);
                        dataMap.put("qdsj", qdsj);
                        dataMap.put("xmzbbm", xmzbbm);//
                        dataMap.put("xbr", xbr);
                        dataMap.put("yjgdsj", yjgdsj);
                        dataMap.put("htjxqk", htjxqk);
                        dataMap.put("ysrq", ysrq);
                        dataMap.put("nf", nf); 
                        
                        qbsj.add(dataMap);jl++;

                    }else if(!bh.equals("") && !xmmc.equals("") && !htmc.equals("")){ // 正常 
                         
                        
                        dataMap.put("bh", bh); // gs
                        dataMap.put("xmmc", xmmc);
                        dataMap.put("htmc", htmc);
                        dataMap.put("htdsr_j", htdsr);
                        dataMap.put("htdsr_y", "");
                        dataMap.put("htnr", htnr);
                        dataMap.put("wtfs", wtfs);
                        dataMap.put("htjk", htjk);
                        dataMap.put("htgq", htgq);
                        dataMap.put("qdsj", qdsj);
                        dataMap.put("xmzbbm", xmzbbm);//
                        dataMap.put("xbr", xbr);
                        dataMap.put("yjgdsj", yjgdsj);
                        dataMap.put("htjxqk", htjxqk);
                        dataMap.put("ysrq", ysrq);
                        dataMap.put("nf", nf); 
                        
                        qbsj.add(dataMap);jl++;
                        
                    }else if(bh.equals("") && xmmc.equals("") && htmc.equals("")&& htdsr.equals("")){ // 都为空的情况 // 有年份的情况
                        System.out.println(">>>>>>>>>>>>>>>>>>>>>>> 都为空的情况 <<<<<<<<<<<<<<<<<<<<<<");
                    }else{
                        System.out.println(">>>>>>>>>>>>>>>>>>>>>>> 未发现的情况 <<<<<<<<<<<<<<<<<<<<<<");
                    }
                    /*
                    // 定义每一行的变量
                    
                    //String ID = parseCell(row.getCell(0));   

                    Map<String,Object> dataMap = new HashMap<String,Object>();
                    // 顺序一致!! 
                    //dataMap.put("DLRID", I); //DLRID    登录人id
                    
                     dataMap.put("GS", ""); // gs  
                    
                    // System.out.println(dataMap); 
                    // 加入 
                    //qbsj.add(dataMap);*/
                     
                }
                System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
                System.out.println(">>>"+qbsj);
                return qbsj;
      
        }  
        catch (Exception e) {  
            e.printStackTrace();  
            return qbsj;
        }
    } 
    
    
    public static void main(String[] args)  throws Exception{ 
        
        List<Map<String, Object>> sj = E(); 
        
        System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
        //System.out.println(">>>"+fh); 
      }   
        
    }

 

1.合同编号&项目名称&合同名称为空, 合同当事人不为空的情况

 

2.合同编号不为空,项目名称 与合同名称为空的情况

POI 4.0 读取Excel

2.1合同编号不为空,项目名称与合同名称为空的情况       其甲方没有的情况 也是甲方在上层的情况

POI 4.0 读取Excel

3.合同编号不为空, 项目名称为空, 合同名称不为空的情况

POI 4.0 读取Excel

4.合同编号为空,项目名称与合同名称不为空的情况

POI 4.0 读取Excel

5.正常

POI 4.0 读取Excel

6.// 都为空的情况 // 有年份的情况

相关文章: