• Npoi复制行


     private void CopyRange(HSSFWorkbook myHSSFWorkBook, int fromRowIndex, int fromColIndex, int toRowIndex, int toColIndex, bool onlyData, bool copyComment)
            {
                HSSFRow sourceRow 
    = myHSSFWorkBook.GetSheetAt(myHSSFWorkBook.ActiveSheetIndex).GetRow(fromRowIndex);
                HSSFCell sourceCell 
    = sourceRow.GetCell(fromColIndex);
                
    if (sourceRow != null && sourceCell != null)
                {
                    HSSFRow changingRow 
    = null;
                    HSSFCell changingCell 
    = null;
                    changingRow 
    = myHSSFWorkBook.GetSheetAt(myHSSFWorkBook.ActiveSheetIndex).GetRow(toRowIndex);
                    
    if (changingRow == null)
                        changingRow 
    = myHSSFWorkBook.GetSheetAt(myHSSFWorkBook.ActiveSheetIndex).CreateRow(toRowIndex);
                    changingCell 
    = changingRow.GetCell(toColIndex);
                    
    if (changingCell == null)
                        changingCell 
    = changingRow.CreateCell(toColIndex);

                    
    if (onlyData)//仅数据
                    {
                        
    //对单元格的值赋值
                        changingCell.SetCellValue(sourceCell.StringCellValue);
                    }
                    
    else         //非仅数据
                    {
                        
    //单元格的编码
                        changingCell.Encoding = sourceCell.Encoding;
                        
    //单元格的格式
                        changingCell.CellStyle = sourceCell.CellStyle;
                        
    //单元格的公式
                        if (sourceCell.CellFormula == "")
                            changingCell.SetCellValue(sourceCell.StringCellValue);
                        
    else
                            changingCell.SetCellFormula(sourceCell.CellFormula);
                        
    //对单元格的批注赋值
                        if (copyComment)
                        {
                            
    if (sourceCell.CellComment != null)
                            {
                                HSSFPatriarch patr 
    = myHSSFWorkBook.GetSheetAt(myHSSFWorkBook.ActiveSheetIndex).CreateDrawingPatriarch();
                                HSSFComment comment 
    = patr.CreateComment(new HSSFClientAnchor(0000, toColIndex, toRowIndex, toColIndex + 1, toRowIndex + 1));

                                comment.String 
    = new HSSFRichTextString(sourceCell.CellComment.String.ToString());
                                comment.Author 
    = sourceCell.CellComment.Author;

                                changingCell.CellComment 
    = comment;
                            }
                        }
                    }
                }
            }


  • 相关阅读:
    SpringBoot 之基础学习篇.
    Java 反射机制
    第二十二节,TensorFlow中的图片分类模型库slim的使用、数据集处理
    第二十一节,条件变分自编码
    第二十节,变分自编码
    第十九节,去噪自编码和栈式自编码
    使用webdriver+urllib爬取网页数据(模拟登陆,过验证码)
    第十八节,自编码网络介绍及代码实现
    第十七节,受限玻尔兹曼机网络及代码实现
    第二十二节,TensorFlow中RNN实现一些其它知识补充
  • 原文地址:https://www.cnblogs.com/oliver_zh/p/1796002.html
Copyright © 2020-2023  润新知