NPOI 将一个sheet指定区域复制到另一个sheet,复制数据,样式和备注
来源:互联网 发布:linux 修改用户权限 编辑:程序博客网 时间:2024/06/06 04:09
Private Sub CopyRange(ByRef fromSheet As HSSFSheet, ByRef toSheet As HSSFSheet, ByVal fromRowIndex As Integer, ByVal fromColIndex As Integer, ByVal toRowIndex As Integer, ByVal toColIndex As Integer, ByVal onlyData As Boolean, ByVal copyComment As Boolean)
Dim sourceRow As HSSFRow = fromSheet.GetRow(fromRowIndex)
Dim sourceCell As HSSFCell = sourceRow.GetCell(fromColIndex)
If (Not sourceRow Is Nothing) And (Not sourceCell Is Nothing) Then
Dim changingRow As HSSFRow = Nothing
Dim changingCell As HSSFCell = Nothing
changingRow = toSheet.GetRow(toRowIndex)
If (changingRow Is Nothing) Then
changingRow = toSheet.CreateRow(toRowIndex)
End If
changingCell = changingRow.GetCell(toColIndex)
If (changingCell Is Nothing) Then
changingCell = changingRow.CreateCell(toColIndex, sourceCell.CellType)
End If
If (onlyData) Then '仅数据
'对单元格的值赋值
If sourceCell.CellType = CellType.STRING Then
changingCell.SetCellType(CellType.STRING)
changingCell.SetCellValue(sourceCell.RichStringCellValue)
End If
changingCell.SetCellValue(sourceCell.ToString())
Else '非仅数据
'单元格的编码
changingCell.Encoding = sourceCell.Encoding
'单元格的格式
changingCell.CellStyle = sourceCell.CellStyle
'单元格的公式
changingCell.SetCellType(sourceCell.CellType)
changingCell.SetCellValue(sourceCell.ToString())
'对单元格的批注赋值
If Not sourceCell.CellComment Is Nothing Then
Dim patr As HSSFPatriarch
Try
patr = toSheet.DrawingPatriarch
Catch ex As Exception
patr = CType(toSheet.CreateDrawingPatriarch(), HSSFPatriarch)
End Try
Dim tempCellCommentColumn As Integer = sourceCell.CellComment.Column + toColIndex - fromColIndex
Dim tempCellCommentRow As Integer = sourceCell.CellComment.Row + toRowIndex - fromRowIndex
Dim comment1 As HSSFComment = CType(patr.CreateCellComment(New HSSFClientAnchor(0, 0, 0, 0, tempCellCommentColumn, tempCellCommentRow, tempCellCommentColumn + 2, tempCellCommentRow + 2)), HSSFComment)
comment1.String = sourceCell.CellComment.String
comment1.Author = sourceCell.CellComment.Author
changingCell.CellComment = comment1
End If
'changingCell.CellComment = sourceCell.CellComment
End If
End If
End Sub
- NPOI 将一个sheet指定区域复制到另一个sheet,复制数据,样式和备注
- NPOI跨Sheet复制(含格式、字体、合并区域)
- NPOI中如何复制Sheet
- NPOI 复制Sheet(转载)
- Delphi操作EXCEL复制Sheet到另一个XLS文件中
- 复制sheet
- 复制sheet和写xls
- POI 复制excel一行到另外一个sheet页(修改)
- 将数据从一个表复制到另一个表
- 将一个列表的数据复制到另一个列表中。
- 关于select和insert,将一个表中的部分数据复制到另一个表中
- 将一个字符串复制到另一个字符串
- excel sheet中数据的快速复制
- excel sheet的 某列(m*n行) 快速复制到 m行n列区域
- Excel中Sheet复制
- python excel sheet复制
- PHPExcel sheet复制
- 导出数据到Excel 2003 单个Sheet页(NPOI)
- myeclipse10 Cannot return from outside a function or method
- MySql数据库乱码解决方案
- Hadoop学习过程遇到的问题总结
- 网络基本功(三):细说VLAN与Trunk
- pdflatex, xelatex, xetex和miktex等的区别和关系
- NPOI 将一个sheet指定区域复制到另一个sheet,复制数据,样式和备注
- RESTful Web Services Part 5 - Relevant Concepts
- MySQL优化之表索引、视图、内置函数、预处理、事务处理、存储、触发器
- svm-struct使用指南(原版翻译)
- RESTful Web Services Part 6 - Maturity Model
- 一个例子明白抛出与捕获异常
- Qt-下拉列表框QComboBox类
- storm的并发
- @Transactional spring 配置事务 注意事项