ApachePOI快速入门

2020-12-27 08:26

阅读:664

标签:physical   xls   cal   建行   new   web   ota   新建   leo   

POI

三大实现类

HSSFWorkbook XSSFWorkbook SXSSFWorkbook

  org.apache.poi
            poi
            3.17org.apache.poi
            poi-ooxml
            3.17
  • 03 创建 HSSFWorkbook对象 xls --poi 6536行

  • 07 创建 XSSFWorkbook对象 xlsx --ooxml 耗时长!!

  • 00 创建 SXSSFWorkbook对象 升级版 快一点!

import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
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.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

/**
 * 03版本 后缀 xls HSSFWorkbook对象
 * 03版本 后缀 xlsx  XSSFWorkbook对象
 */
public class Demo {
    public static void main(String[] args) throws IOException {

        //新建工作簿
        Workbook workbook = new HSSFWorkbook();
        //新建表
        Sheet sheet = workbook.createSheet("统计表");
        //创建行
        Row row1 = sheet.createRow(0);
        //创建单元格
        Cell cell = row1.createCell(0);
        //在单元格填充内容
        cell.setCellValue("用户名");
        Cell cell1 = row1.createCell(1);
        cell1.setCellValue("性别");
        Row row2 = sheet.createRow(1);
        Cell cell2 = row2.createCell(0);
        cell2.setCellValue("哈哈");
        Cell cell3 = row2.createCell(1);
        cell3.setCellValue("15");
        //表格导出
        String path = "D:\\web\\";
        FileOutputStream fileOutputStream = new FileOutputStream(path + "03.xlsx");
        workbook.write(fileOutputStream);
        //关闭流
        fileOutputStream.close();



        FileInputStream fileInputStream = new FileInputStream("D:\\web\\" + "03.xlsx");
        Workbook wb = new HSSFWorkbook(fileInputStream);
        Sheet st = wb.getSheetAt(0);

        Row row = st.getRow(0);
        int physicalNumberOfCells = row.getPhysicalNumberOfCells();
        for (int i = 0; i 

1、获取sheet的总行数
int totalRows = sheet.getPhysicalNumberOfRows();
2、获取该行的总列数
int RowCells=sheet.getRow(0).getPhysicalNumberOfCells();

ApachePOI快速入门

标签:physical   xls   cal   建行   new   web   ota   新建   leo   

原文地址:https://www.cnblogs.com/botaoJava/p/13870793.html


评论


亲,登录后才可以留言!