@@ -0,0 +1,170 @@ | |||
package org.jeecgframework.poi.excel.export.template; | |||
import java.util.ArrayList; | |||
import java.util.List; | |||
import org.apache.poi.ss.usermodel.Cell; | |||
import org.apache.poi.ss.usermodel.Row; | |||
import org.apache.poi.ss.usermodel.Sheet; | |||
import static org.jeecgframework.poi.util.PoiElUtil.*; | |||
/** | |||
* 针对模板统计问题做统一处理 | |||
* 1.处理模板之前统计需要SUM的数据以及位置 | |||
* 2.遍历时统计数据 | |||
* 3.遍历后设置数据 | |||
* @author JueYue | |||
* @date 2016年6月19日 | |||
*/ | |||
public class TemplateSumHanlder { | |||
private List<TemplateSumEntity> sumList = new ArrayList<TemplateSumEntity>(); | |||
/** | |||
* 统计计算所有的统计单元格 | |||
*/ | |||
public void getAllSumCell(Sheet sheet) { | |||
Row row = null; | |||
int index = 0; | |||
while (index <= sheet.getLastRowNum()) { | |||
row = sheet.getRow(index++); | |||
if (row == null) { | |||
continue; | |||
} | |||
for (int i = row.getFirstCellNum(); i < row.getLastCellNum(); i++) { | |||
if (row.getCell(i) != null && row.getCell(i).getStringCellValue().contains(SUM)) { | |||
addSumCellToList(row.getCell(i)); | |||
} | |||
} | |||
} | |||
} | |||
private void addSumCellToList(Cell cell) { | |||
String cellValue = cell.getStringCellValue(); | |||
int index = 0; | |||
while ((index = indexOfIgnoreCase(cellValue, SUM, index)) != -1) { | |||
TemplateSumEntity entity = new TemplateSumEntity(); | |||
entity.setCellValue(cellValue); | |||
entity.setSumKey(getSumKey(cellValue, index++)); | |||
entity.setCol(cell.getColumnIndex()); | |||
entity.setRow(cell.getRowIndex()); | |||
sumList.add(entity); | |||
} | |||
} | |||
/** | |||
* SUM:(key) | |||
* | |||
* @param cellValue | |||
* @param index | |||
* @return | |||
*/ | |||
private String getSumKey(String cellValue, int index) { | |||
return cellValue.substring(index + 4, cellValue.indexOf(")", index)); | |||
} | |||
public void addListSizeToSumEntity(){ | |||
} | |||
/** | |||
* | |||
* @param rowIndex | |||
*/ | |||
public void findForeachList(int rowIndex){ | |||
} | |||
private static int indexOfIgnoreCase(String str, String searchStr, int startPos) { | |||
if (str == null || searchStr == null) { | |||
return -1; | |||
} | |||
if (startPos < 0) { | |||
startPos = 0; | |||
} | |||
int endLimit = (str.length() - searchStr.length()) + 1; | |||
if (startPos > endLimit) { | |||
return -1; | |||
} | |||
if (searchStr.length() == 0) { | |||
return startPos; | |||
} | |||
for (int i = startPos; i < endLimit; i++) { | |||
if (str.regionMatches(true, i, searchStr, 0, searchStr.length())) { | |||
return i; | |||
} | |||
} | |||
return -1; | |||
} | |||
/** | |||
* 统计对象 | |||
* @author JueYue | |||
* @date 2016年6月19日 | |||
*/ | |||
protected class TemplateSumEntity { | |||
/** | |||
* CELL的值 | |||
*/ | |||
private String cellValue; | |||
/** | |||
* 需要计算的KEY | |||
*/ | |||
private String sumKey; | |||
/** | |||
* 列 | |||
*/ | |||
private int col; | |||
/** | |||
* 行 | |||
*/ | |||
private int row; | |||
/** | |||
* 最后值 | |||
*/ | |||
private Object value; | |||
public String getCellValue() { | |||
return cellValue; | |||
} | |||
public void setCellValue(String cellValue) { | |||
this.cellValue = cellValue; | |||
} | |||
public String getSumKey() { | |||
return sumKey; | |||
} | |||
public void setSumKey(String sumKey) { | |||
this.sumKey = sumKey; | |||
} | |||
public int getCol() { | |||
return col; | |||
} | |||
public void setCol(int col) { | |||
this.col = col; | |||
} | |||
public int getRow() { | |||
return row; | |||
} | |||
public void setRow(int row) { | |||
this.row = row; | |||
} | |||
public Object getValue() { | |||
return value; | |||
} | |||
public void setValue(Object value) { | |||
this.value = value; | |||
} | |||
} | |||
} |
@@ -0,0 +1,31 @@ | |||
/** | |||
* 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 | |||
* | |||
* Unless required by applicable law or agreed to in writing, software | |||
* distributed under the License is distributed on an "AS IS" BASIS, | |||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
* See the License for the specific language governing permissions and | |||
* limitations under the License. | |||
*/ | |||
package org.jeecgframework.poi.excel.html.css; | |||
import org.apache.poi.ss.usermodel.Cell; | |||
import org.jeecgframework.poi.excel.html.entity.CellStyleEntity; | |||
public class CssConverImpl implements ICssConvertToHtml, ICssConvertToExcel { | |||
@Override | |||
public void convertToExcel(Cell cell, CellStyleEntity style) { | |||
} | |||
@Override | |||
public void convertToHtml(Cell cell, CellStyleEntity entity) { | |||
} | |||
} |
@@ -0,0 +1,35 @@ | |||
/** | |||
* 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 | |||
* | |||
* Unless required by applicable law or agreed to in writing, software | |||
* distributed under the License is distributed on an "AS IS" BASIS, | |||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
* See the License for the specific language governing permissions and | |||
* limitations under the License. | |||
*/ | |||
package org.jeecgframework.poi.excel.html.css; | |||
import org.apache.poi.ss.usermodel.Cell; | |||
import org.jeecgframework.poi.excel.html.entity.CellStyleEntity; | |||
/** | |||
* CSS <--> Cell Style 转换类 | |||
* @author JueYue | |||
* 2016年3月20日 下午4:53:04 | |||
*/ | |||
public interface ICssConvertToExcel { | |||
/** | |||
* 把HTML样式转换成Cell样式 | |||
* @param cell | |||
* @param style | |||
* @return | |||
*/ | |||
public void convertToExcel(Cell cell, CellStyleEntity style); | |||
} |
@@ -0,0 +1,34 @@ | |||
/** | |||
* 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 | |||
* | |||
* Unless required by applicable law or agreed to in writing, software | |||
* distributed under the License is distributed on an "AS IS" BASIS, | |||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
* See the License for the specific language governing permissions and | |||
* limitations under the License. | |||
*/ | |||
package org.jeecgframework.poi.excel.html.css; | |||
import org.apache.poi.ss.usermodel.Cell; | |||
import org.jeecgframework.poi.excel.html.entity.CellStyleEntity; | |||
/** | |||
* CSS <--> Cell Style 转换类 | |||
* @author JueYue | |||
* 2016年3月20日 下午4:53:04 | |||
*/ | |||
public interface ICssConvertToHtml { | |||
/** | |||
* 把Excel单元格样式转换成HTML样式 | |||
* @param cell | |||
* @return | |||
*/ | |||
public void convertToHtml(Cell cell, CellStyleEntity style); | |||
} |
@@ -0,0 +1,54 @@ | |||
/** | |||
* 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 | |||
* | |||
* Unless required by applicable law or agreed to in writing, software | |||
* distributed under the License is distributed on an "AS IS" BASIS, | |||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
* See the License for the specific language governing permissions and | |||
* limitations under the License. | |||
*/ | |||
package org.jeecgframework.poi.excel.html.css.impl; | |||
import org.apache.poi.ss.usermodel.Cell; | |||
import org.apache.poi.ss.usermodel.CellStyle; | |||
import org.jeecgframework.poi.excel.html.css.ICssConvertToExcel; | |||
import org.jeecgframework.poi.excel.html.css.ICssConvertToHtml; | |||
import org.jeecgframework.poi.excel.html.entity.CellStyleBorderEntity; | |||
import org.jeecgframework.poi.excel.html.entity.CellStyleEntity; | |||
/** | |||
* 边框转换实现类 | |||
* @author JueYue | |||
* 2016年4月3日 上午10:26:47 | |||
*/ | |||
public class BorderCssConverImpl implements ICssConvertToExcel, ICssConvertToHtml { | |||
@Override | |||
public void convertToHtml(Cell cell, CellStyleEntity style) { | |||
} | |||
@Override | |||
public void convertToExcel(Cell cell, CellStyleEntity style) { | |||
CellStyle cellStyle = cell.getCellStyle(); | |||
if (cellStyle == null) { | |||
return; | |||
} | |||
CellStyleBorderEntity border = new CellStyleBorderEntity(); | |||
border.setBorderBottom(cellStyle.getBorderBottom()); | |||
border.setBorderBottomColor(cellStyle.getBottomBorderColor()); | |||
border.setBorderLeft(cellStyle.getBorderLeft()); | |||
border.setBorderLeftColor(cellStyle.getLeftBorderColor()); | |||
border.setBorderRight(cellStyle.getBorderRight()); | |||
border.setBorderRightColor(cellStyle.getRightBorderColor()); | |||
border.setBorderTop(cellStyle.getBorderTop()); | |||
border.setBorderTopColor(cellStyle.getTopBorderColor()); | |||
style.setBorder(border); | |||
} | |||
} |
@@ -0,0 +1,40 @@ | |||
/** | |||
* 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 | |||
* | |||
* Unless required by applicable law or agreed to in writing, software | |||
* distributed under the License is distributed on an "AS IS" BASIS, | |||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
* See the License for the specific language governing permissions and | |||
* limitations under the License. | |||
*/ | |||
package org.jeecgframework.poi.excel.html.css.impl; | |||
import org.apache.poi.ss.usermodel.Cell; | |||
import org.jeecgframework.poi.excel.html.css.ICssConvertToExcel; | |||
import org.jeecgframework.poi.excel.html.css.ICssConvertToHtml; | |||
import org.jeecgframework.poi.excel.html.entity.CellStyleEntity; | |||
/** | |||
* 行高转换实现类 | |||
* @author JueYue | |||
* 2016年4月3日 上午10:26:47 | |||
*/ | |||
public class HeightCssConverImpl implements ICssConvertToExcel, ICssConvertToHtml { | |||
@Override | |||
public void convertToHtml(Cell cell, CellStyleEntity style) { | |||
style.setHeight(cell.getRow().getHeight()); | |||
} | |||
@Override | |||
public void convertToExcel(Cell cell, CellStyleEntity style) { | |||
} | |||
} |
@@ -0,0 +1,39 @@ | |||
/** | |||
* 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 | |||
* | |||
* Unless required by applicable law or agreed to in writing, software | |||
* distributed under the License is distributed on an "AS IS" BASIS, | |||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
* See the License for the specific language governing permissions and | |||
* limitations under the License. | |||
*/ | |||
package org.jeecgframework.poi.excel.html.css.impl; | |||
import org.apache.poi.ss.usermodel.Cell; | |||
import org.jeecgframework.poi.excel.html.css.ICssConvertToExcel; | |||
import org.jeecgframework.poi.excel.html.css.ICssConvertToHtml; | |||
import org.jeecgframework.poi.excel.html.entity.CellStyleEntity; | |||
/** | |||
* 列宽转换实现类 | |||
* @author JueYue | |||
* 2016年4月3日 上午10:26:47 | |||
*/ | |||
public class WidthCssConverImpl implements ICssConvertToExcel, ICssConvertToHtml { | |||
@Override | |||
public void convertToHtml(Cell cell, CellStyleEntity style) { | |||
style.setWidth(cell.getRow().getSheet().getColumnWidth(cell.getColumnIndex())); | |||
} | |||
@Override | |||
public void convertToExcel(Cell cell, CellStyleEntity style) { | |||
} | |||
} |
@@ -0,0 +1,105 @@ | |||
/** | |||
* 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 | |||
* | |||
* Unless required by applicable law or agreed to in writing, software | |||
* distributed under the License is distributed on an "AS IS" BASIS, | |||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
* See the License for the specific language governing permissions and | |||
* limitations under the License. | |||
*/ | |||
package org.jeecgframework.poi.excel.html.entity; | |||
/** | |||
* 边框样式 | |||
* @author JueYue | |||
* 2016年4月3日 上午10:35:28 | |||
*/ | |||
public class CellStyleBorderEntity { | |||
private short borderLeft; | |||
private short borderRight; | |||
private short borderTop; | |||
private short borderBottom; | |||
private short borderLeftColor; | |||
private short borderRightColor; | |||
private short borderTopColor; | |||
private short borderBottomColor; | |||
public short getBorderLeft() { | |||
return borderLeft; | |||
} | |||
public void setBorderLeft(short borderLeft) { | |||
this.borderLeft = borderLeft; | |||
} | |||
public short getBorderRight() { | |||
return borderRight; | |||
} | |||
public void setBorderRight(short borderRight) { | |||
this.borderRight = borderRight; | |||
} | |||
public short getBorderTop() { | |||
return borderTop; | |||
} | |||
public void setBorderTop(short borderTop) { | |||
this.borderTop = borderTop; | |||
} | |||
public short getBorderBottom() { | |||
return borderBottom; | |||
} | |||
public void setBorderBottom(short borderBottom) { | |||
this.borderBottom = borderBottom; | |||
} | |||
public short getBorderLeftColor() { | |||
return borderLeftColor; | |||
} | |||
public void setBorderLeftColor(short borderLeftColor) { | |||
this.borderLeftColor = borderLeftColor; | |||
} | |||
public short getBorderRightColor() { | |||
return borderRightColor; | |||
} | |||
public void setBorderRightColor(short borderRightColor) { | |||
this.borderRightColor = borderRightColor; | |||
} | |||
public short getBorderTopColor() { | |||
return borderTopColor; | |||
} | |||
public void setBorderTopColor(short borderTopColor) { | |||
this.borderTopColor = borderTopColor; | |||
} | |||
public short getBorderBottomColor() { | |||
return borderBottomColor; | |||
} | |||
public void setBorderBottomColor(short borderBottomColor) { | |||
this.borderBottomColor = borderBottomColor; | |||
} | |||
} |
@@ -0,0 +1,97 @@ | |||
/** | |||
* 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 | |||
* | |||
* Unless required by applicable law or agreed to in writing, software | |||
* distributed under the License is distributed on an "AS IS" BASIS, | |||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
* See the License for the specific language governing permissions and | |||
* limitations under the License. | |||
*/ | |||
package org.jeecgframework.poi.excel.html.entity; | |||
/** | |||
* Cell 具有的样式 | |||
* @author JueYue | |||
* 2016年3月20日 下午4:56:51 | |||
*/ | |||
public class CellStyleEntity { | |||
/** | |||
* 宽 | |||
*/ | |||
private double width; | |||
/** | |||
* 高 | |||
*/ | |||
private double height; | |||
/** | |||
* 边框 | |||
*/ | |||
private CellStyleBorderEntity border; | |||
/** | |||
* 背景 | |||
*/ | |||
private String background; | |||
/** | |||
* 水平位置 | |||
*/ | |||
private String align; | |||
/** | |||
* 垂直位置 | |||
*/ | |||
private String vetical; | |||
public double getWidth() { | |||
return width; | |||
} | |||
public void setWidth(double width) { | |||
this.width = width; | |||
} | |||
public double getHeight() { | |||
return height; | |||
} | |||
public void setHeight(double height) { | |||
this.height = height; | |||
} | |||
public CellStyleBorderEntity getBorder() { | |||
return border; | |||
} | |||
public void setBorder(CellStyleBorderEntity border) { | |||
this.border = border; | |||
} | |||
public String getBackground() { | |||
return background; | |||
} | |||
public void setBackground(String background) { | |||
this.background = background; | |||
} | |||
public String getAlign() { | |||
return align; | |||
} | |||
public void setAlign(String align) { | |||
this.align = align; | |||
} | |||
public String getVetical() { | |||
return vetical; | |||
} | |||
public void setVetical(String vetical) { | |||
this.vetical = vetical; | |||
} | |||
} |
@@ -38,6 +38,7 @@ public final class PoiElUtil { | |||
public static final String NUMBER_SYMBOL = "n:"; | |||
public static final String FORMAT_DATE = "fd:"; | |||
public static final String FORMAT_NUMBER = "fn:"; | |||
public static final String SUM = "sum:"; | |||
public static final String IF_DELETE = "!if:"; | |||
public static final String EMPTY = ""; | |||
public static final String CONST = "'"; | |||