zoukankan      html  css  js  c++  java
  • C#添加多个Sheet表

    using System;
    using System.Reflection;
    using Microsoft.Office.Interop.Excel;


    namespace Customize.Common
    {
        /// <summary>
        /// Class1 的摘要说明
        /// </summary>
        public class ExcelHelper
        {
            public ExcelHelper()
            {
                //
                // TODO: 在此处添加构造函数逻辑
                //
            }

        /// <summary>
            /// 添加多个Excel的Sheet
            /// 使用此方法应该注意:在web.config文件的<system.web>中加入<identity impersonate="true" userName="njsz.com\huangfei.yu" password="yhfm,./"/>
            /// 添加dll的引用 和 using System.Reflection; 的引用
            /// </summary>
            /// <returns></returns>
            public static string MakeMoreSheet()
            {
                string results = string.Empty;
                //const int nCells = 5;
                Application app = new Application();
                if (app == null)
                {
                    results = "FileNotExists";
                }

                app.Visible = true;
                //Getting the workbooks collection
                Workbooks workbooks = app.Workbooks;
               

                //Adding a new workbook The following line is the temporary workaround for the LCID problem
                _Workbook workbook = workbooks.Add(XlWBATemplate.xlWBATWorksheet);//添加一个Sheet表
                //Getting the worksheets collection 得到sheet的集合
                Sheets sheets = workbook.Worksheets;
                _Worksheet worksheet1 = (_Worksheet)sheets.Add(Missing.Value, Missing.Value, Missing.Value, Missing.Value);//添加第二个sheet

                //_Worksheet worksheet = (_Worksheet)sheets.get_Item(1);
                // This paragraph puts the value 5 to the cell G1
                //Range range1 = worksheet.get_Range("G1", Missing.Value);           
                //range1.Value2 = nCells;

                //_Worksheet worksheet2 = (_Worksheet)sheets.Add(Missing.Value, Missing.Value, Missing.Value, Missing.Value); //
                //_Workbook workbook1 = workbooks.Add(XlWBATemplate.xlWBATWorksheet);
                //Sheets sheets2 = workbook.Worksheets;

                //_Worksheet worksheet2 = (_Worksheet)sheets.get_Item(2);
                // This paragraph puts the value 5 to the cell G1
                //Range range2 = worksheet2.get_Range("G2", Missing.Value);
                //range2.Value2 = nCells;
                return results;
            }

    }

  • 相关阅读:
    selenium 8大元素定位方法
    selenium环境安装及简单使用
    Python json序列化和反序列化
    pytest使用allure生成测试报告
    Windows10下JDK15的安装教程
    Ansible:服务器巡检_3、Windows 平台巡检
    转载:shell中各种括号的作用详解()、(())、[]、[[]]、{}(推荐)
    Tips: Linux 中 当形参名称是 变量时,如何取出全部的实参
    Python 问题记录:XXX.whl is not a supported wheel on this platform.
    Ansible:服务器巡检_2、Linux 服务器巡检脚本
  • 原文地址:https://www.cnblogs.com/bicabo/p/1753092.html
Copyright © 2011-2022 走看看