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;
                            }
                        }
                    }
                }
            }


  • 相关阅读:
    4.10Python数据处理篇之Matplotlib系列(十)---文本的显示
    4.9Python数据处理篇之Matplotlib系列(九)---子图分布
    4.8Python数据处理篇之Matplotlib系列(八)---Figure的学习
    4.7Python数据处理篇之Matplotlib系列(七)---matplotlib原理分析
    4.6Python数据处理篇之Matplotlib系列(六)---plt.hist()与plt.hist2d()直方图
    4.5Python数据处理篇之Matplotlib系列(五)---plt.pie()饼状图
    4.4Python数据处理篇之Matplotlib系列(四)---plt.bar()与plt.barh条形图
    4.3Python数据处理篇之Matplotlib系列(三)---plt.plot()折线图
    Angular 定时器$timeout和$interval,延时调用
    javascript中top、clientTop、scrollTop、offsetTop的讲解(转载加总结)
  • 原文地址:https://www.cnblogs.com/oliver_zh/p/1796002.html
Copyright © 2011-2022 走看看