How to make background color to RED of entire sheet

Hi ,

I am using Aspose.Cells version 4.4.0.0.

I want to make the background color of whole sheet to Red by using single statement.

I know we can use sheet.cells.Createrange function for applying 65000 rows and 256 columns.

but this is taking time while executing.

So , Please can anyone Suggest any statement or Provide C# code for applying range to entire sheet.

Please its urgent...

Thanks,

Hi,


Thank you for using Aspose.Cells.

You can apply style to a whole worksheet somewhat like this:

Aspose.Cells.Style style = new Aspose.Cells.Style();

style.
ForegroundColor = Color.Red;

style.Pattern = BackgroundType.Solid;

StyleFlag sf = new StyleFlag();

sf.All = true;

Cells cells = worksheet.Cells;

cells.ApplyStyle(style, sf);

Hi,

Thanks for your posting and using Aspose.Cells for .NET.

You can color the entire worksheet by applying the Style object to all cells of worksheet using worksheet.Cells.ApplyStyle() method.

Please see the code below, it set the fill color to red of entire worksheet.

I have also attached the output xlsx file generated by the code and screenshot for your reference.

C#

Workbook workbook = new Workbook();

Worksheet worksheet = workbook.Worksheets[0];

Cell cellA1 = worksheet.Cells["A1"];

Style st = cellA1.GetStyle();

st.Pattern = BackgroundType.Solid;
st.ForegroundColor = Color.Red;

worksheet.Cells.ApplyStyle(st, new StyleFlag() { All = true });

workbook.Save("output.xlsx");

Screenshot:

Hi,


Following is the simplest code that works absolutely fine with our latest version v7.3.0 and that might work with your older version ( I am not sure though, you may try to adjust the code accordingly):

Sample code:

Workbook workbook = new Workbook();
Style style = workbook.Styles[workbook.Styles.Add()];
style.ForegroundColor = Color.Red;
style.Pattern = BackgroundType.Solid;
StyleFlag flag = new StyleFlag();
flag.CellShading = true;
Worksheet sheet = workbook.Worksheets[0];

sheet.Cells.ApplyStyle(style, flag);
workbook.Save(“e:\test2\backgroundcolor.xls”);

If there is no relevant APIs in your older version v4.4.0, then I am afraid you have to either use/stick to your existing approach or upgrade to latest versions.

Thank you.

Thanks for your post.

But I did not find cells.ApplyStyle(style, sf); With my Aspose.Cells 4.4.0.0 Version.

So, Please suggest any other solution for this.

Thanks,

Hi,

I am afraid, you need to upgrade or if that is not possible, then please try the workaround as suggested by Amjad in the above post: 397651

If the above code still does not work, then you will have to set the fill color iteratively as you are doing it before.

Let us know if you have any other question, we will be glad to help you.