欢迎使用CSDN-markdown编辑器
来源:互联网 发布:用手机淘宝注册账号 编辑:程序博客网 时间:2024/06/10 16:08
代码块
/*====================== 复制execl到指定行====================*/using NPOI.HSSF.UserModel;using NPOI.SS.UserModel;using NPOI.SS.Util;using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace UavSystem.UavModel.Export{ public class CopyExcel { //参数 1.要复制的开始行2.要复制的结束行3.复制到新execl第几行4.要复制的execl的sheet public void copyRows(int startRow, int endRow, int pPosition, ISheet sheet) { int pStartRow = startRow - 1; int pEndRow = endRow - 1; int targetRowFrom; int targetRowTo; int columnCount; CellRangeAddress region = null; int i; int j; if (pStartRow == -1 || pEndRow == -1) { return; } // 拷贝合并的单元格 for (i = 0; i < sheet.NumMergedRegions; i++) { region = sheet.GetMergedRegion(i); //sheet.getMergedRegion(i); if ((region.FirstRow >= pStartRow) && (region.LastRow <= pEndRow)) { targetRowFrom = region.FirstRow - pStartRow + pPosition; targetRowTo = region.LastRow - pStartRow + pPosition; CellRangeAddress newRegion = region.Copy(); newRegion.FirstRow = targetRowFrom; newRegion.FirstColumn = region.FirstColumn; newRegion.LastRow = targetRowTo; newRegion.LastColumn = region.LastColumn; sheet.AddMergedRegion(newRegion); } } // 设置列宽 for (i = pStartRow; i <= pEndRow; i++) { IRow sourceRow = sheet.GetRow(i); columnCount = sourceRow.LastCellNum; if (sourceRow != null) { IRow newRow = sheet.CreateRow(pPosition - pStartRow + i); newRow.Height = sourceRow.Height; for (j = 0; j < columnCount; j++) { ICell templateCell = sourceRow.GetCell(j); if (templateCell != null) { ICell newCell = newRow.CreateCell(j); copyCell(templateCell, newCell); } } } } } private void copyCell(ICell srcCell, ICell distCell) { distCell.CellStyle = srcCell.CellStyle; if (srcCell.CellComment != null) { distCell.CellComment = srcCell.CellComment; } // 不同数据类型处理 CellType srcCellType = srcCell.CellType; distCell.SetCellType(srcCellType); if (srcCellType == CellType.Numeric) { if (HSSFDateUtil.IsCellDateFormatted(srcCell)) { distCell.SetCellValue(srcCell.DateCellValue); } else { distCell.SetCellValue(srcCell.NumericCellValue); } } else if (srcCellType == CellType.String) { distCell.SetCellValue(srcCell.RichStringCellValue); } else if (srcCellType == CellType.Blank) { // nothing21 } else if (srcCellType == CellType.Boolean) { distCell.SetCellValue(srcCell.BooleanCellValue); } else if (srcCellType == CellType.Error) { distCell.SetCellErrorValue(srcCell.ErrorCellValue); } else if (srcCellType == CellType.Formula) { distCell.SetCellFormula(srcCell.CellFormula); } else { } } }}
阅读全文
0 0
- 欢迎使用CSDN-markdown编辑器
- 欢迎使用CSDN-markdown编辑器
- 欢迎使用CSDN-markdown编辑器
- 欢迎使用CSDN-markdown编辑器
- 欢迎使用CSDN-markdown编辑器
- 欢迎使用CSDN-markdown编辑器
- 欢迎使用CSDN-markdown编辑器
- 欢迎使用CSDN-markdown编辑器
- 欢迎使用CSDN-markdown编辑器
- 欢迎使用CSDN-markdown编辑器
- 欢迎使用CSDN-markdown编辑器
- 欢迎使用CSDN-markdown编辑器
- 欢迎使用CSDN-markdown编辑器
- 欢迎使用CSDN-markdown编辑器
- 欢迎使用CSDN-markdown编辑器
- 欢迎使用CSDN-markdown编辑器
- 欢迎使用CSDN-markdown编辑器
- 欢迎使用CSDN-markdown编辑器
- Could not get unknown property 'ANDROID_BUILD_SDK_VERSION'
- react native 暂时遇到问题的解决办法(windows)(1)
- Android Activity的四种启动模式
- 第三篇:UML用例建模解析(三)
- Android进阶#(7/12)装点程序“门面”——代码规范_第一个重点,排版
- 欢迎使用CSDN-markdown编辑器
- 多线程基础四(二)、能停止的线程(异常法、sleep、return、interrupt、stop)
- 你应该知道的9篇深度学习论文(CNNs 理解)
- Java-线程池专题(什么是线程池,如何使用,为什么要用)
- 获取状态栏、标题栏高度
- Mysql数据库数据类型详解
- Excel中CTRL+D的别样用法 隔行和隔列向下填充示例
- 玩转html5<canvas>画图
- 畅通工程--并查集(水)