Apache poi 3.9复制行到指定位置(支持复制合并单元格)
来源:互联网 发布:电脑软件入门教程 编辑:程序博客网 时间:2024/06/05 17:36
在网上查了一下相关资料,都不适用,自己改动后成功复制
/**
* 行复制功能* @param fromRow
* @param toRow
*/
public static void copyRow(HSSFWorkbook wb,HSSFSheet sheet,HSSFRow fromRow,HSSFRow toRow,boolean copyValueFlag){
toRow.setHeight(fromRow.getHeight());
for(int i = 0; i < sheet.getNumMergedRegions(); i++) {
CellRangeAddress cellRangeAddress = sheet.getMergedRegion(i);
if(cellRangeAddress.getFirstRow() == fromRow.getRowNum()) {
CellRangeAddress newCellRangeAddress = new CellRangeAddress(toRow.getRowNum(), (toRow.getRowNum() +
(cellRangeAddress.getLastRow() - cellRangeAddress.getFirstRow())), cellRangeAddress
.getFirstColumn(), cellRangeAddress.getLastColumn());
sheet.addMergedRegion(newCellRangeAddress);
}
}
for (Iterator cellIt = fromRow.cellIterator(); cellIt.hasNext();) {
HSSFCell tmpCell = (HSSFCell) cellIt.next();
HSSFCell newCell = toRow.createCell(tmpCell.getCellNum());
copyCell(wb,tmpCell, newCell, copyValueFlag);
}
}
/**
* 复制单元格
*
* @param srcCell
* @param distCell
* @param copyValueFlag
* true则连同cell的内容一起复制
*/
public static void copyCell(HSSFWorkbook wb,HSSFCell srcCell, HSSFCell distCell,
boolean copyValueFlag) {
HSSFCellStyle newstyle=wb.createCellStyle();
newstyle.cloneStyleFrom(srcCell.getCellStyle());
//样式
distCell.setCellStyle(newstyle);
//评论
if (srcCell.getCellComment() != null) {
distCell.setCellComment(srcCell.getCellComment());
}
// 不同数据类型处理
int srcCellType = srcCell.getCellType();
distCell.setCellType(srcCellType);
if (copyValueFlag) {
if (srcCellType == HSSFCell.CELL_TYPE_NUMERIC) {
if (HSSFDateUtil.isCellDateFormatted(srcCell)) {
distCell.setCellValue(srcCell.getDateCellValue());
} else {
distCell.setCellValue(srcCell.getNumericCellValue());
}
} else if (srcCellType == HSSFCell.CELL_TYPE_STRING) {
distCell.setCellValue(srcCell.getRichStringCellValue());
} else if (srcCellType == HSSFCell.CELL_TYPE_BLANK) {
// nothing21
} else if (srcCellType == HSSFCell.CELL_TYPE_BOOLEAN) {
distCell.setCellValue(srcCell.getBooleanCellValue());
} else if (srcCellType == HSSFCell.CELL_TYPE_ERROR) {
distCell.setCellErrorValue(srcCell.getErrorCellValue());
} else if (srcCellType == HSSFCell.CELL_TYPE_FORMULA) {
distCell.setCellFormula(srcCell.getCellFormula());
} else { // nothing29
}
}
}
阅读全文
0 0
- Apache poi 3.9复制行到指定位置(支持复制合并单元格)
- POI复制行支持07,13。同时复制单元格合并
- poi操作excel,复制sheet,复制行,复制单元格
- poi操作excel,复制sheet,复制行,复制单元格 .
- Apache POI 合并单元格
- Apache POI 合并单元格
- 复制指定文件(夹)到指定位置
- Jacob 复制表格到指定位置
- java—file复制到指定位置
- poi 复制并合格单元格
- Apache POI Excel合并单元格
- Apache POI读合并单元格
- 关于POI设置SHEET名称以及合并单元格,复制单元格方法
- poi Excel复制指定行案例
- poi导出excel,支持合并的单元格
- poi读取excel,支持合并单元格
- java之Apache POI 合并单元格
- 汇编语言中复制程序中的特定代码到指定位置
- filter函数
- Tensorflow安装教程
- easyUI中combobox解决不能中文检索的方式
- Kaptcha验证码的使用
- oracle交集,并集,差集
- Apache poi 3.9复制行到指定位置(支持复制合并单元格)
- ImageView使用一张图片做出selector效果,控件点击出现波纹效果,友好的交互。
- spring mvc + hibernate 框架搭建
- 首次在没有参考解析的情况下完成了一个leetcode题目!
- 初始化版本库 简要说明
- Python matplotlib 生成图形
- javasctipt常用事件总结
- java使用插件播放mp3,同时只播放一首歌
- keras 搬砖系列-自编码器