mirror of
https://gitee.com/dromara/hutool.git
synced 2025-05-04 20:58:00 +08:00
修复 ExcelUtil.getReader(xxx) 读取Excel后,Excel文件会发生变化
This commit is contained in:
parent
f52ec39d44
commit
1b6a27aa89
@ -63,7 +63,7 @@ public class ExcelReader extends ExcelBase<ExcelReader> {
|
|||||||
* @param sheetIndex sheet序号,0表示第一个sheet
|
* @param sheetIndex sheet序号,0表示第一个sheet
|
||||||
*/
|
*/
|
||||||
public ExcelReader(File bookFile, int sheetIndex) {
|
public ExcelReader(File bookFile, int sheetIndex) {
|
||||||
this(WorkbookUtil.createBook(bookFile), sheetIndex);
|
this(WorkbookUtil.createBook(bookFile, true), sheetIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -73,7 +73,7 @@ public class ExcelReader extends ExcelBase<ExcelReader> {
|
|||||||
* @param sheetName sheet名,第一个默认是sheet1
|
* @param sheetName sheet名,第一个默认是sheet1
|
||||||
*/
|
*/
|
||||||
public ExcelReader(File bookFile, String sheetName) {
|
public ExcelReader(File bookFile, String sheetName) {
|
||||||
this(WorkbookUtil.createBook(bookFile), sheetName);
|
this(WorkbookUtil.createBook(bookFile, true), sheetName);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -22,29 +22,52 @@ import java.io.OutputStream;
|
|||||||
*
|
*
|
||||||
* @author looly
|
* @author looly
|
||||||
* @since 4.0.7
|
* @since 4.0.7
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public class WorkbookUtil {
|
public class WorkbookUtil {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 创建或加载工作簿
|
* 创建或加载工作簿(读写模式)
|
||||||
*
|
*
|
||||||
* @param excelFilePath Excel文件路径,绝对路径或相对于ClassPath路径
|
* @param excelFilePath Excel文件路径,绝对路径或相对于ClassPath路径
|
||||||
* @return {@link Workbook}
|
* @return {@link Workbook}
|
||||||
* @since 3.1.1
|
* @since 3.1.1
|
||||||
*/
|
*/
|
||||||
public static Workbook createBook(String excelFilePath) {
|
public static Workbook createBook(String excelFilePath) {
|
||||||
return createBook(FileUtil.file(excelFilePath), null);
|
return createBook(excelFilePath, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 创建或加载工作簿
|
* 创建或加载工作簿
|
||||||
*
|
*
|
||||||
|
* @param excelFilePath Excel文件路径,绝对路径或相对于ClassPath路径
|
||||||
|
* @param readOnly 是否只读模式打开,true:是(不可编辑),false:否(可编辑)
|
||||||
|
* @return {@link Workbook}
|
||||||
|
* @since 3.1.1
|
||||||
|
*/
|
||||||
|
public static Workbook createBook(String excelFilePath, boolean readOnly) {
|
||||||
|
return createBook(FileUtil.file(excelFilePath), null, readOnly);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建或加载工作簿(读写模式)
|
||||||
|
*
|
||||||
* @param excelFile Excel文件
|
* @param excelFile Excel文件
|
||||||
* @return {@link Workbook}
|
* @return {@link Workbook}
|
||||||
*/
|
*/
|
||||||
public static Workbook createBook(File excelFile) {
|
public static Workbook createBook(File excelFile) {
|
||||||
return createBook(excelFile, null);
|
return createBook(excelFile, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建或加载工作簿
|
||||||
|
*
|
||||||
|
* @param excelFile Excel文件
|
||||||
|
* @param readOnly 是否只读模式打开,true:是(不可编辑),false:否(可编辑)
|
||||||
|
* @return {@link Workbook}
|
||||||
|
*/
|
||||||
|
public static Workbook createBook(File excelFile, boolean readOnly) {
|
||||||
|
return createBook(excelFile, null, readOnly);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -73,15 +96,27 @@ public class WorkbookUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 创建或加载工作簿,只读模式
|
* 创建或加载工作簿(读写模式)
|
||||||
*
|
*
|
||||||
* @param excelFile Excel文件
|
* @param excelFile Excel文件
|
||||||
* @param password Excel工作簿密码,如果无密码传{@code null}
|
* @param password Excel工作簿密码,如果无密码传{@code null}
|
||||||
* @return {@link Workbook}
|
* @return {@link Workbook}
|
||||||
*/
|
*/
|
||||||
public static Workbook createBook(File excelFile, String password) {
|
public static Workbook createBook(File excelFile, String password) {
|
||||||
|
return createBook(excelFile, password, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建或加载工作簿
|
||||||
|
*
|
||||||
|
* @param excelFile Excel文件
|
||||||
|
* @param password Excel工作簿密码,如果无密码传{@code null}
|
||||||
|
* @param readOnly 是否只读模式打开,true:是(不可编辑),false:否(可编辑)
|
||||||
|
* @return {@link Workbook}
|
||||||
|
*/
|
||||||
|
public static Workbook createBook(File excelFile, String password, boolean readOnly) {
|
||||||
try {
|
try {
|
||||||
return WorkbookFactory.create(excelFile, password);
|
return WorkbookFactory.create(excelFile, password, readOnly);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new POIException(e);
|
throw new POIException(e);
|
||||||
}
|
}
|
||||||
@ -133,29 +168,54 @@ public class WorkbookUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 创建或加载SXSSFWorkbook工作簿
|
* 创建或加载SXSSFWorkbook工作簿(读写模式)
|
||||||
*
|
*
|
||||||
* @param excelFilePath Excel文件路径,绝对路径或相对于ClassPath路径
|
* @param excelFilePath Excel文件路径,绝对路径或相对于ClassPath路径
|
||||||
* @return {@link SXSSFWorkbook}
|
* @return {@link SXSSFWorkbook}
|
||||||
* @since 4.1.13
|
* @since 4.1.13
|
||||||
*/
|
*/
|
||||||
public static SXSSFWorkbook createSXSSFBook(String excelFilePath) {
|
public static SXSSFWorkbook createSXSSFBook(String excelFilePath) {
|
||||||
return createSXSSFBook(FileUtil.file(excelFilePath), null);
|
return createSXSSFBook(excelFilePath, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 创建或加载SXSSFWorkbook工作簿
|
* 创建或加载SXSSFWorkbook工作簿
|
||||||
*
|
*
|
||||||
|
* @param excelFilePath Excel文件路径,绝对路径或相对于ClassPath路径
|
||||||
|
* @param readOnly 是否只读模式打开,true:是(不可编辑),false:否(可编辑)
|
||||||
|
* @return {@link SXSSFWorkbook}
|
||||||
|
* @since 4.1.13
|
||||||
|
*/
|
||||||
|
public static SXSSFWorkbook createSXSSFBook(String excelFilePath, boolean readOnly) {
|
||||||
|
return createSXSSFBook(FileUtil.file(excelFilePath), null, readOnly);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建或加载SXSSFWorkbook工作簿(读写模式)
|
||||||
|
*
|
||||||
* @param excelFile Excel文件
|
* @param excelFile Excel文件
|
||||||
* @return {@link SXSSFWorkbook}
|
* @return {@link SXSSFWorkbook}
|
||||||
* @since 4.1.13
|
* @since 4.1.13
|
||||||
*/
|
*/
|
||||||
public static SXSSFWorkbook createSXSSFBook(File excelFile) {
|
public static SXSSFWorkbook createSXSSFBook(File excelFile) {
|
||||||
return createSXSSFBook(excelFile, null);
|
return createSXSSFBook(excelFile, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 创建或加载SXSSFWorkbook工作簿,只读模式
|
* 创建或加载SXSSFWorkbook工作簿
|
||||||
|
*
|
||||||
|
* @param excelFile Excel文件
|
||||||
|
* @param readOnly 是否只读模式打开,true:是(不可编辑),false:否(可编辑)
|
||||||
|
* @return {@link SXSSFWorkbook}
|
||||||
|
* @since 4.1.13
|
||||||
|
*/
|
||||||
|
public static SXSSFWorkbook createSXSSFBook(File excelFile, boolean readOnly) {
|
||||||
|
return createSXSSFBook(excelFile, null, readOnly);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建或加载SXSSFWorkbook工作簿(读写模式)
|
||||||
*
|
*
|
||||||
* @param excelFile Excel文件
|
* @param excelFile Excel文件
|
||||||
* @param password Excel工作簿密码,如果无密码传{@code null}
|
* @param password Excel工作簿密码,如果无密码传{@code null}
|
||||||
@ -163,7 +223,21 @@ public class WorkbookUtil {
|
|||||||
* @since 4.1.13
|
* @since 4.1.13
|
||||||
*/
|
*/
|
||||||
public static SXSSFWorkbook createSXSSFBook(File excelFile, String password) {
|
public static SXSSFWorkbook createSXSSFBook(File excelFile, String password) {
|
||||||
return toSXSSFBook(createBook(excelFile, password));
|
return createSXSSFBook(excelFile, password, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建或加载SXSSFWorkbook工作簿
|
||||||
|
*
|
||||||
|
* @param excelFile Excel文件
|
||||||
|
* @param password Excel工作簿密码,如果无密码传{@code null}
|
||||||
|
* @param readOnly 是否只读模式打开,true:是(不可编辑),false:否(可编辑)
|
||||||
|
* @return {@link SXSSFWorkbook}
|
||||||
|
* @since 4.1.13
|
||||||
|
*/
|
||||||
|
public static SXSSFWorkbook createSXSSFBook(File excelFile, String password, boolean readOnly) {
|
||||||
|
return toSXSSFBook(createBook(excelFile, password, readOnly));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -271,7 +345,6 @@ public class WorkbookUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* sheet是否为空
|
* sheet是否为空
|
||||||
*
|
*
|
||||||
* @param sheet {@link Sheet}
|
* @param sheet {@link Sheet}
|
||||||
@ -283,6 +356,7 @@ public class WorkbookUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// -------------------------------------------------------------------------------------------------------- Private method start
|
// -------------------------------------------------------------------------------------------------------- Private method start
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 将普通工作簿转换为SXSSFWorkbook
|
* 将普通工作簿转换为SXSSFWorkbook
|
||||||
*
|
*
|
||||||
|
Loading…
Reference in New Issue
Block a user