Testing POI Excel Format Handling Implementation in EasyExcel
This test suite evaluates Apache POI functionality within the EasyExcel library, focusing on Excel workbook and cell formatting operations. It includes tests for both SXSSF and XSSF implementations, verifying row counting and cell value formatting capabilities.
Test Coverage Overview
Implementation Analysis
Technical Details
Best Practices Demonstrated
alibaba/easyexcel
easyexcel-test/src/test/java/com/alibaba/easyexcel/test/temp/poi/PoiFormatTest.java
package com.alibaba.easyexcel.test.temp.poi;
import java.io.IOException;
import java.util.Locale;
import org.apache.poi.ss.usermodel.DataFormatter;
import org.apache.poi.xssf.streaming.SXSSFRow;
import org.apache.poi.xssf.streaming.SXSSFSheet;
import org.apache.poi.xssf.streaming.SXSSFWorkbook;
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 org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* 测试poi
*
* @author Jiaju Zhuang
**/
public class PoiFormatTest {
private static final Logger LOGGER = LoggerFactory.getLogger(PoiFormatTest.class);
@Test
public void lastRowNum() throws IOException {
String file = "D:\\test\\原文件.xlsx";
SXSSFWorkbook xssfWorkbook = new SXSSFWorkbook(new XSSFWorkbook(file));
SXSSFSheet xssfSheet = xssfWorkbook.getSheetAt(0);
LOGGER.info("一共行数:{}", xssfSheet.getLastRowNum());
SXSSFRow row = xssfSheet.getRow(0);
LOGGER.info("第一行数据:{}", row);
xssfSheet.createRow(20);
LOGGER.info("一共行数:{}", xssfSheet.getLastRowNum());
}
@Test
public void lastRowNumXSSF() throws IOException {
String file = "/Users/zhuangjiaju/Downloads/测试格式.xlsx";
XSSFWorkbook xssfWorkbook = new XSSFWorkbook(file);
LOGGER.info("一共:{}个sheet", xssfWorkbook.getNumberOfSheets());
XSSFSheet xssfSheet = xssfWorkbook.getSheetAt(0);
LOGGER.info("一共行数:{}", xssfSheet.getLastRowNum());
XSSFRow row = xssfSheet.getRow(1);
XSSFCell xssfCell = row.getCell(0);
DataFormatter d = new DataFormatter(Locale.CHINA);
LOGGER.info("fo:{}", d.formatCellValue(xssfCell));
}
}