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. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to set background color for a entire worksheet ?

This article explains how to set background color for entire worksheet in XlsIO using C#/VB.NET.

How to set background color for entire worksheet?

To set background color for entire worksheet, we need to create a style in workbook and apply it to the entire worksheet.

The following methods in XlsIO is used to set default styles for row or column in a worksheet.

S.No

Method

Usage

1

void SetDefaultColumnStyle(int iColumnIndex, IStyle defaultStyle);

Sets the default style for the specified column.

2

void SetDefaultColumnStyle(int iStartColumnIndex, int iEndColumnIndex, IStyle defaultStyle);

Sets the default style for the columns between the start and end index specified.

3

void SetDefaultRowStyle(int iRowIndex, IStyle defaultStyle);

Sets the default style for the specified row.

4

void SetDefaultRowStyle(int iStartRowIndex, int iEndRowIndex, IStyle defaultStyle);

Sets the default style for the rows between the start and end index specified.

 

Note: When applying the styles for the entire worksheet, it is preferable to use SetDefaultColumnStyle(int iStartColumnIndex, int iEndColumnIndex, IStyle defaultStyle). Because the SetDefaultRowStyle(int iStartRowIndex, int iEndRowIndex, IStyle defaultStyle) will cause performance issue as the number of rows in higher than the number columns.

Steps to set color for the entire worksheet

  1. Set workbook version for the workbook. Because, here we use maximum number columns which will be different based on the workbook version.

 

 

  1. Create a new style and add it to the styles in the workbook.

 

  1. Set background color for the new style.

 

  1. Apply the style to the worksheet using IWorksheet.SetDefaultColumnStyle(Int iStartColumnIndex,iEndColumnIndex,IStyle defaultStyle) method. Here, startIndex is 1 and the endIndex is the maximum number column in the worksheet.

 

To know more about sheet or range formatting in XlsIO, please refer the documentation.

Download complete sample

The following C#/VB.NET complete code snippet shows how to set color for entire worksheet in XlsIO.

 

 

The following screenshot shows the output generated by XlsIO after applying color for entire worksheet.

Article ID: Published Date: Last Revised Date: Platform: Control:
8537 02/28/2018 02/28/2018 WinForms XlsIO
Did you find this information helpful?
Add Comment
You must log in to leave a comment

Please sign in to access our KB

or the page will be automatically redirected to sign-in page in 10 seconds.

Warning Icon 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.Close Icon