通过C#创建Excel工作簿后,我只想添加一张工作表

问题描述:

代码是这个

        Excel.Application appC = new Excel.Application();  
        appC.Visible = true;              
        Excel.Workbook bookC = appC.Workbooks.Add(1);  
        Excel.Worksheet sheetC = bookC.Worksheets.Add();  
        sheetC.Name = "something";

命令Workbook.Add()使用一个参数,该参数应确定将在工作簿中创建多少张纸...对吗?

The command Workbook.Add() takes one parameter that is supposed to determine how many sheets will be created in the workbook... right?

那我为什么要得到2张纸...一张叫东西",另一张叫表2"? 我究竟做错了什么??

So why do I get 2 sheets... one named "something" and one named "sheet 2"? What am I doing wrong??

这是创建Excel应用程序对象并打开仅包含一个工作表并根据需要命名的工作簿的代码:

This is the code to create an Excel application object and open a workbook with only ONE sheet and name it as you wish:

Excel.Application appC = new Excel.Application();    
appC.SheetsInNewWorkbook = 1;       
appC.Visible = true;     
Excel.Workbook bookC = appC.Workbooks.Add();    
Excel.Worksheet sheetC = appC.Sheets.get_Item(1);   
sheetC.Name = "name-of-sheet";