We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.

xlsio worksheet (tab) name

Thread ID:

Created:

Updated:

Platform:

Replies:

117295 Sep 24,2014 04:16 PM Oct 6,2016 08:39 AM ASP.NET MVC (Classic) 3
loading
Tags: XlsIO
Mike Smith
Asked On September 24, 2014 04:16 PM

I am trying to get the name of an existing worksheet (Sheet1, Sheet2, etc) using the following statements. However, GetSheetNameByReference is an internal protected method so the following does not work.

 IWorkbook workbook = application.Workbooks.Open(d.ResolveApplicationDataPath(@"Products_09172014.xlsx"),
                ExcelOpenType.Automatic);

var x = ((WorkbookImpl)workbook).GetSheetNameByReference(0);

Is there another technique to get the sheet name besides trying to use GetSheetNameByReference in this way ?



Sudha Ramachandran [Syncfusion]
Replied On September 25, 2014 02:04 AM

Hi Mike,

Thank you for using Syncfusion products.

Name of the worksheets can be accessed by accessing the worksheets or tabsheets collection as referred in the below code snippet.

Code Snippet:

 

//Access worksheet name using index of the worksheet

string sheetName = workbook.Worksheets[0].Name;

 

//Access worksheet name using tab sheet index

string worksheetName = ((IWorksheet)workbook.TabSheets[0]).Name;

 

Please let us know if you need any clarification.

 

Regards,

Sudha R


Catalin Pop
Replied On October 5, 2016 12:25 PM

worksheet.Name = "New Name";                
var newworksheet = workbook.Worksheets.AddCopy(worksheet);
workbook.TabSheets[newworksheet .TabIndex].Name = worksheet.Name;

I'm having a similar problem. I try to change the name of the worksheet but when I save the workbook and open it with Office the names are Sheet2 Sheet3 and so on.

Abirami Varadharajan [Syncfusion]
Replied On October 6, 2016 08:39 AM

Hi Catalin, 

Thank you for contacting Syncfusion support. 

We are unable to reproduce the issue. As you are trying to set same name(New Name) for copied sheet as source worksheet name, the exception is thrown indicates “Name of worksheet must be unique in a workbook.” As per MSExcel behavior. We request you to set different name for copied worksheet as provided below to avoid this exception. 

Code Example: 
            worksheet.Name = "New Name"; 
            worksheet.Range["A1"].Text = "SourceWorksheet"; 
            var newworksheet = workbook.Worksheets.AddCopy(worksheet); 
            workbook.TabSheets[newworksheet.TabIndex].Name = "CopiedWorksheet"; 

We have also shared sample for your reference which can be downloaded from following location. 
 

Regards, 
Abirami. 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;