zoukankan      html  css  js  c++  java
  • 使用C#和Excel进行报表开发(6)

    内容摘要:在Excel中,行和列实际上仍然是Range,只不过取得行和列的方法和前面几篇随笔出现的有点不同,要使用Worksheet的Rows和Columns属性的get_Item方法,下面是例子代码,演示了怎样选中行,并且在行之间复制数据。

      在Excel中,行和列实际上仍然是Range,只不过取得行和列的方法和前面几篇随笔出现的有点不同,要使用Worksheet的Rows和Columns属性的get_Item方法,下面是例子代码,演示了怎样选中行,并且在行之间复制数据,和插入行:

      ThisApplication = new Excel.Application();  ThisWorkbook = ThisApplication.Workbooks.Open("z:Book1.xls", Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);  ThisApplication.DisplayAlerts = false;
      xlSheet = (Excel.Worksheet)ThisWorkbook.Worksheets.get_Item(1);
      //Excel.Range range = xlSheet.get_Range("G4",Type.Missing);
      Excel.Range range = (Excel.Range)xlSheet.Rows.get_Item(18, Type.Missing);
      Excel.Range range1 = (Excel.Range)xlSheet.Rows.get_Item(19, Type.Missing);
      range.Value = "123";
      range.Copy(range1);
      range1.Rows.Insert(XlInsertShiftDirection.xlShiftDown);
      ThisWorkbook.SaveAs("z:Book2.xls", Type.Missing, Type.Missing,
      Type.Missing, Type.Missing, Type.Missing, Excel.XlSaveAsAccessMode.xlNoChange,
      Type.Missing, Type.Missing, Type.Missing, Type.Missing);

      关于Excel进程的释放,前面几篇随笔已经有了,这里就不再重复了。

    作者:wpf之家
    本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
  • 相关阅读:
    程序活动记录&程序调试&多线程编程
    数据结构与算法
    C/C++
    Information Retrieval --- Retrieval Comment
    Information Retrieval --- Clustering
    Information Retrieval --- Classification
    Information Retrieval --- Web Search
    Information Retrieval --- Retrieval Enforce:Relevance Feedback & Query Expansion
    Information Retrieval --- Retrieval Model
    ubuntu server 安装vnc
  • 原文地址:https://www.cnblogs.com/wpf123/p/2347390.html
Copyright © 2011-2022 走看看