What is the function of background color in Excel?
First of all, let us look at the following two pictures:
First of all, let us look at the following two pictures:
Obviously, picture1.2 is clear at a glance compared with picture 1.1. Yes, you are absolutely right. Making the information distinctive is one function of background color in Excel. Furthermore, people can use background color to classify some sort of value or category for the convenience of observing. Thus, Excel background color is very useful to design data information. For common people, it is just a piece of cake to set the background color manually. But for those programmers, setting Excel background color is not that easy. So this text mainly introduces you how to set background color in Excel with C#, VB.NET.
How to set Excel background color with C#, VB.NET?
Spire.XLS, as an Excel component, enables developers to use C#, VB.NET to set background color in a rapid speed. Before you start, please make sure that Spire.XLS and Visual Studio are installed in your computer. If you have no Spire.XLS, please freely download it here.
Follow the below simple steps to set Excel background color:
Spire.XLS, as an Excel component, enables developers to use C#, VB.NET to set background color in a rapid speed. Before you start, please make sure that Spire.XLS and Visual Studio are installed in your computer. If you have no Spire.XLS, please freely download it here.
Follow the below simple steps to set Excel background color:
Steps
1. Create Background Color in Visual Studio, then, add Spire. XLS dll and System.Drawing as references.
2. Load Excel file which we need set cell background color. Use the following code to load the Excel file from local PC.
C# Code:
Workbook workbook = new Workbook();
workbook.LoadFromFile(@"..\..\..\..\Data\country.xls",ExcelVersion.Version97to2003);
Worksheet worksheet = workbook.Worksheets[0];
1. Create Background Color in Visual Studio, then, add Spire. XLS dll and System.Drawing as references.
2. Load Excel file which we need set cell background color. Use the following code to load the Excel file from local PC.
C# Code:
Workbook workbook = new Workbook();
workbook.LoadFromFile(@"..\..\..\..\Data\country.xls",ExcelVersion.Version97to2003);
Worksheet worksheet = workbook.Worksheets[0];
VB.NET Code:
Dim workbook As New Workbook()
workbook.LoadFromFile("..\..\..\..\Data\country.xls",ExcelVersion.Version97to2003)
Dim worksheet As Worksheet = workbook.Worksheets(0)
3.Set Excel Background Color. By using Spire.XLS, developers/programmers can choose any cells even area to add background color. The code below shows how to set Excel cell background code on 2 different areas.
C# Code:
//set the backgroundcolor=LightBlue of Range["A2:E9"]
worksheet.Range["A2:E9"].Style.Color = Color.LightBlue;
//set the backgroundcolor=Silver of Range["A11:E18"]
worksheet.Range["A11:E18"].Style.Color = Color.Silver;
VB.NET Code:
'set the backgroundcolor=LightBlue of Range["A2:E9"]
worksheet.Range("A2:E9").Style.Color = Color.LightBlue
'set the backgroundcolor=Silver of Range["A11:E18"]
worksheet.Range("A11:E18").Style.Color = Color.Silver
4. Save and Preview. Use the following code to save and preview.
C# Code:
workbook.SaveToFile("sample.xls", ExcelVersion.Version97to2003);
System.Diagnostics.Process.Start(workbook.FileName);
VB.NET Code:
workbook.SaveToFile("sample.xls", ExcelVersion.Version97to2003)
System.Diagnostics.Process.Start(workbook.FileName)
Click to Full Demo
Effective Screenshot
workbook.SaveToFile("sample.xls", ExcelVersion.Version97to2003)
System.Diagnostics.Process.Start(workbook.FileName)
Click to Full Demo
Effective Screenshot
More About Spire. XLS
Spire. XLS, as a professional Excel component, allows its users to operate Excel document directly such as save to stream, save as web response, copy, lock/unlock worksheet, set up workbook properties, etc. Click to learn more…
RSS Feed