mirror of
https://gitee.com/dromara/hutool.git
synced 2025-11-18 16:59:09 +08:00
fix code
This commit is contained in:
@@ -5,7 +5,7 @@ import cn.hutool.core.io.IORuntimeException;
|
||||
import cn.hutool.core.io.IoUtil;
|
||||
import cn.hutool.core.lang.Assert;
|
||||
import cn.hutool.core.util.CharsetUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.ObjUtil;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.Reader;
|
||||
@@ -30,7 +30,7 @@ public class CsvBaseReader implements Serializable {
|
||||
/**
|
||||
* 默认编码
|
||||
*/
|
||||
protected static final Charset DEFAULT_CHARSET = CharsetUtil.CHARSET_UTF_8;
|
||||
protected static final Charset DEFAULT_CHARSET = CharsetUtil.UTF_8;
|
||||
|
||||
private final CsvReadConfig config;
|
||||
|
||||
@@ -49,7 +49,7 @@ public class CsvBaseReader implements Serializable {
|
||||
* @param config 配置项
|
||||
*/
|
||||
public CsvBaseReader(CsvReadConfig config) {
|
||||
this.config = ObjectUtil.defaultIfNull(config, CsvReadConfig::defaultConfig);
|
||||
this.config = ObjUtil.defaultIfNull(config, CsvReadConfig::defaultConfig);
|
||||
}
|
||||
//--------------------------------------------------------------------------------------------- Constructor end
|
||||
|
||||
|
||||
@@ -6,8 +6,8 @@ import cn.hutool.core.io.IoUtil;
|
||||
import cn.hutool.core.map.MapUtil;
|
||||
import cn.hutool.core.text.StrBuilder;
|
||||
import cn.hutool.core.util.CharUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.core.util.ObjUtil;
|
||||
import cn.hutool.core.text.StrUtil;
|
||||
|
||||
import java.io.Closeable;
|
||||
import java.io.IOException;
|
||||
@@ -80,7 +80,7 @@ public final class CsvParser extends ComputeIter<CsvRow> implements Closeable, S
|
||||
*/
|
||||
public CsvParser(final Reader reader, CsvReadConfig config) {
|
||||
this.reader = Objects.requireNonNull(reader, "reader must not be null");
|
||||
this.config = ObjectUtil.defaultIfNull(config, CsvReadConfig::defaultConfig);
|
||||
this.config = ObjUtil.defaultIfNull(config, CsvReadConfig::defaultConfig);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -175,7 +175,7 @@ public final class CsvParser extends ComputeIter<CsvRow> implements Closeable, S
|
||||
String field = currentFields.get(i);
|
||||
if (MapUtil.isNotEmpty(this.config.headerAlias)) {
|
||||
// 自定义别名
|
||||
field = ObjectUtil.defaultIfNull(this.config.headerAlias.get(field), field);
|
||||
field = ObjUtil.defaultIfNull(this.config.headerAlias.get(field), field);
|
||||
}
|
||||
if (StrUtil.isNotEmpty(field) && false == localHeaderMap.containsKey(field)) {
|
||||
localHeaderMap.put(field, i);
|
||||
|
||||
@@ -12,7 +12,7 @@ import cn.hutool.core.map.MapUtil;
|
||||
import cn.hutool.core.util.ArrayUtil;
|
||||
import cn.hutool.core.util.CharUtil;
|
||||
import cn.hutool.core.util.CharsetUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.ObjUtil;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.Closeable;
|
||||
@@ -68,7 +68,7 @@ public final class CsvWriter implements Closeable, Flushable, Serializable {
|
||||
* @param file File CSV文件
|
||||
*/
|
||||
public CsvWriter(File file) {
|
||||
this(file, CharsetUtil.CHARSET_UTF_8);
|
||||
this(file, CharsetUtil.UTF_8);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -154,7 +154,7 @@ public final class CsvWriter implements Closeable, Flushable, Serializable {
|
||||
*/
|
||||
public CsvWriter(Writer writer, CsvWriteConfig config) {
|
||||
this.writer = (writer instanceof BufferedWriter) ? writer : new BufferedWriter(writer);
|
||||
this.config = ObjectUtil.defaultIfNull(config, CsvWriteConfig::defaultConfig);
|
||||
this.config = ObjUtil.defaultIfNull(config, CsvWriteConfig::defaultConfig);
|
||||
}
|
||||
// --------------------------------------------------------------------------------------------------- Constructor end
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package cn.hutool.poi.excel;
|
||||
|
||||
import cn.hutool.core.util.ArrayUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.core.text.StrUtil;
|
||||
import org.apache.poi.ss.formula.ConditionalFormattingEvaluator;
|
||||
import org.apache.poi.ss.usermodel.Cell;
|
||||
import org.apache.poi.ss.usermodel.ExcelNumberFormat;
|
||||
|
||||
@@ -2,7 +2,7 @@ package cn.hutool.poi.excel;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.lang.Assert;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.core.text.StrUtil;
|
||||
import org.apache.poi.hssf.usermodel.HSSFClientAnchor;
|
||||
import org.apache.poi.hssf.usermodel.HSSFPicture;
|
||||
import org.apache.poi.hssf.usermodel.HSSFPictureData;
|
||||
|
||||
@@ -3,9 +3,9 @@ package cn.hutool.poi.excel;
|
||||
import cn.hutool.core.exceptions.DependencyException;
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.io.IoUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.ObjUtil;
|
||||
import cn.hutool.core.regex.ReUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.core.text.StrUtil;
|
||||
import cn.hutool.poi.PoiChecker;
|
||||
import cn.hutool.poi.excel.cell.CellLocation;
|
||||
import cn.hutool.poi.excel.sax.ExcelSaxReader;
|
||||
@@ -150,7 +150,7 @@ public class ExcelUtil {
|
||||
try {
|
||||
return new ExcelReader(bookFilePath, sheetIndex);
|
||||
} catch (NoClassDefFoundError e) {
|
||||
throw new DependencyException(ObjectUtil.defaultIfNull(e.getCause(), e), PoiChecker.NO_POI_ERROR_MSG);
|
||||
throw new DependencyException(ObjUtil.defaultIfNull(e.getCause(), e), PoiChecker.NO_POI_ERROR_MSG);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -166,7 +166,7 @@ public class ExcelUtil {
|
||||
try {
|
||||
return new ExcelReader(bookFilePath, sheetName);
|
||||
} catch (NoClassDefFoundError e) {
|
||||
throw new DependencyException(ObjectUtil.defaultIfNull(e.getCause(), e), PoiChecker.NO_POI_ERROR_MSG);
|
||||
throw new DependencyException(ObjUtil.defaultIfNull(e.getCause(), e), PoiChecker.NO_POI_ERROR_MSG);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -181,7 +181,7 @@ public class ExcelUtil {
|
||||
try {
|
||||
return new ExcelReader(bookFile, sheetIndex);
|
||||
} catch (NoClassDefFoundError e) {
|
||||
throw new DependencyException(ObjectUtil.defaultIfNull(e.getCause(), e), PoiChecker.NO_POI_ERROR_MSG);
|
||||
throw new DependencyException(ObjUtil.defaultIfNull(e.getCause(), e), PoiChecker.NO_POI_ERROR_MSG);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -196,7 +196,7 @@ public class ExcelUtil {
|
||||
try {
|
||||
return new ExcelReader(bookFile, sheetName);
|
||||
} catch (NoClassDefFoundError e) {
|
||||
throw new DependencyException(ObjectUtil.defaultIfNull(e.getCause(), e), PoiChecker.NO_POI_ERROR_MSG);
|
||||
throw new DependencyException(ObjUtil.defaultIfNull(e.getCause(), e), PoiChecker.NO_POI_ERROR_MSG);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -223,7 +223,7 @@ public class ExcelUtil {
|
||||
try {
|
||||
return new ExcelReader(bookStream, sheetIndex);
|
||||
} catch (NoClassDefFoundError e) {
|
||||
throw new DependencyException(ObjectUtil.defaultIfNull(e.getCause(), e), PoiChecker.NO_POI_ERROR_MSG);
|
||||
throw new DependencyException(ObjUtil.defaultIfNull(e.getCause(), e), PoiChecker.NO_POI_ERROR_MSG);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -239,7 +239,7 @@ public class ExcelUtil {
|
||||
try {
|
||||
return new ExcelReader(bookStream, sheetName);
|
||||
} catch (NoClassDefFoundError e) {
|
||||
throw new DependencyException(ObjectUtil.defaultIfNull(e.getCause(), e), PoiChecker.NO_POI_ERROR_MSG);
|
||||
throw new DependencyException(ObjUtil.defaultIfNull(e.getCause(), e), PoiChecker.NO_POI_ERROR_MSG);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -257,7 +257,7 @@ public class ExcelUtil {
|
||||
try {
|
||||
return new ExcelWriter();
|
||||
} catch (NoClassDefFoundError e) {
|
||||
throw new DependencyException(ObjectUtil.defaultIfNull(e.getCause(), e), PoiChecker.NO_POI_ERROR_MSG);
|
||||
throw new DependencyException(ObjUtil.defaultIfNull(e.getCause(), e), PoiChecker.NO_POI_ERROR_MSG);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -274,7 +274,7 @@ public class ExcelUtil {
|
||||
try {
|
||||
return new ExcelWriter(isXlsx);
|
||||
} catch (NoClassDefFoundError e) {
|
||||
throw new DependencyException(ObjectUtil.defaultIfNull(e.getCause(), e), PoiChecker.NO_POI_ERROR_MSG);
|
||||
throw new DependencyException(ObjUtil.defaultIfNull(e.getCause(), e), PoiChecker.NO_POI_ERROR_MSG);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -288,7 +288,7 @@ public class ExcelUtil {
|
||||
try {
|
||||
return new ExcelWriter(destFilePath);
|
||||
} catch (NoClassDefFoundError e) {
|
||||
throw new DependencyException(ObjectUtil.defaultIfNull(e.getCause(), e), PoiChecker.NO_POI_ERROR_MSG);
|
||||
throw new DependencyException(ObjUtil.defaultIfNull(e.getCause(), e), PoiChecker.NO_POI_ERROR_MSG);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -303,7 +303,7 @@ public class ExcelUtil {
|
||||
try {
|
||||
return new ExcelWriter((File) null, sheetName);
|
||||
} catch (NoClassDefFoundError e) {
|
||||
throw new DependencyException(ObjectUtil.defaultIfNull(e.getCause(), e), PoiChecker.NO_POI_ERROR_MSG);
|
||||
throw new DependencyException(ObjUtil.defaultIfNull(e.getCause(), e), PoiChecker.NO_POI_ERROR_MSG);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -317,7 +317,7 @@ public class ExcelUtil {
|
||||
try {
|
||||
return new ExcelWriter(destFile);
|
||||
} catch (NoClassDefFoundError e) {
|
||||
throw new DependencyException(ObjectUtil.defaultIfNull(e.getCause(), e), PoiChecker.NO_POI_ERROR_MSG);
|
||||
throw new DependencyException(ObjUtil.defaultIfNull(e.getCause(), e), PoiChecker.NO_POI_ERROR_MSG);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -332,7 +332,7 @@ public class ExcelUtil {
|
||||
try {
|
||||
return new ExcelWriter(destFilePath, sheetName);
|
||||
} catch (NoClassDefFoundError e) {
|
||||
throw new DependencyException(ObjectUtil.defaultIfNull(e.getCause(), e), PoiChecker.NO_POI_ERROR_MSG);
|
||||
throw new DependencyException(ObjUtil.defaultIfNull(e.getCause(), e), PoiChecker.NO_POI_ERROR_MSG);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -347,7 +347,7 @@ public class ExcelUtil {
|
||||
try {
|
||||
return new ExcelWriter(destFile, sheetName);
|
||||
} catch (NoClassDefFoundError e) {
|
||||
throw new DependencyException(ObjectUtil.defaultIfNull(e.getCause(), e), PoiChecker.NO_POI_ERROR_MSG);
|
||||
throw new DependencyException(ObjUtil.defaultIfNull(e.getCause(), e), PoiChecker.NO_POI_ERROR_MSG);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -365,7 +365,7 @@ public class ExcelUtil {
|
||||
try {
|
||||
return new BigExcelWriter();
|
||||
} catch (NoClassDefFoundError e) {
|
||||
throw new DependencyException(ObjectUtil.defaultIfNull(e.getCause(), e), PoiChecker.NO_POI_ERROR_MSG);
|
||||
throw new DependencyException(ObjUtil.defaultIfNull(e.getCause(), e), PoiChecker.NO_POI_ERROR_MSG);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -382,7 +382,7 @@ public class ExcelUtil {
|
||||
try {
|
||||
return new BigExcelWriter(rowAccessWindowSize);
|
||||
} catch (NoClassDefFoundError e) {
|
||||
throw new DependencyException(ObjectUtil.defaultIfNull(e.getCause(), e), PoiChecker.NO_POI_ERROR_MSG);
|
||||
throw new DependencyException(ObjUtil.defaultIfNull(e.getCause(), e), PoiChecker.NO_POI_ERROR_MSG);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -396,7 +396,7 @@ public class ExcelUtil {
|
||||
try {
|
||||
return new BigExcelWriter(destFilePath);
|
||||
} catch (NoClassDefFoundError e) {
|
||||
throw new DependencyException(ObjectUtil.defaultIfNull(e.getCause(), e), PoiChecker.NO_POI_ERROR_MSG);
|
||||
throw new DependencyException(ObjUtil.defaultIfNull(e.getCause(), e), PoiChecker.NO_POI_ERROR_MSG);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -410,7 +410,7 @@ public class ExcelUtil {
|
||||
try {
|
||||
return new BigExcelWriter(destFile);
|
||||
} catch (NoClassDefFoundError e) {
|
||||
throw new DependencyException(ObjectUtil.defaultIfNull(e.getCause(), e), PoiChecker.NO_POI_ERROR_MSG);
|
||||
throw new DependencyException(ObjUtil.defaultIfNull(e.getCause(), e), PoiChecker.NO_POI_ERROR_MSG);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -425,7 +425,7 @@ public class ExcelUtil {
|
||||
try {
|
||||
return new BigExcelWriter(destFilePath, sheetName);
|
||||
} catch (NoClassDefFoundError e) {
|
||||
throw new DependencyException(ObjectUtil.defaultIfNull(e.getCause(), e), PoiChecker.NO_POI_ERROR_MSG);
|
||||
throw new DependencyException(ObjUtil.defaultIfNull(e.getCause(), e), PoiChecker.NO_POI_ERROR_MSG);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -440,7 +440,7 @@ public class ExcelUtil {
|
||||
try {
|
||||
return new BigExcelWriter(destFile, sheetName);
|
||||
} catch (NoClassDefFoundError e) {
|
||||
throw new DependencyException(ObjectUtil.defaultIfNull(e.getCause(), e), PoiChecker.NO_POI_ERROR_MSG);
|
||||
throw new DependencyException(ObjUtil.defaultIfNull(e.getCause(), e), PoiChecker.NO_POI_ERROR_MSG);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -7,14 +7,14 @@ import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.io.IORuntimeException;
|
||||
import cn.hutool.core.io.IoUtil;
|
||||
import cn.hutool.core.lang.Assert;
|
||||
import cn.hutool.core.lang.id.IdUtil;
|
||||
import cn.hutool.core.map.MapUtil;
|
||||
import cn.hutool.core.map.TableMap;
|
||||
import cn.hutool.core.map.multi.RowKeyTable;
|
||||
import cn.hutool.core.map.multi.Table;
|
||||
import cn.hutool.core.net.URLEncoder;
|
||||
import cn.hutool.core.util.CharsetUtil;
|
||||
import cn.hutool.core.lang.id.IdUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.core.util.URLUtil;
|
||||
import cn.hutool.core.text.StrUtil;
|
||||
import cn.hutool.poi.excel.cell.CellLocation;
|
||||
import cn.hutool.poi.excel.cell.CellUtil;
|
||||
import cn.hutool.poi.excel.style.Align;
|
||||
@@ -366,7 +366,7 @@ public class ExcelWriter extends ExcelBase<ExcelWriter> {
|
||||
*/
|
||||
public String getDisposition(String fileName, Charset charset) {
|
||||
if (null == charset) {
|
||||
charset = CharsetUtil.CHARSET_UTF_8;
|
||||
charset = CharsetUtil.UTF_8;
|
||||
}
|
||||
|
||||
if (StrUtil.isBlank(fileName)) {
|
||||
@@ -374,7 +374,7 @@ public class ExcelWriter extends ExcelBase<ExcelWriter> {
|
||||
fileName = IdUtil.fastSimpleUUID();
|
||||
}
|
||||
|
||||
fileName = StrUtil.addSuffixIfNot(URLUtil.encodeAll(fileName, charset), isXlsx() ? ".xlsx" : ".xls");
|
||||
fileName = StrUtil.addSuffixIfNot(URLEncoder.encodeAll(fileName, charset), isXlsx() ? ".xlsx" : ".xls");
|
||||
return StrUtil.format("attachment; filename=\"{}\"", fileName);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package cn.hutool.poi.excel;
|
||||
|
||||
import cn.hutool.core.collection.ListUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.core.text.StrUtil;
|
||||
import cn.hutool.poi.excel.cell.CellEditor;
|
||||
import cn.hutool.poi.excel.cell.CellUtil;
|
||||
import org.apache.poi.ss.usermodel.Cell;
|
||||
|
||||
@@ -4,7 +4,7 @@ package cn.hutool.poi.excel;
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.io.IORuntimeException;
|
||||
import cn.hutool.core.io.IoUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.core.text.StrUtil;
|
||||
import cn.hutool.poi.exceptions.POIException;
|
||||
import org.apache.poi.ss.usermodel.Sheet;
|
||||
import org.apache.poi.ss.usermodel.Workbook;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package cn.hutool.poi.excel.cell;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.core.util.ObjUtil;
|
||||
import cn.hutool.core.text.StrUtil;
|
||||
import cn.hutool.poi.excel.ExcelUtil;
|
||||
import cn.hutool.poi.excel.StyleSet;
|
||||
import cn.hutool.poi.excel.cell.setters.CellSetterFactory;
|
||||
@@ -364,7 +364,7 @@ public class CellUtil {
|
||||
if (null == cell) {
|
||||
return null;
|
||||
}
|
||||
return ObjectUtil.defaultIfNull(
|
||||
return ObjUtil.defaultIfNull(
|
||||
getCellIfMergedRegion(cell.getSheet(), cell.getColumnIndex(), cell.getRowIndex()),
|
||||
cell);
|
||||
}
|
||||
@@ -380,7 +380,7 @@ public class CellUtil {
|
||||
* @since 5.1.5
|
||||
*/
|
||||
public static Cell getMergedRegionCell(Sheet sheet, int x, int y) {
|
||||
return ObjectUtil.defaultIfNull(
|
||||
return ObjUtil.defaultIfNull(
|
||||
getCellIfMergedRegion(sheet, x, y),
|
||||
() -> SheetUtil.getCell(sheet, y, x));
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package cn.hutool.poi.excel.cell.setters;
|
||||
|
||||
import cn.hutool.core.regex.ReUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.core.text.StrUtil;
|
||||
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package cn.hutool.poi.excel.cell.setters;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.core.text.StrUtil;
|
||||
import cn.hutool.poi.excel.cell.CellSetter;
|
||||
import org.apache.poi.ss.usermodel.Cell;
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package cn.hutool.poi.excel.cell.values;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.core.text.StrUtil;
|
||||
import cn.hutool.poi.excel.cell.CellValue;
|
||||
import org.apache.poi.ss.usermodel.Cell;
|
||||
import org.apache.poi.ss.usermodel.FormulaError;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package cn.hutool.poi.excel.cell.values;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.core.text.StrUtil;
|
||||
import cn.hutool.poi.excel.ExcelDateUtil;
|
||||
import cn.hutool.poi.excel.cell.CellValue;
|
||||
import java.util.Date;
|
||||
|
||||
@@ -2,7 +2,7 @@ package cn.hutool.poi.excel.editors;
|
||||
|
||||
import org.apache.poi.ss.usermodel.Cell;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.core.text.StrUtil;
|
||||
import cn.hutool.poi.excel.cell.CellEditor;
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package cn.hutool.poi.excel.reader;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.ObjUtil;
|
||||
import cn.hutool.poi.excel.ExcelUtil;
|
||||
import cn.hutool.poi.excel.RowUtil;
|
||||
import cn.hutool.poi.excel.cell.CellEditor;
|
||||
@@ -130,7 +130,7 @@ public abstract class AbstractSheetReader<T> implements SheetReader<T> {
|
||||
|
||||
final String header = headerObj.toString();
|
||||
if(null != this.headerAlias){
|
||||
return ObjectUtil.defaultIfNull(this.headerAlias.get(header), header);
|
||||
return ObjUtil.defaultIfNull(this.headerAlias.get(header), header);
|
||||
}
|
||||
return header;
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ package cn.hutool.poi.excel.reader;
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.collection.IterUtil;
|
||||
import cn.hutool.core.collection.ListUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.core.text.StrUtil;
|
||||
import org.apache.poi.ss.usermodel.Sheet;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
@@ -2,8 +2,8 @@ package cn.hutool.poi.excel.sax;
|
||||
|
||||
import cn.hutool.core.io.IoUtil;
|
||||
import cn.hutool.core.lang.Assert;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.core.util.ObjUtil;
|
||||
import cn.hutool.core.text.StrUtil;
|
||||
import cn.hutool.poi.excel.sax.handler.RowHandler;
|
||||
import cn.hutool.poi.exceptions.POIException;
|
||||
import org.apache.poi.hssf.eventusermodel.EventWorkbookBuilder.SheetRecordCollectingListener;
|
||||
@@ -325,7 +325,7 @@ public class Excel03SaxReader implements HSSFListener, ExcelSaxReader<Excel03Sax
|
||||
if (null != sstRecord) {
|
||||
value = sstRecord.getString(lsrec.getSSTIndex()).toString();
|
||||
}
|
||||
addToRowCellList(lsrec, ObjectUtil.defaultIfNull(value, StrUtil.EMPTY));
|
||||
addToRowCellList(lsrec, ObjUtil.defaultIfNull(value, StrUtil.EMPTY));
|
||||
break;
|
||||
case NumberRecord.sid: // 数字类型
|
||||
final NumberRecord numrec = (NumberRecord) record;
|
||||
|
||||
@@ -2,9 +2,9 @@ package cn.hutool.poi.excel.sax;
|
||||
|
||||
import cn.hutool.core.io.IORuntimeException;
|
||||
import cn.hutool.core.io.IoUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.ReflectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.core.util.ObjUtil;
|
||||
import cn.hutool.core.reflect.ReflectUtil;
|
||||
import cn.hutool.core.text.StrUtil;
|
||||
import cn.hutool.poi.excel.sax.handler.RowHandler;
|
||||
import cn.hutool.poi.exceptions.POIException;
|
||||
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
|
||||
@@ -219,7 +219,7 @@ public class Excel07SaxReader implements ExcelSaxReader<Excel07SaxReader> {
|
||||
final int sheetIndex = Integer.parseInt(idOrRidOrSheetName);
|
||||
rid = ridReader.getRidBySheetIdBase0(sheetIndex);
|
||||
// 如果查找不到对应index,则认为用户传入的直接是rid
|
||||
return ObjectUtil.defaultIfNull(rid, sheetIndex);
|
||||
return ObjUtil.defaultIfNull(rid, sheetIndex);
|
||||
} catch (NumberFormatException ignore) {
|
||||
// 非数字,说明非index,且没有对应名称,抛出异常
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.exceptions.DependencyException;
|
||||
import cn.hutool.core.io.IORuntimeException;
|
||||
import cn.hutool.core.util.CharUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.core.text.StrUtil;
|
||||
import cn.hutool.poi.excel.ExcelDateUtil;
|
||||
import cn.hutool.poi.excel.sax.handler.RowHandler;
|
||||
import cn.hutool.poi.exceptions.POIException;
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package cn.hutool.poi.excel.sax;
|
||||
|
||||
import cn.hutool.core.text.StrBuilder;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.core.util.ObjUtil;
|
||||
import cn.hutool.core.text.StrUtil;
|
||||
import cn.hutool.poi.excel.cell.FormulaCellValue;
|
||||
import cn.hutool.poi.excel.sax.handler.RowHandler;
|
||||
import org.apache.poi.ss.usermodel.BuiltinFormats;
|
||||
@@ -292,7 +292,7 @@ public class SheetDataSaxHandler extends DefaultHandler {
|
||||
this.xssfCellStyle = stylesTable.getStyleAt(Integer.parseInt(xfIndexStr));
|
||||
// 单元格存储格式的索引,对应style.xml中的numFmts元素的子元素索引
|
||||
final int numFmtIndex = xssfCellStyle.getDataFormat();
|
||||
this.numFmtString = ObjectUtil.defaultIfNull(
|
||||
this.numFmtString = ObjUtil.defaultIfNull(
|
||||
xssfCellStyle.getDataFormatString(),
|
||||
() -> BuiltinFormats.getBuiltinFormat(numFmtIndex));
|
||||
if (CellDataType.NUMBER == this.cellDataType && ExcelSaxUtil.isDateFormat(numFmtIndex, numFmtString)) {
|
||||
|
||||
@@ -4,7 +4,7 @@ import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.collection.ListUtil;
|
||||
import cn.hutool.core.io.IORuntimeException;
|
||||
import cn.hutool.core.io.IoUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.core.text.StrUtil;
|
||||
import cn.hutool.poi.exceptions.POIException;
|
||||
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
|
||||
import org.apache.poi.xssf.eventusermodel.XSSFReader;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package cn.hutool.poi.excel.style;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.core.text.StrUtil;
|
||||
import org.apache.poi.ss.usermodel.BorderStyle;
|
||||
import org.apache.poi.ss.usermodel.Cell;
|
||||
import org.apache.poi.ss.usermodel.CellStyle;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package cn.hutool.poi.exceptions;
|
||||
|
||||
import cn.hutool.core.exceptions.ExceptionUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.core.text.StrUtil;
|
||||
|
||||
/**
|
||||
* POI异常
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package cn.hutool.poi.csv;
|
||||
|
||||
import cn.hutool.core.io.IoUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.core.text.StrUtil;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ public class CsvReaderTest {
|
||||
@Test
|
||||
public void readTest() {
|
||||
CsvReader reader = new CsvReader();
|
||||
CsvData data = reader.read(ResourceUtil.getReader("test.csv", CharsetUtil.CHARSET_UTF_8));
|
||||
CsvData data = reader.read(ResourceUtil.getReader("test.csv", CharsetUtil.UTF_8));
|
||||
Assert.assertEquals("sss,sss", data.getRow(0).get(0));
|
||||
Assert.assertEquals(1, data.getRow(0).getOriginalLineNumber());
|
||||
Assert.assertEquals("性别", data.getRow(0).get(2));
|
||||
@@ -129,7 +129,7 @@ public class CsvReaderTest {
|
||||
@Test
|
||||
public void lineNoTest() {
|
||||
CsvReader reader = new CsvReader();
|
||||
CsvData data = reader.read(ResourceUtil.getReader("test_lines.csv", CharsetUtil.CHARSET_UTF_8));
|
||||
CsvData data = reader.read(ResourceUtil.getReader("test_lines.csv", CharsetUtil.UTF_8));
|
||||
Assert.assertEquals(1, data.getRow(0).getOriginalLineNumber());
|
||||
Assert.assertEquals("a,b,c,d", CollUtil.join(data.getRow(0), ","));
|
||||
|
||||
@@ -146,7 +146,7 @@ public class CsvReaderTest {
|
||||
public void lineLimitTest() {
|
||||
// 从原始第2行开始读取
|
||||
CsvReader reader = new CsvReader(CsvReadConfig.defaultConfig().setBeginLineNo(2));
|
||||
CsvData data = reader.read(ResourceUtil.getReader("test_lines.csv", CharsetUtil.CHARSET_UTF_8));
|
||||
CsvData data = reader.read(ResourceUtil.getReader("test_lines.csv", CharsetUtil.UTF_8));
|
||||
|
||||
Assert.assertEquals(2, data.getRow(0).getOriginalLineNumber());
|
||||
Assert.assertEquals("1,2,3,4", CollUtil.join(data.getRow(0), ","));
|
||||
@@ -164,7 +164,7 @@ public class CsvReaderTest {
|
||||
public void lineLimitWithHeaderTest() {
|
||||
// 从原始第2行开始读取
|
||||
CsvReader reader = new CsvReader(CsvReadConfig.defaultConfig().setBeginLineNo(2).setContainsHeader(true));
|
||||
CsvData data = reader.read(ResourceUtil.getReader("test_lines.csv", CharsetUtil.CHARSET_UTF_8));
|
||||
CsvData data = reader.read(ResourceUtil.getReader("test_lines.csv", CharsetUtil.UTF_8));
|
||||
|
||||
Assert.assertEquals(4, data.getRow(0).getOriginalLineNumber());
|
||||
Assert.assertEquals("q,w,e,r,我是一段\n带换行的内容",
|
||||
|
||||
@@ -92,7 +92,7 @@ public class CsvUtilTest {
|
||||
@Ignore
|
||||
public void writeTest() {
|
||||
String path = FileUtil.isWindows() ? "d:/test/testWrite.csv" : "~/test/testWrite.csv";
|
||||
CsvWriter writer = CsvUtil.getWriter(path, CharsetUtil.CHARSET_UTF_8);
|
||||
CsvWriter writer = CsvUtil.getWriter(path, CharsetUtil.UTF_8);
|
||||
writer.write(
|
||||
new String[] {"a1", "b1", "c1", "123345346456745756756785656"},
|
||||
new String[] {"a2", "b2", "c2"},
|
||||
@@ -112,7 +112,7 @@ public class CsvUtilTest {
|
||||
}
|
||||
|
||||
String path = FileUtil.isWindows() ? "d:/test/testWriteBeans.csv" : "~/test/testWriteBeans.csv";
|
||||
CsvWriter writer = CsvUtil.getWriter(path, CharsetUtil.CHARSET_UTF_8);
|
||||
CsvWriter writer = CsvUtil.getWriter(path, CharsetUtil.UTF_8);
|
||||
List<Student> students = new ArrayList<>();
|
||||
Student student1 = new Student();
|
||||
student1.setId(1);
|
||||
@@ -162,7 +162,7 @@ public class CsvUtilTest {
|
||||
resultList.add(list);
|
||||
|
||||
String path = FileUtil.isWindows() ? "d:/test/csvWrapTest.csv" : "~/test/csvWrapTest.csv";
|
||||
final CsvWriter writer = CsvUtil.getWriter(path, CharsetUtil.CHARSET_UTF_8);
|
||||
final CsvWriter writer = CsvUtil.getWriter(path, CharsetUtil.UTF_8);
|
||||
writer.write(resultList);
|
||||
}
|
||||
|
||||
@@ -201,7 +201,7 @@ public class CsvUtilTest {
|
||||
|
||||
CsvData csvData = new CsvData(header, row);
|
||||
String path = FileUtil.isWindows() ? "d:/test/csvWriteDataTest.csv" : "~/test/csvWriteDataTest.csv";
|
||||
final CsvWriter writer = CsvUtil.getWriter(path, CharsetUtil.CHARSET_UTF_8);
|
||||
final CsvWriter writer = CsvUtil.getWriter(path, CharsetUtil.UTF_8);
|
||||
writer.write(csvData);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ public class CsvWriterTest {
|
||||
|
||||
final CsvWriter writer = CsvUtil.getWriter(
|
||||
FileUtil.file("d:/test/csvAliasTest.csv"),
|
||||
CharsetUtil.CHARSET_GBK, false, csvWriteConfig);
|
||||
CharsetUtil.GBK, false, csvWriteConfig);
|
||||
|
||||
writer.writeHeaderLine("name", "gender", "address");
|
||||
writer.writeLine("张三", "男", "XX市XX区");
|
||||
@@ -33,7 +33,7 @@ public class CsvWriterTest {
|
||||
@Ignore
|
||||
public void issue2255Test(){
|
||||
String fileName = "D:/test/" + new Random().nextInt(100) + "-a.csv";
|
||||
CsvWriter writer = CsvUtil.getWriter(fileName, CharsetUtil.CHARSET_UTF_8);
|
||||
CsvWriter writer = CsvUtil.getWriter(fileName, CharsetUtil.UTF_8);
|
||||
List<String> list = new ArrayList<>();
|
||||
for (int i = 0; i < 10000; i++) {
|
||||
list.add(i+"");
|
||||
|
||||
@@ -4,7 +4,7 @@ import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.map.MapUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.ObjUtil;
|
||||
import cn.hutool.poi.excel.style.StyleUtil;
|
||||
import org.apache.poi.ss.usermodel.CellStyle;
|
||||
import org.apache.poi.ss.usermodel.FillPatternType;
|
||||
@@ -22,11 +22,11 @@ import java.util.Map;
|
||||
|
||||
/**
|
||||
* 写出Excel单元测试
|
||||
*
|
||||
*
|
||||
* @author looly
|
||||
*/
|
||||
public class BigExcelWriteTest {
|
||||
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void writeTest2() {
|
||||
@@ -48,9 +48,9 @@ public class BigExcelWriteTest {
|
||||
List<List<?>> rows = CollUtil.newArrayList(row1, row2, row3, row4, row5);
|
||||
for(int i=0; i < 400000; i++) {
|
||||
//超大列表写出测试
|
||||
rows.add(ObjectUtil.clone(row1));
|
||||
rows.add(ObjUtil.clone(row1));
|
||||
}
|
||||
|
||||
|
||||
String filePath = "e:/bigWriteTest.xlsx";
|
||||
FileUtil.del(filePath);
|
||||
// 通过工具类创建writer
|
||||
@@ -66,7 +66,7 @@ public class BigExcelWriteTest {
|
||||
// 关闭writer,释放内存
|
||||
writer.close();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void mergeTest() {
|
||||
@@ -89,10 +89,10 @@ public class BigExcelWriteTest {
|
||||
writer.merge(row1.size() - 1, "测试标题");
|
||||
// 一次性写出内容,使用默认样式
|
||||
writer.write(rows);
|
||||
|
||||
|
||||
// 合并单元格后的标题行,使用默认标题样式
|
||||
writer.merge(7, 10, 4, 10, "测试Merge", false);
|
||||
|
||||
|
||||
// 关闭writer,释放内存
|
||||
writer.close();
|
||||
}
|
||||
@@ -120,14 +120,14 @@ public class BigExcelWriteTest {
|
||||
String path = "e:/bigWriteMapTest.xlsx";
|
||||
FileUtil.del(path);
|
||||
BigExcelWriter writer = ExcelUtil.getBigWriter(path);
|
||||
|
||||
|
||||
//设置内容字体
|
||||
Font font = writer.createFont();
|
||||
font.setBold(true);
|
||||
font.setColor(Font.COLOR_RED);
|
||||
font.setItalic(true);
|
||||
font.setColor(Font.COLOR_RED);
|
||||
font.setItalic(true);
|
||||
writer.getStyleSet().setFont(font, true);
|
||||
|
||||
|
||||
// 合并单元格后的标题行,使用默认标题样式
|
||||
writer.merge(row1.size() - 1, "一班成绩单");
|
||||
// 一次性写出内容,使用默认样式
|
||||
@@ -135,7 +135,7 @@ public class BigExcelWriteTest {
|
||||
// 关闭writer,释放内存
|
||||
writer.close();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void writeMapTest2() {
|
||||
@@ -145,12 +145,12 @@ public class BigExcelWriteTest {
|
||||
row1.put("成绩", 88.32);
|
||||
row1.put("是否合格", true);
|
||||
row1.put("考试日期", DateUtil.date());
|
||||
|
||||
|
||||
// 通过工具类创建writer
|
||||
String path = "e:/bigWriteMapTest2.xlsx";
|
||||
FileUtil.del(path);
|
||||
BigExcelWriter writer = ExcelUtil.getBigWriter(path);
|
||||
|
||||
|
||||
// 一次性写出内容,使用默认样式
|
||||
writer.writeRow(row1, true);
|
||||
// 关闭writer,释放内存
|
||||
@@ -192,7 +192,7 @@ public class BigExcelWriteTest {
|
||||
// 关闭writer,释放内存
|
||||
writer.close();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void writeCellValueTest() {
|
||||
|
||||
@@ -3,7 +3,7 @@ package cn.hutool.poi.excel;
|
||||
import cn.hutool.core.io.resource.ResourceUtil;
|
||||
import cn.hutool.core.lang.Console;
|
||||
import cn.hutool.core.map.MapUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.ObjUtil;
|
||||
import cn.hutool.poi.excel.cell.CellHandler;
|
||||
import lombok.Data;
|
||||
import org.junit.Assert;
|
||||
@@ -206,7 +206,7 @@ public class ExcelReadTest {
|
||||
@Test
|
||||
public void nullValueEditTest(){
|
||||
final ExcelReader reader = ExcelUtil.getReader("null_cell_test.xlsx");
|
||||
reader.setCellEditor((cell, value)-> ObjectUtil.defaultIfNull(value, "#"));
|
||||
reader.setCellEditor((cell, value)-> ObjUtil.defaultIfNull(value, "#"));
|
||||
final List<List<Object>> read = reader.read();
|
||||
|
||||
// 对于任意一个单元格有值的情况下,之前的单元格值按照null处理
|
||||
|
||||
@@ -5,7 +5,7 @@ import cn.hutool.core.convert.Convert;
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.io.IoUtil;
|
||||
import cn.hutool.core.lang.Console;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.core.text.StrUtil;
|
||||
import cn.hutool.poi.excel.cell.FormulaCellValue;
|
||||
import cn.hutool.poi.excel.sax.Excel03SaxReader;
|
||||
import cn.hutool.poi.excel.sax.handler.RowHandler;
|
||||
|
||||
@@ -8,7 +8,7 @@ import cn.hutool.core.lang.Console;
|
||||
import cn.hutool.core.map.MapUtil;
|
||||
import cn.hutool.core.util.CharsetUtil;
|
||||
import cn.hutool.core.lang.id.IdUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.ObjUtil;
|
||||
import cn.hutool.poi.excel.cell.setters.EscapeStrCellSetter;
|
||||
import cn.hutool.poi.excel.style.StyleUtil;
|
||||
import org.apache.poi.common.usermodel.HyperlinkType;
|
||||
@@ -144,7 +144,7 @@ public class ExcelWriteTest {
|
||||
List<List<?>> rows = CollUtil.newArrayList(row1, row2, row3, row4, row5);
|
||||
for (int i = 0; i < 400; i++) {
|
||||
// 超大列表写出测试
|
||||
rows.add(ObjectUtil.clone(row1));
|
||||
rows.add(ObjUtil.clone(row1));
|
||||
}
|
||||
|
||||
String filePath = "d:/test/writeTest.xlsx";
|
||||
@@ -882,7 +882,7 @@ public class ExcelWriteTest {
|
||||
@Test
|
||||
public void getDispositionTest(){
|
||||
ExcelWriter writer = ExcelUtil.getWriter(true);
|
||||
final String disposition = writer.getDisposition("测试A12.xlsx", CharsetUtil.CHARSET_UTF_8);
|
||||
final String disposition = writer.getDisposition("测试A12.xlsx", CharsetUtil.UTF_8);
|
||||
Assert.assertEquals("attachment; filename=\"%E6%B5%8B%E8%AF%95A12.xlsx\"", disposition);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user