当前位置:网站首页>Copy excel row to specified row
Copy excel row to specified row
2022-07-28 14:22:00 【Leg hair Ger】
/**
* Line copy function
*
* @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());
// style
distCell.setCellStyle(newstyle);
// Comment on
if (srcCell.getCellComment() != null) {
distCell.setCellComment(srcCell.getCellComment());
}
// Different data types are processed
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
}
}
} 
边栏推荐
- Mobile phone scrolling screenshot software recommendation
- zabbix分布式
- Langjing Technology (Trax China) "robot +ai" opens the era of Chinese retail meta universe
- Clickhouse架构与设计
- Multi level cache scheme
- Jmeter安装教程及登录增加token
- MeterSphere--开源持续测试平台
- IP black and white list
- LeetCode 105.从前序与中序遍历序列构造二叉树 && 106.从中序与后序遍历序列构造二叉树
- Daily question - Scholarship
猜你喜欢

2022高处安装、维护、拆除考试题库及在线模拟考试
![[ecmascript6] set and map](/img/64/dd6ffc5f0faf881b990e609cf62343.png)
[ecmascript6] set and map

开源项目丨Taier1.2版本发布,新增工作流、租户绑定简化等多项功能

Foundation of deep learning ---- GNN spectral domain and airspace (continuous improvement, update and accumulation)

草料二维码--在线二维码生成器

LeetCode 0142.环形链表 II

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

ZABBIX distributed

Langjing Technology (Trax China) "robot +ai" opens the era of Chinese retail meta universe

修订版 | 目标检测:速度和准确性比较(Faster R-CNN,R-FCN,SSD,FPN,RetinaNet和YOLOv3)...
随机推荐
Detailed explanation of C language student achievement management system [easy to understand]
Revised version | target detection: speed and accuracy comparison (faster r-cnn, r-fcn, SSD, FPN, retinanet and yolov3)
LeetCode 1331.数组序号转换
[utils] fastdfs tool class
协同办公工具:在线白板初起步,在线设计已红海
如何有效进行回顾会议(上)?
超好用的手机录屏软件推荐
How to effectively conduct the review meeting (Part 1)?
阿里、京东、抖音:把云推向产业心脏
2022低压电工考试题及答案
目标检测:速度和准确性比较(Fater R-CNN,R-FCN,SSD,FPN,RetinaNet和YOLOv3)
3种方法解轮转数组
HCIP第十一天
Leetcode 1331. array sequence number conversion
Thesis study -- masked generative disintegration
As a programmer, how to manage time efficiently?
手机滚动截屏软件推荐
[ecmascript6] other new interface features
用友BIP CRM新品发布,赋能大中型企业营销增长
【翻译】盐业公司来Linkerd公司是为了负载平衡,留下来是为了效率、可靠性和性能。...