Rename Excel Sheet and Set Tab Color

An Excel file may contain dozens of sheets. Sometimes people need to rename sheets in order to make clear of the special sheets. While sometimes, setting the tab color seems to be another good way. This section will introduce a solution to rename sheet and set tab color in Excel via a .NET Excel component with C#, VB.NET.

Spire.XLS for .NET which offers a combination of APIs and GUl controls enables you to fast create and handle Excel files in .NET applications. Using this .NET Excel component, you can rename sheet and set tab color in Excel with a very simple way. After loading the Excel file from system and specify which sheets you want to name, you can rename these sheets by assigning a name string: Worksheet.Name and set the tab color by Worksheet.TabColor. Please view the effect of the whole project as below picture:

Rename Excel Sheet

Here you can download Spire.XLS for .NET and install it on your system. After adding Spire.Xls dll, you can start this task through below code.

Rename Sheet and Set Tab Color in Excel with C#, VB.NET

[C#]
using Spire.Xls;

namespace changeename
{
    class Program
    {
        static void Main(string[] args)
        {
            //create Excel worksheet
            Workbook workbook = new Workbook();
            workbook.LoadFromFile(@"D:\michelle\my file\Excel Font.xlsx");
            Worksheet worksheet = workbook.Worksheets[0];
            Worksheet worksheet1 = workbook.Worksheets[1];
            Worksheet worksheet2 = workbook.Worksheets[2];

           //change sheet name
            worksheet.Name = "Rename sheet1";
            worksheet1.Name = "Rename sheet2";
            worksheet2.Name = "Rename sheet3";
            //set tab color
            worksheet.TabColor = Color.DarkGreen;
            worksheet1.TabColor = Color.Red;
            worksheet2.TabColor = Color.Gold;
            //save to file
            workbook.SaveToFile("Reanme.xlsx");
            System.Diagnostics.Process.Start(workbook.FileName);
        }
    }
}

[VB.NET]
Imports Spire.Xls

Namespace changeename
	Class Program
		Private Shared Sub Main(args As String())
			'create Excel worksheet
			Dim workbook As New Workbook()
			workbook.LoadFromFile("D:\michelle\my file\Excel Font.xlsx")
			Dim worksheet As Worksheet = workbook.Worksheets(0)
			Dim worksheet1 As Worksheet = workbook.Worksheets(1)
			Dim worksheet2 As Worksheet = workbook.Worksheets(2)

			'change sheet name
			worksheet.Name = "Rename sheet1"
			worksheet1.Name = "Rename sheet2"
			worksheet2.Name = "Rename sheet3"
			'set tab color
			worksheet.TabColor = Color.DarkGreen
			worksheet1.TabColor = Color.Red
			worksheet2.TabColor = Color.Gold
			'save to file
			workbook.SaveToFile("Reanme.xlsx")
			System.Diagnostics.Process.Start(workbook.FileName)
		End Sub
	End Class
End Namespace