XlsIO creates more than one sheet.

I am making a program that reads data and writes results in a workbook (.xlsx) made with XlsIO. I need that book with only a sheet. When I write these sentences:

                IWorkbook workbook = application.Workbooks.Create(1);

                IWorksheet worksheet = workbook.Worksheets.Create("NAME_OF_THE_SHEET");

The book is created, but one additional sheet appears before the sheet named  "NAME_OF_THE_SHEET".

How can I correct this issue? Thanks for your answer.


6 Replies

MM Mugil Murugan Syncfusion Team May 7, 2024 01:09 PM UTC

Hi,


//Here the first worksheet is created

IWorkbook workbook = application.Workbooks.Create(1);

//Here the second worksheet  is created

IWorksheet worksheet = workbook.Worksheets.Create("NAME_OF_THE_SHEET");

Because of this, two worksheets have been created, we suggest to use the below mentioned code

for creating a single worksheet.


Code Snippet:

IWorkbook workbook = application.Workbooks.Create(1);


Regards,

Mugil M.



CC Carlos Castillo May 7, 2024 03:39 PM UTC

Thanks Mugil for your answer.


I understood that. But, how can I name a worksheet after it has been created? Is it possible?


Best regards,



CARLOS CASTILLO



CC Carlos Castillo May 7, 2024 06:31 PM UTC

I try to create a book with only one sheet using these instructions:


                IWorkbook workbook = application.Workbooks.Create();

                IWorksheet worksheet = workbook.Worksheets.Create("NAME_OF _THE_SHEET");


But, now XlsIO creates 3 empty sheets before sheet named "NAME_OF_THE_SHEET".


I need a book with one named sheet. How can I do that?


Thanks in advance



MM Mugil Murugan Syncfusion Team May 8, 2024 06:01 AM UTC

Hi Carlos,

 

You can use the IWorksheet.Name property to set the name for the worksheet.

 

//Access the first worksheet

IWorksheet worksheet = workbook.Worksheets[0];

 

//Get or set the name  of the sheet

worksheet.Name = "NAME_OF_THE_SHEET";

 

Please refer to the UG for more information about working with excel worksheet.

 

 

Regards,

Mugil M.



CC Carlos Castillo May 8, 2024 06:54 PM UTC

Thanks Mugil for your answer, but it does not work.

Using the instructions, the sheet named "NAME_OF_THE_SHEET" is created, and 2 empty sheets after the sheet with the name are added.

The version of XlsIO that I am using is 25.1.41.

Thanks for your answer.




CARLOS CASTILLO



CC Carlos Castillo May 8, 2024 07:56 PM UTC

After some tests, the right instructions to make a book with a need sheet are as follows:


IWorkbook workbook = application.Workbooks.Create(1);

IWorksheet worksheet = workbook.Worksheets[0];

worksheet.Name = "NAME_OF_THE_SHEET";


That's all. Thanks for your help.


CARLOS CASTILLO


Loader.
Up arrow icon