@@ -167,7 +167,7 @@ public class ExcelExportServer extends BaseExportServer { | |||||
? createHeaderAndTitle(entity, sheet, workbook, excelParams) : 0; | ? createHeaderAndTitle(entity, sheet, workbook, excelParams) : 0; | ||||
int titleHeight = index; | int titleHeight = index; | ||||
setCellWith(excelParams, sheet); | setCellWith(excelParams, sheet); | ||||
short rowHeight = entity.getHeight() > 0? entity.getHeight() : getRowHeight(excelParams); | |||||
short rowHeight = entity.getHeight() > 0 ? entity.getHeight() : getRowHeight(excelParams); | |||||
setCurrentIndex(1); | setCurrentIndex(1); | ||||
Iterator<?> its = dataSet.iterator(); | Iterator<?> its = dataSet.iterator(); | ||||
List<Object> tempList = new ArrayList<Object>(); | List<Object> tempList = new ArrayList<Object>(); | ||||
@@ -226,15 +226,18 @@ public class ExcelExportServer extends BaseExportServer { | |||||
CellStyle titleStyle = getExcelExportStyler().getTitleStyle(title.getColor()); | CellStyle titleStyle = getExcelExportStyler().getTitleStyle(title.getColor()); | ||||
for (int i = 0, exportFieldTitleSize = excelParams.size(); i < exportFieldTitleSize; i++) { | for (int i = 0, exportFieldTitleSize = excelParams.size(); i < exportFieldTitleSize; i++) { | ||||
ExcelExportEntity entity = excelParams.get(i); | ExcelExportEntity entity = excelParams.get(i); | ||||
// 加入换了groupName或者结束就,就把之前的那个换行 | |||||
if (StringUtils.isBlank(entity.getGroupName()) || !entity.getGroupName().equals(excelParams.get(i - 1).getGroupName())) { | |||||
if(groupCellLength > 1){ | |||||
sheet.addMergedRegion(new CellRangeAddress(index, index, cellIndex - groupCellLength, cellIndex - 1)); | |||||
} | |||||
groupCellLength = 0; | |||||
} | |||||
if (StringUtils.isNotBlank(entity.getGroupName())) { | if (StringUtils.isNotBlank(entity.getGroupName())) { | ||||
createStringCell(row, cellIndex, entity.getGroupName(), titleStyle, entity); | createStringCell(row, cellIndex, entity.getGroupName(), titleStyle, entity); | ||||
createStringCell(listRow, cellIndex, entity.getName(), titleStyle, entity); | createStringCell(listRow, cellIndex, entity.getName(), titleStyle, entity); | ||||
groupCellLength++; | groupCellLength++; | ||||
} else if (StringUtils.isNotBlank(entity.getName())) { | } else if (StringUtils.isNotBlank(entity.getName())) { | ||||
if(groupCellLength > 0){ | |||||
sheet.addMergedRegion(new CellRangeAddress(index, index, cellIndex, cellIndex - groupCellLength)); | |||||
groupCellLength = 0; | |||||
} | |||||
createStringCell(row, cellIndex, entity.getName(), titleStyle, entity); | createStringCell(row, cellIndex, entity.getName(), titleStyle, entity); | ||||
} | } | ||||
if (entity.getList() != null) { | if (entity.getList() != null) { | ||||
@@ -254,7 +257,7 @@ public class ExcelExportServer extends BaseExportServer { | |||||
} | } | ||||
cellIndex++; | cellIndex++; | ||||
} | } | ||||
if(groupCellLength > 0){ | |||||
if (groupCellLength > 1) { | |||||
sheet.addMergedRegion(new CellRangeAddress(index, index, cellIndex - groupCellLength, cellIndex - 1)); | sheet.addMergedRegion(new CellRangeAddress(index, index, cellIndex - groupCellLength, cellIndex - 1)); | ||||
} | } | ||||
return rows; | return rows; | ||||
@@ -1,13 +1,13 @@ | |||||
/** | /** | ||||
* Copyright 2013-2015 JueYue (qrb.jueyue@gmail.com) | * Copyright 2013-2015 JueYue (qrb.jueyue@gmail.com) | ||||
* | |||||
* Licensed under the Apache License, Version 2.0 (the "License"); | |||||
* you may not use this file except in compliance with the License. | |||||
* You may obtain a copy of the License at | |||||
* | * | ||||
* http://www.apache.org/licenses/LICENSE-2.0 | |||||
* Licensed under the Apache License, Version 2.0 (the "License"); | |||||
* you may not use this file except in compliance with the License. | |||||
* You may obtain a copy of the License at | |||||
* | * | ||||
* Unless required by applicable law or agreed to in writing, software | |||||
* http://www.apache.org/licenses/LICENSE-2.0 | |||||
* | |||||
* Unless required by applicable law or agreed to in writing, software | |||||
* distributed under the License is distributed on an "AS IS" BASIS, | * distributed under the License is distributed on an "AS IS" BASIS, | ||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
* See the License for the specific language governing permissions and | * See the License for the specific language governing permissions and | ||||
@@ -16,6 +16,7 @@ | |||||
package cn.afterturn.easypoi.excel.export.styler; | package cn.afterturn.easypoi.excel.export.styler; | ||||
import org.apache.poi.ss.usermodel.BuiltinFormats; | import org.apache.poi.ss.usermodel.BuiltinFormats; | ||||
import org.apache.poi.ss.usermodel.Cell; | |||||
import org.apache.poi.ss.usermodel.CellStyle; | import org.apache.poi.ss.usermodel.CellStyle; | ||||
import org.apache.poi.ss.usermodel.Workbook; | import org.apache.poi.ss.usermodel.Workbook; | ||||
@@ -24,18 +25,18 @@ import cn.afterturn.easypoi.excel.entity.params.ExcelForEachParams; | |||||
/** | /** | ||||
* 抽象接口提供两个公共方法 | * 抽象接口提供两个公共方法 | ||||
* @author JueYue | |||||
* 2015年1月9日 下午5:48:55 | |||||
* | |||||
* @author JueYue 2015年1月9日 下午5:48:55 | |||||
*/ | */ | ||||
public abstract class AbstractExcelExportStyler implements IExcelExportStyler { | public abstract class AbstractExcelExportStyler implements IExcelExportStyler { | ||||
//单行 | //单行 | ||||
protected CellStyle stringNoneStyle; | |||||
protected CellStyle stringNoneWrapStyle; | |||||
protected CellStyle stringNoneStyle; | |||||
protected CellStyle stringNoneWrapStyle; | |||||
//间隔行 | //间隔行 | ||||
protected CellStyle stringSeptailStyle; | |||||
protected CellStyle stringSeptailWrapStyle; | |||||
protected CellStyle stringSeptailStyle; | |||||
protected CellStyle stringSeptailWrapStyle; | |||||
protected Workbook workbook; | |||||
protected Workbook workbook; | |||||
protected static final short STRING_FORMAT = (short) BuiltinFormats.getBuiltinFormat("TEXT"); | protected static final short STRING_FORMAT = (short) BuiltinFormats.getBuiltinFormat("TEXT"); | ||||
@@ -61,6 +62,11 @@ public abstract class AbstractExcelExportStyler implements IExcelExportStyler { | |||||
return stringSeptailStyle; | return stringSeptailStyle; | ||||
} | } | ||||
@Override | |||||
public CellStyle getStyles(Cell cell, int dataRow, ExcelExportEntity entity, Object obj, Object data) { | |||||
return getStyles(dataRow % 2 == 1, entity); | |||||
} | |||||
public CellStyle stringNoneStyle(Workbook workbook, boolean isWarp) { | public CellStyle stringNoneStyle(Workbook workbook, boolean isWarp) { | ||||
return null; | return null; | ||||
} | } | ||||
@@ -69,6 +75,7 @@ public abstract class AbstractExcelExportStyler implements IExcelExportStyler { | |||||
return null; | return null; | ||||
} | } | ||||
@Override | @Override | ||||
public CellStyle getTemplateStyles(boolean isSingle, ExcelForEachParams excelForEachParams) { | public CellStyle getTemplateStyles(boolean isSingle, ExcelForEachParams excelForEachParams) { | ||||
return null; | return null; | ||||
@@ -1,13 +1,13 @@ | |||||
/** | /** | ||||
* Copyright 2013-2015 JueYue (qrb.jueyue@gmail.com) | * Copyright 2013-2015 JueYue (qrb.jueyue@gmail.com) | ||||
* | |||||
* Licensed under the Apache License, Version 2.0 (the "License"); | |||||
* you may not use this file except in compliance with the License. | |||||
* You may obtain a copy of the License at | |||||
* | * | ||||
* http://www.apache.org/licenses/LICENSE-2.0 | |||||
* Licensed under the Apache License, Version 2.0 (the "License"); | |||||
* you may not use this file except in compliance with the License. | |||||
* You may obtain a copy of the License at | |||||
* | * | ||||
* Unless required by applicable law or agreed to in writing, software | |||||
* http://www.apache.org/licenses/LICENSE-2.0 | |||||
* | |||||
* Unless required by applicable law or agreed to in writing, software | |||||
* distributed under the License is distributed on an "AS IS" BASIS, | * distributed under the License is distributed on an "AS IS" BASIS, | ||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
* See the License for the specific language governing permissions and | * See the License for the specific language governing permissions and | ||||
@@ -15,6 +15,7 @@ | |||||
*/ | */ | ||||
package cn.afterturn.easypoi.excel.export.styler; | package cn.afterturn.easypoi.excel.export.styler; | ||||
import org.apache.poi.ss.usermodel.Cell; | |||||
import org.apache.poi.ss.usermodel.CellStyle; | import org.apache.poi.ss.usermodel.CellStyle; | ||||
import cn.afterturn.easypoi.excel.entity.params.ExcelExportEntity; | import cn.afterturn.easypoi.excel.entity.params.ExcelExportEntity; | ||||
@@ -22,38 +23,38 @@ import cn.afterturn.easypoi.excel.entity.params.ExcelForEachParams; | |||||
/** | /** | ||||
* Excel导出样式接口 | * Excel导出样式接口 | ||||
* @author JueYue | |||||
* 2015年1月9日 下午5:32:30 | |||||
* | |||||
* @author JueYue 2015年1月9日 下午5:32:30 | |||||
*/ | */ | ||||
public interface IExcelExportStyler { | public interface IExcelExportStyler { | ||||
/** | /** | ||||
* 列表头样式 | * 列表头样式 | ||||
* @param headerColor | |||||
* @return | |||||
*/ | */ | ||||
public CellStyle getHeaderStyle(short headerColor); | public CellStyle getHeaderStyle(short headerColor); | ||||
/** | /** | ||||
* 标题样式 | * 标题样式 | ||||
* @param color | |||||
* @return | |||||
*/ | */ | ||||
public CellStyle getTitleStyle(short color); | public CellStyle getTitleStyle(short color); | ||||
/** | /** | ||||
* 获取样式方法 | * 获取样式方法 | ||||
* @param parity | |||||
* @param entity | |||||
* @return | |||||
*/ | */ | ||||
@Deprecated | |||||
public CellStyle getStyles(boolean parity, ExcelExportEntity entity); | public CellStyle getStyles(boolean parity, ExcelExportEntity entity); | ||||
/** | |||||
* 获取样式方法 | |||||
* | |||||
* @param dataRow 数据行 | |||||
* @param obj 对象 | |||||
* @param data 数据 | |||||
*/ | |||||
public CellStyle getStyles(Cell cell, int dataRow, ExcelExportEntity entity, Object obj, Object data); | |||||
/** | /** | ||||
* 模板使用的样式设置 | * 模板使用的样式设置 | ||||
* @param isSingle | |||||
* @param excelForEachParams | |||||
* @return | |||||
*/ | */ | ||||
public CellStyle getTemplateStyles(boolean isSingle, ExcelForEachParams excelForEachParams); | public CellStyle getTemplateStyles(boolean isSingle, ExcelForEachParams excelForEachParams); | ||||