zoukankan      html  css  js  c++  java
  • 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;
                            }
                        }
                    }
                }
            }


  • 相关阅读:
    PHP面向对象——类
    PHP强大的数组函数
    php学习资源
    版本管理(二)之Git和GitHub的连接和使用
    版本管理(一)之Git和GitHub的区别(优点和缺点)
    (win10)Wamp环境下php升级至PHP7.2
    wamp3.1.0 X64下载链接
    4.总结近5周以来的github上的工作情况,以图表方式分析你小组的工作情况、存在的问题及解决的方案。(尤心心)
    四则运算需求分析和功能实现--杨宇杰
    1.对四则运算软件需求的获取方式进行实践,例如使用调查问卷访问相关关系人等。
  • 原文地址:https://www.cnblogs.com/oliver_zh/p/1796002.html
Copyright © 2011-2022 走看看