[Java]通过Poi包读取Excel表格

简介: public List readCardExcel() throws IOException { XSSFWorkbook hssfWorkbook = new XSSFWorkbook(new FileInputStream("D:\\buyal\\名片总和.
public List<EntBusinessCard> readCardExcel() throws IOException {
        XSSFWorkbook hssfWorkbook = new XSSFWorkbook(new FileInputStream("D:\\buyal\\名片总和.xlsx"));

        EntBusinessCard card = null;
        List<EntBusinessCard> list = new ArrayList<EntBusinessCard>();

        for (int numSheet = 0; numSheet < hssfWorkbook.getNumberOfSheets(); numSheet++){
            XSSFSheet hssfSheet = hssfWorkbook.getSheetAt(numSheet);

            if(hssfSheet == null){
                continue;
            }

            for(int rowNum = 1; rowNum <= hssfSheet.getLastRowNum(); rowNum++){
                XSSFRow hssfRow = hssfSheet.getRow(rowNum);

                if(hssfRow != null){
                    card = new EntBusinessCard();
                    card.setProperty(hssfRow.getCell(0) == null ?"":getValue(hssfRow.getCell(0)));
                    card.setRole(hssfRow.getCell(1) == null ?"":getValue(hssfRow.getCell(1)));
                    card.setName(hssfRow.getCell(2) == null ?"":getValue(hssfRow.getCell(2)));
                    card.setDirect(hssfRow.getCell(3) == null ?"":getValue(hssfRow.getCell(3)));
                    card.setPostcode(hssfRow.getCell(4) == null ?"":getValue(hssfRow.getCell(4)));
                    card.setRealaddress(hssfRow.getCell(5) == null ?"":getValue(hssfRow.getCell(5)));
                    card.setEnttype(hssfRow.getCell(6) == null ?"":getValue(hssfRow.getCell(6)));
                    card.setLine(hssfRow.getCell(7) == null ?"":getValue(hssfRow.getCell(7)));
                    card.setMainproduct(hssfRow.getCell(8) == null ?"":getValue(hssfRow.getCell(8)));
                    card.setMainproductpic(hssfRow.getCell(9) == null ?"":getValue(hssfRow.getCell(9)));
                    card.setScale(hssfRow.getCell(10) == null ?"":getValue(hssfRow.getCell(10)));
                    card.setUrl(hssfRow.getCell(11) == null ?"":getValue(hssfRow.getCell(11)));
                    card.setFax(hssfRow.getCell(12) == null ?"":getValue(hssfRow.getCell(12)));
                    card.setWorkshopstatus(hssfRow.getCell(13) == null ?"":getValue(hssfRow.getCell(13)));
                    card.setCapacity(hssfRow.getCell(14) == null ?"":getValue(hssfRow.getCell(14)));
                    card.setContract(hssfRow.getCell(15) == null ?"":getValue(hssfRow.getCell(15)));
                    card.setTele(hssfRow.getCell(17) == null ?"":getValue(hssfRow.getCell(17)));
                    card.setEmail(hssfRow.getCell(18) == null ?"":getValue(hssfRow.getCell(18)));
                    card.setIntroduce(hssfRow.getCell(19) == null ?"":getValue(hssfRow.getCell(19)));

                    list.add(card);
                }
            }

        }
        return list;
    }

getValue()

    public String getValue(XSSFCell hssfCell){
        if (hssfCell.getCellType() == hssfCell.CELL_TYPE_BOOLEAN) {
            // 返回布尔类型的值
            return String.valueOf(hssfCell.getBooleanCellValue());
        } else if (hssfCell.getCellType() == hssfCell.CELL_TYPE_NUMERIC) {
            // 返回数值类型的值
            return String.valueOf(hssfCell.getNumericCellValue());
        } else {
            // 返回字符串类型的值
            return String.valueOf(hssfCell.getStringCellValue());
        }
    }

EntBusinessCard 类

public class EntBusinessCard {
    private String property;
    private String role;
    private String name;
    private String direct;
    private String postcode;
    private String realaddress;
    private String enttype;
    private String line;
    private String mainproduct;
    private String mainproductpic;
    private String scale;
    private String url;
    private String fax;
    private String workshopstatus;
    private String capacity;
    private String contract;
    private String tele;
    private String email;
    private String introduce;

getter()。。。
setter()。。。
}
目录
相关文章
|
3月前
|
Java API Apache
Java编程如何读取Word文档里的Excel表格,并在保存文本内容时保留表格的样式?
【10月更文挑战第29天】Java编程如何读取Word文档里的Excel表格,并在保存文本内容时保留表格的样式?
205 5
|
5天前
|
文字识别 BI
【图片型PDF】批量识别扫描件PDF指定区域局部位置内容,将识别内容导出Excel表格或批量改名文件,基于阿里云OCR对图片型PDF识别改名案例实现
在医疗和政务等领域,图片型PDF文件(如病历、报告、公文扫描件)的处理需求广泛。通过OCR技术识别这些文件中的文字信息,提取关键内容并保存为表格,极大提高了信息管理和利用效率。本文介绍一款工具——咕嘎批量OCR系统,帮助用户快速处理图片型PDF文件,支持区域识别、内容提取、导出表格及批量改名等功能。下载工具后,按步骤选择处理模式、进行区域采样、批量处理文件,几分钟内即可高效完成数百个文件的处理。
39 8
|
2月前
|
人工智能 自然语言处理 Java
FastExcel:开源的 JAVA 解析 Excel 工具,集成 AI 通过自然语言处理 Excel 文件,完全兼容 EasyExcel
FastExcel 是一款基于 Java 的高性能 Excel 处理工具,专注于优化大规模数据处理,提供简洁易用的 API 和流式操作能力,支持从 EasyExcel 无缝迁移。
223 9
FastExcel:开源的 JAVA 解析 Excel 工具,集成 AI 通过自然语言处理 Excel 文件,完全兼容 EasyExcel
|
3月前
|
Java BI API
Java Excel报表生成:JXLS库的高效应用
在Java应用开发中,经常需要将数据导出到Excel文件中,以便于数据的分析和共享。JXLS库是一个强大的工具,它基于Apache POI,提供了一种简单而高效的方式来生成Excel报表。本文将详细介绍JXLS库的使用方法和技巧,帮助你快速掌握Java中的Excel导出功能。
109 6
|
3月前
|
SQL 数据可视化 数据挖掘
想让Excel表格设计更美观?试试这几款好用工具!
Excel表格设计在项目管理和数据分析中至关重要。本文推荐四款辅助工具:板栗看板、Excel自动图表助手、Think-Cell Chart 和 Power BI,分别在任务管理、图表生成、数据可视化等方面表现突出,帮助你设计出更专业、美观的表格。
142 2
|
3月前
|
Java API Apache
|
3月前
|
存储 Java API
Java实现导出多个excel表打包到zip文件中,供客户端另存为窗口下载
Java实现导出多个excel表打包到zip文件中,供客户端另存为窗口下载
170 4
|
4月前
|
JavaScript 前端开发 数据处理
Vue导出el-table表格为Excel文件的两种方式
Vue导出el-table表格为Excel文件的两种方式
223 6
|
9月前
|
Java
java面向对象——包+继承+多态(一)-2
java面向对象——包+继承+多态(一)
67 3
|
9月前
|
SQL Java 编译器
java面向对象——包+继承+多态(一)-1
java面向对象——包+继承+多态(一)
45 2

热门文章

最新文章