add compact to poi5.2

This commit is contained in:
Looly 2022-02-16 12:29:57 +08:00
parent 9dcf13ab97
commit 531055e6bd
14 changed files with 40 additions and 31 deletions

View File

@ -2,9 +2,10 @@
# 🚀Changelog
-------------------------------------------------------------------------------------------------------------
# 5.7.22 (2022-02-14)
# 5.7.22 (2022-02-16)
### 🐣新特性
* 【poi 】 ExcelUtil.readBySax增加对POI-5.2.0的兼容性issue#I4TJF4@gitee
### 🐞Bug修复
-------------------------------------------------------------------------------------------------------------
@ -38,6 +39,7 @@
* 【dfa 】 修复密集匹配和贪婪匹配冲突问题issue#2126@Github
* 【db 】 修复c3p0丢失信息问题issue#I4T7XZ@Gitee
* 【http 】 修复Action中HttpExchange没有关闭问题
* 【http 】 修复Action中HttpExchange没有关闭问题
-------------------------------------------------------------------------------------------------------------
# 5.7.20 (2022-01-20)

View File

@ -899,10 +899,12 @@ public class FileUtil extends PathUtil {
* 调用 Java 虚拟机时可以为该系统属性赋予不同的值但不保证对该属性的编程更改对该方法使用的临时目录有任何影响
* @return 临时文件
* @throws IORuntimeException IO异常
* @since 5.7.22
*/
public static File createTempFile() throws IORuntimeException {
return createTempFile("hutool", null, null, true);
}
/**
* 在默认临时文件目录下创建临时文件创建后的文件名为 prefix[Randon].suffix
* 默认临时文件目录由系统属性 <code>java.io.tmpdir<code> 指定
@ -913,10 +915,12 @@ public class FileUtil extends PathUtil {
* @param isReCreat 是否重新创建文件删掉原来的创建新的
* @return 临时文件
* @throws IORuntimeException IO异常
* @since 5.7.22
*/
public static File createTempFile(String suffix, boolean isReCreat) throws IORuntimeException {
return createTempFile("hutool", suffix, null, isReCreat);
}
/**
* 在默认临时文件目录下创建临时文件创建后的文件名为 prefix[Randon].suffix
* 默认临时文件目录由系统属性 <code>java.io.tmpdir<code> 指定
@ -929,10 +933,12 @@ public class FileUtil extends PathUtil {
* @param isReCreat 是否重新创建文件删掉原来的创建新的
* @return 临时文件
* @throws IORuntimeException IO异常
* @since 5.7.22
*/
public static File createTempFile(String prefix, String suffix, boolean isReCreat) throws IORuntimeException {
return createTempFile(prefix, suffix, null, isReCreat);
}
/**
* 创建临时文件<br>
* 创建后的文件名为 prefix[Randon].tmp

View File

@ -460,7 +460,7 @@ public class FileUtilTest {
Assert.assertTrue(nullDirTempFile.exists());
File suffixDirTempFile = FileUtil.createTempFile(".xlsx",true);
Assert.assertTrue(FileUtil.getSuffix(suffixDirTempFile).equals("xlsx"));
Assert.assertEquals("xlsx", FileUtil.getSuffix(suffixDirTempFile));
File prefixDirTempFile = FileUtil.createTempFile("prefix",".xlsx",true);
Assert.assertTrue(FileUtil.getPrefix(prefixDirTempFile).startsWith("prefix"));

View File

@ -62,16 +62,16 @@ public class ExcelFileUtil {
* 如果强转成PushbackInputStream在调用FileMagic.valueOf(inputStream)时会报错
* {@link FileMagic}
* 报错内容getFileMagic() only operates on streams which support mark(int)
* 此处修改成 final InputStream inputStream = FileMagic.prepareToCheckMagic(in)
* 此处修改成 final InputStream in = FileMagic.prepareToCheckMagic(in)
*
* @param in {@link InputStream}
* @author kefan.qu
*/
private static FileMagic getFileMagic(InputStream in) {
FileMagic magic;
final InputStream inputStream = FileMagic.prepareToCheckMagic(in);
in = FileMagic.prepareToCheckMagic(in);
try {
magic = FileMagic.valueOf(inputStream);
magic = FileMagic.valueOf(in);
} catch (IOException e) {
throw new IORuntimeException(e);
}

View File

@ -283,7 +283,7 @@ public class ExcelReader extends ExcelBase<ExcelReader> {
/**
* 读取工作簿中指定的Sheet此方法为类流处理方式当读到指定单元格时会调用CellEditor接口<br>
* 用户通过实现此接口可以更加灵活处理每个单元格的数据
* 用户通过实现此接口可以更加灵活处理每个单元格的数据
*
* @param cellHandler 单元格处理器用于处理读到的单元格及其数据
* @since 5.3.8
@ -294,7 +294,7 @@ public class ExcelReader extends ExcelBase<ExcelReader> {
/**
* 读取工作簿中指定的Sheet此方法为类流处理方式当读到指定单元格时会调用CellEditor接口<br>
* 用户通过实现此接口可以更加灵活处理每个单元格的数据
* 用户通过实现此接口可以更加灵活处理每个单元格的数据
*
* @param startRowIndex 起始行包含从0开始计数
* @param endRowIndex 结束行包含从0开始计数

View File

@ -33,23 +33,23 @@ public class StyleSet implements Serializable {
/**
* 标题样式
*/
protected CellStyle headCellStyle;
protected final CellStyle headCellStyle;
/**
* 默认样式
*/
protected CellStyle cellStyle;
protected final CellStyle cellStyle;
/**
* 默认数字样式
*/
protected CellStyle cellStyleForNumber;
protected final CellStyle cellStyleForNumber;
/**
* 默认日期样式
*/
protected CellStyle cellStyleForDate;
protected final CellStyle cellStyleForDate;
/**
* 默认链接样式
*/
protected CellStyle cellStyleForHyperlink;
protected final CellStyle cellStyleForHyperlink;
/**
* 构造

View File

@ -18,11 +18,11 @@ public class FormulaCellValue implements CellValue<String>, CellSetter {
/**
* 公式
*/
String formula;
private final String formula;
/**
* 结果使用ExcelWriter时可以不用
*/
Object result;
private final Object result;
/**
* 构造

View File

@ -1,6 +1,5 @@
package cn.hutool.poi.excel.cell.setters;
import cn.hutool.core.lang.Console;
import cn.hutool.poi.excel.cell.CellSetter;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Hyperlink;

View File

@ -6,15 +6,15 @@ import cn.hutool.poi.excel.cell.CellEditor;
/**
* POI中NUMRIC类型的值默认返回的是Double类型此编辑器用于转换其为int型
* @author Looly
*
* @author Looly
*/
public class NumericToIntEditor implements CellEditor{
public class NumericToIntEditor implements CellEditor {
@Override
public Object edit(Cell cell, Object value) {
if(value instanceof Number) {
return ((Number)value).intValue();
if (value instanceof Number) {
return ((Number) value).intValue();
}
return value;
}

View File

@ -128,7 +128,7 @@ public class Excel07SaxReader implements ExcelSaxReader<Excel07SaxReader> {
// 获取共享字符串表
try {
this.handler.sharedStringsTable = xssfReader.getSharedStringsTable();
this.handler.sharedStrings = xssfReader.getSharedStringsTable();
} catch (IOException e) {
throw new IORuntimeException(e);
} catch (InvalidFormatException e) {

View File

@ -13,7 +13,7 @@ import org.apache.poi.hssf.eventusermodel.FormatTrackingHSSFListener;
import org.apache.poi.hssf.record.CellValueRecordInterface;
import org.apache.poi.ooxml.util.SAXHelper;
import org.apache.poi.ss.usermodel.DataFormatter;
import org.apache.poi.xssf.model.SharedStringsTable;
import org.apache.poi.xssf.model.SharedStrings;
import org.apache.poi.xssf.usermodel.XSSFRichTextString;
import org.xml.sax.ContentHandler;
import org.xml.sax.InputSource;
@ -53,13 +53,13 @@ public class ExcelSaxUtil {
/**
* 根据数据类型获取数据
*
* @param cellDataType 数据类型枚举
* @param value 数据值
* @param sharedStringsTable {@link SharedStringsTable}
* @param numFmtString 数字格式名
* @param cellDataType 数据类型枚举
* @param value 数据值
* @param sharedStrings {@link SharedStrings}
* @param numFmtString 数字格式名
* @return 数据值
*/
public static Object getDataValue(CellDataType cellDataType, String value, SharedStringsTable sharedStringsTable, String numFmtString) {
public static Object getDataValue(CellDataType cellDataType, String value, SharedStrings sharedStrings, String numFmtString) {
if (null == value) {
return null;
}
@ -85,7 +85,7 @@ public class ExcelSaxUtil {
case SSTINDEX:
try {
final int index = Integer.parseInt(value);
result = sharedStringsTable.getItemAt(index).getString();
result = sharedStrings.getItemAt(index).getString();
} catch (NumberFormatException e) {
result = value;
}
@ -208,8 +208,8 @@ public class ExcelSaxUtil {
* @param formatIndex 格式索引一般用于内建格式
* @param formatString 格式字符串
* @return 是否为日期格式
* @since 5.5.3
* @see ExcelDateUtil#isDateFormat(int, String)
* @since 5.5.3
*/
public static boolean isDateFormat(int formatIndex, String formatString) {
return ExcelDateUtil.isDateFormat(formatIndex, formatString);

View File

@ -6,7 +6,7 @@ import cn.hutool.core.util.StrUtil;
import cn.hutool.poi.excel.cell.FormulaCellValue;
import cn.hutool.poi.excel.sax.handler.RowHandler;
import org.apache.poi.ss.usermodel.BuiltinFormats;
import org.apache.poi.xssf.model.SharedStringsTable;
import org.apache.poi.xssf.model.SharedStrings;
import org.apache.poi.xssf.model.StylesTable;
import org.apache.poi.xssf.usermodel.XSSFCellStyle;
import org.xml.sax.Attributes;
@ -28,7 +28,7 @@ public class SheetDataSaxHandler extends DefaultHandler {
// 单元格的格式表对应style.xml
protected StylesTable stylesTable;
// excel 2007 的共享字符串表,对应sharedString.xml
protected SharedStringsTable sharedStringsTable;
protected SharedStrings sharedStrings;
// sheet的索引从0开始
protected int sheetIndex;
@ -238,7 +238,7 @@ public class SheetDataSaxHandler extends DefaultHandler {
fillBlankCell(preCoordinate, curCoordinate, false);
final String contentStr = StrUtil.trim(lastContent);
Object value = ExcelSaxUtil.getDataValue(this.cellDataType, contentStr, this.sharedStringsTable, this.numFmtString);
Object value = ExcelSaxUtil.getDataValue(this.cellDataType, contentStr, this.sharedStrings, this.numFmtString);
if (false == this.lastFormula.isEmpty()) {
value = new FormulaCellValue(StrUtil.trim(lastFormula), value);
}

View File

@ -118,6 +118,7 @@ public class OfdWriter implements Serializable, Closeable {
* @param div 节点可以是段落CanvasImg或者填充
* @return this
*/
@SuppressWarnings("rawtypes")
public OfdWriter add(Div div) {
this.doc.add(div);
return this;

View File

@ -22,6 +22,7 @@ public enum PicType {
/**
* 构造
*
* @param value 图片类型值
*/
PicType(int value) {