1
0
mirror of https://gitee.com/dromara/hutool.git synced 2025-04-05 17:37:59 +08:00

add methods

This commit is contained in:
Looly 2021-08-19 11:39:13 +08:00
parent 3cb4aa0796
commit 9d8f00e049
3 changed files with 45 additions and 3 deletions
CHANGELOG.md
hutool-core/src/main/java/cn/hutool/core/text/csv
hutool-poi/src/main/java/cn/hutool/poi/excel

View File

@ -14,6 +14,7 @@
* 【http 】 SoapClient.sendForResponse改为publicissue#I466NN@Gitee
* 【core 】 XmlUtil增加append重载issue#I466Q0@Gitee
* 【poi 】 增加EscapeStrCellSetterissue#I466ZZ@Gitee
* 【poi 】 ExcelBase增加renameSheet、cloneSheetissue#I466ZZ@Gitee
### 🐞Bug修复

View File

@ -11,7 +11,7 @@ import java.io.Serializable;
* @author looly
* @since 4.0.5
*/
public class CsvConfig<T extends CsvConfig<?>> implements Serializable {
public class CsvConfig<T extends CsvConfig<T>> implements Serializable {
private static final long serialVersionUID = -8069578249066158459L;
/**

View File

@ -12,6 +12,7 @@ import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.streaming.SXSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import java.io.Closeable;
import java.util.ArrayList;
@ -107,6 +108,21 @@ public class ExcelBase<T extends ExcelBase<T>> implements Closeable {
return this.sheet;
}
/**
* 重命名当前sheet
*
* @param newName 新名字
* @return this
* @see Workbook#setSheetName(int, String)
* @since 5.7.10
*/
@SuppressWarnings("unchecked")
public T renameSheet(String newName) {
this.workbook.setSheetName(this.workbook.getSheetIndex(this.sheet), newName);
return (T) this;
}
/**
* 自定义需要读取或写出的Sheet如果给定的sheet不存在创建之<br>
* 在读取中此方法用于切换读取的sheet在写出时此方法用于新建或者切换sheet
@ -144,6 +160,31 @@ public class ExcelBase<T extends ExcelBase<T>> implements Closeable {
return (T) this;
}
/**
* 复制当前sheet为新sheet
*
* @param sheetIndex sheet位置
* @param newSheetName 新sheet名
* @param setAsCurrentSheet 是否切换为当前sheet
* @return this
* @since 5.7.10
*/
@SuppressWarnings("unchecked")
public T cloneSheet(int sheetIndex, String newSheetName, boolean setAsCurrentSheet) {
Sheet sheet;
if (this.workbook instanceof XSSFWorkbook) {
XSSFWorkbook workbook = (XSSFWorkbook) this.workbook;
sheet = workbook.cloneSheet(sheetIndex, newSheetName);
} else {
sheet = this.workbook.cloneSheet(sheetIndex);
this.workbook.setSheetName(sheetIndex, newSheetName);
}
if (setAsCurrentSheet) {
this.sheet = sheet;
}
return (T) this;
}
/**
* 获取指定坐标单元格单元格不存在时返回{@code null}
*
@ -281,7 +322,7 @@ public class ExcelBase<T extends ExcelBase<T>> implements Closeable {
*/
public CellStyle createCellStyle(int x, int y) {
final Cell cell = getOrCreateCell(x, y);
final CellStyle cellStyle = this.workbook.createCellStyle();
final CellStyle cellStyle = this.workbook.createCellStyle();
cell.setCellStyle(cellStyle);
return cellStyle;
}
@ -293,7 +334,7 @@ public class ExcelBase<T extends ExcelBase<T>> implements Closeable {
* @see Workbook#createCellStyle()
* @since 5.4.0
*/
public CellStyle createCellStyle(){
public CellStyle createCellStyle() {
return StyleUtil.createCellStyle(this.workbook);
}