mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
fix code
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
package cn.hutool.poi.excel;
|
||||
|
||||
import java.io.Closeable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import cn.hutool.core.io.IoUtil;
|
||||
import cn.hutool.core.lang.Assert;
|
||||
import cn.hutool.poi.excel.cell.CellLocation;
|
||||
import cn.hutool.poi.excel.cell.CellUtil;
|
||||
import cn.hutool.poi.excel.style.StyleUtil;
|
||||
import org.apache.poi.ss.usermodel.Cell;
|
||||
import org.apache.poi.ss.usermodel.CellStyle;
|
||||
import org.apache.poi.ss.usermodel.Row;
|
||||
@@ -12,10 +12,9 @@ import org.apache.poi.ss.usermodel.Sheet;
|
||||
import org.apache.poi.ss.usermodel.Workbook;
|
||||
import org.apache.poi.xssf.usermodel.XSSFSheet;
|
||||
|
||||
import cn.hutool.core.io.IoUtil;
|
||||
import cn.hutool.core.lang.Assert;
|
||||
import cn.hutool.poi.excel.cell.CellUtil;
|
||||
import cn.hutool.poi.excel.style.StyleUtil;
|
||||
import java.io.Closeable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Excel基础类,用于抽象ExcelWriter和ExcelReader中共用部分的对象和方法
|
||||
@@ -281,11 +280,22 @@ 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建单元格样式
|
||||
*
|
||||
* @return {@link CellStyle}
|
||||
* @see Workbook#createCellStyle()
|
||||
* @since 5.4.0
|
||||
*/
|
||||
public CellStyle createCellStyle(){
|
||||
return StyleUtil.createCellStyle(this.workbook);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取或创建某一行的样式,返回样式后可以设置样式内容<br>
|
||||
* 需要注意,此方法返回行样式,设置背景色在单元格设置值后会被覆盖,需要单独设置其单元格的样式。
|
||||
|
@@ -39,7 +39,7 @@ public class StyleUtil {
|
||||
* @return {@link CellStyle}
|
||||
*/
|
||||
public static CellStyle cloneCellStyle(Workbook workbook, CellStyle cellStyle) {
|
||||
final CellStyle newCellStyle = workbook.createCellStyle();
|
||||
final CellStyle newCellStyle = createCellStyle(workbook);
|
||||
newCellStyle.cloneStyleFrom(cellStyle);
|
||||
return newCellStyle;
|
||||
}
|
||||
@@ -144,6 +144,21 @@ public class StyleUtil {
|
||||
return font;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建单元格样式
|
||||
*
|
||||
* @param workbook {@link Workbook} 工作簿
|
||||
* @return {@link CellStyle}
|
||||
* @see Workbook#createCellStyle()
|
||||
* @since 5.4.0
|
||||
*/
|
||||
public static CellStyle createCellStyle(Workbook workbook) {
|
||||
if(null == workbook){
|
||||
return null;
|
||||
}
|
||||
return workbook.createCellStyle();
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建默认普通单元格样式
|
||||
*
|
||||
@@ -156,7 +171,7 @@ public class StyleUtil {
|
||||
* @return {@link CellStyle}
|
||||
*/
|
||||
public static CellStyle createDefaultCellStyle(Workbook workbook) {
|
||||
final CellStyle cellStyle = workbook.createCellStyle();
|
||||
final CellStyle cellStyle = createCellStyle(workbook);
|
||||
setAlign(cellStyle, HorizontalAlignment.CENTER, VerticalAlignment.CENTER);
|
||||
setBorder(cellStyle, BorderStyle.THIN, IndexedColors.BLACK);
|
||||
return cellStyle;
|
||||
@@ -169,7 +184,7 @@ public class StyleUtil {
|
||||
* @return {@link CellStyle}
|
||||
*/
|
||||
public static CellStyle createHeadCellStyle(Workbook workbook) {
|
||||
final CellStyle cellStyle = workbook.createCellStyle();
|
||||
final CellStyle cellStyle = createCellStyle(workbook);
|
||||
setAlign(cellStyle, HorizontalAlignment.CENTER, VerticalAlignment.CENTER);
|
||||
setBorder(cellStyle, BorderStyle.THIN, IndexedColors.BLACK);
|
||||
setColor(cellStyle, IndexedColors.GREY_25_PERCENT, FillPatternType.SOLID_FOREGROUND);
|
||||
|
Reference in New Issue
Block a user