Apache POI操作excel

news/2024/7/21 6:46:41 标签: apache, excel

使用Apache POI

引入坐标

<dependency>
    <groupId>org.apache.poi</groupId>
    <artifactId>poi</artifactId>
    <version>3.16</version>
</dependency>
<dependency>
    <groupId>org.apache.poi</groupId>
    <artifactId>poi-ooxml</artifactId>
    <version>3.16</version>
</dependency>

样例工程

package com.sky.test;

import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;

public class POITest {
    /**
     * 基于POI读取Excel文件
     * @throws Exception
     */
    public static void read() throws Exception{
        FileInputStream in = new FileInputStream(new File("D:\\itcast.xlsx"));
        //通过输入流读取指定的Excel文件
        XSSFWorkbook excel = new XSSFWorkbook(in);
        //获取Excel文件的第1个Sheet页
        XSSFSheet sheet = excel.getSheetAt(0);

        //获取Sheet页中的最后一行的行号
        int lastRowNum = sheet.getLastRowNum();

        for (int i = 0; i <= lastRowNum; i++) {
            //获取Sheet页中的行
            XSSFRow titleRow = sheet.getRow(i);
            //获取行的第2个单元格
            XSSFCell cell1 = titleRow.getCell(1);
            //获取单元格中的文本内容
            String cellValue1 = cell1.getStringCellValue();
            //获取行的第3个单元格
            XSSFCell cell2 = titleRow.getCell(2);
            //获取单元格中的文本内容
            String cellValue2 = cell2.getStringCellValue();

            System.out.println(cellValue1 + " " +cellValue2);
        }

        //关闭资源
        in.close();
        excel.close();
    }

    public static void main(String[] args) throws Exception {
        read();
    }
}


http://www.niftyadmin.cn/n/5236481.html

相关文章

Apache Doris 详细教程(三)

7、监控和报警 Doris 可以使用 Prometheus 和 Grafana 进行监控和采集&#xff0c;官网下载最新版即可。 Prometheus 官网下载&#xff1a;https://prometheus.io/download/ Grafana 官网下载&#xff1a;https://grafana.com/grafana/download Doris 的监控数据通过 FE 和…

auth_user表扩建

【1】auth_user表扩建 方法一 一对一字段关联: 在model再建模型表&#xff0c;我们创建的表的数据和auth_user表的数据一一对应。 from django.contrib.auth.models import Userclass OtherUser(models.Model):users models.OneToOneField(toUser) 方法二 步骤一&#xff1a; …

【蓝桥杯选拔赛真题73】Scratch烟花特效 少儿编程scratch图形化编程 蓝桥杯创意编程选拔赛真题解析

目录 scratch烟花特效 一、题目要求 编程实现 二、案例分析 1、角色分析

MySQL学习day04(一)

DQL学习&#xff08;Data Query Language数据查询语言&#xff09; DQL-语法&#xff1a; select 字段列表 from 表名列表 where 条件列表 group by 分组字段列表 having 分组后条件别表 order by 排序字段列表 limit 分页参数 基本查询条件查询&#xff08;where&#xff09;…

数学杂谈:残次品的无砝码天平定位问题

数学杂谈&#xff1a;残次品的无砝码天平定位问题 1. 问题描述2. 问题解答3. 问题拓展 1. 引理12. 引理23. 引理34. 推论15. 推论2 1. 问题描述 给出问题如下&#xff1a; 12个乒乓球&#xff0c;有一个次品&#xff0c;不知轻重&#xff0c;用一台无砝码天平称三次&#xf…

React使用TailwindCSS

React中使用TailwindCSS TailwindCSS是 下载及初始化 可以查看官网对照自己使用的框架进行配置 npm install -D tailwindcss postcss autoprefixer下载完毕后执行如下命令 npx tailwindcss init -p可以发现项目中多了两个文件 其中默认已经进行了配置&#xff0c;我们需要将…

泊车功能专题介绍 ———— 记忆泊车评价规程(征求意见稿)

文章目录 评价方法指标体系指标权重分配算分方法指标得分计算方法露天停车场一键召唤得分情况说明泊出能力得分情况说明水平划线车位——两侧存在静止车辆水平划线车位——两侧存在静止车辆且车位附近有静止直立儿童垂直划线车位——两侧存在静止车辆垂直划线车位——两侧存在静…

HuggingFace学习笔记--Prompt-Tuning、P-Tuning和Prefix-Tuning高效微调

1--Prompt-Tuning 1-1--Prompt-Tuning介绍 Prompt-Tuning 高效微调只会训练新增的Prompt的表示层&#xff0c;模型的其余参数全部固定&#xff1b; 新增的 Prompt 内容可以分为 Hard Prompt 和 Soft Prompt 两类&#xff1b; Soft prompt 通常指的是一种较为宽泛或模糊的提示&…