当前位置:网站首页>复制excel行到指定行
复制excel行到指定行
2022-07-28 13:28:00 【腿毛ger】
/**
* 行复制功能
*
* @param fromRow
* @param toRow
*/
public static void _copyRow(Workbook wb,Sheet sheet, Row fromRow, Row 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();) {
Cell tmpCell = (Cell) cellIt.next();
Cell newCell = toRow.createCell(tmpCell.getColumnIndex());
_copyCell(wb, tmpCell, newCell, copyValueFlag);
}
}
public static void _copyCell(Workbook wb,Cell srcCell, Cell distCell,
boolean copyValueFlag) {
CellStyle 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 == Cell.CELL_TYPE_NUMERIC) {
if (HSSFDateUtil.isCellDateFormatted(srcCell)) {
distCell.setCellValue(srcCell.getDateCellValue());
} else {
distCell.setCellValue(srcCell.getNumericCellValue());
}
} else if (srcCellType == Cell.CELL_TYPE_STRING) {
distCell.setCellValue(srcCell.getRichStringCellValue());
} else if (srcCellType == Cell.CELL_TYPE_BLANK) {
// nothing21
} else if (srcCellType == Cell.CELL_TYPE_BOOLEAN) {
distCell.setCellValue(srcCell.getBooleanCellValue());
} else if (srcCellType == Cell.CELL_TYPE_ERROR) {
distCell.setCellErrorValue(srcCell.getErrorCellValue());
} else if (srcCellType == Cell.CELL_TYPE_FORMULA) {
distCell.setCellFormula(srcCell.getCellFormula());
} else { // nothing29
}
}
} 
边栏推荐
- 线程阻塞的三种情况。
- Clickhouse架构与设计
- 【Utils】ServletUtil
- Understanding of "image denoising using an improved generic advantageous network with Wasserstein distance"
- 离散对数问题(DLP) && Diffie-Hellman问题(DHP)
- Jmeter安装教程及登录增加token
- Revised version | target detection: speed and accuracy comparison (faster r-cnn, r-fcn, SSD, FPN, retinanet and yolov3)
- Super resolution reconstruction based on deep learning
- [ecmascript6] class
- Docker deploys Mysql to realize remote connection [easy to understand]
猜你喜欢

IP black and white list

Understanding of "image denoising using an improved generic advantageous network with Wasserstein distance"

软件测试工程师的职业规划

Mobile phone scrolling screenshot software recommendation

Redis sentinel mechanism

朗镜科技(Trax中国)“机器人+AI”开启中国零售元宇宙时代

多所“双一流”大学,保研预报名启动!

LeetCode 105.从前序与中序遍历序列构造二叉树 && 106.从中序与后序遍历序列构造二叉树

ZABBIX distributed

Foundation of deep learning ---- GNN spectral domain and airspace (continuous improvement, update and accumulation)
随机推荐
[ecmascript6] set and map
These three online PS tools should be tried
深度学习基础----GNN谱域和空域 (不断完善更新积累)
LeetCode 105.从前序与中序遍历序列构造二叉树 && 106.从中序与后序遍历序列构造二叉树
【Utils】JsonUtil
Foundation of deep learning ---- GNN spectral domain and airspace (continuous improvement, update and accumulation)
2022低压电工考试题及答案
Database optimization understanding these is enough
UFIDA BiP CRM new product launch enables large and medium-sized enterprises to grow their marketing
2022高处安装、维护、拆除考试题库及在线模拟考试
7.27 simulation summary
朗镜科技(Trax中国)“机器人+AI”开启中国零售元宇宙时代
Discrete logarithm problem (DLP) & Diffie Hellman problem (DHP)
【Utils】FastDFS工具类
JMeter installation tutorial and login add token
Thrift 序列化协议浅析
How to write test cases in software testing technology
Understand the principle behind the virtual list, and easily realize the virtual list
作为一个程序员,如何高效的管理时间?
[utils] fastdfs tool class