We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Format many columns at once

I currently have a sheet that I need to format many columns. The columns are not always next to each other. Is it possible to accomplish without adding the style one column at a time? I was thinking of something like CreateRange("L:L,P:P,R:R,AA:AA") to create this range then I would apply the style for these four columns. Also I noticed a RangeCollection class, do I need to use that? I looked at the examples but I could not find a way to utilize the RangeCollection class to get this done.

Thanks.

Hi,


I think you may try to use NameCollection and create Name object to specify your desired ranges for your requirements. I have written a sample code for your reference, please refer to it and accomplish your tasks accordingly:

Sample code:
Workbook workbook = new Workbook();
Worksheet sheet = workbook.Worksheets[0];

Cells cells = sheet.Cells;

NameCollection names = workbook.Worksheets.Names;
Name name = names[names.Add(“Myrange1”)];
name.RefersTo = “=Sheet1!$A:$A, Sheet1!$C:$C”;
Style style = workbook.Styles[workbook.Styles.Add()];
style.ForegroundColor = Color.Yellow;
style.Pattern = BackgroundType.Solid;
StyleFlag flag = new StyleFlag();
flag.CellShading = true;

Range[] rngs = name.GetRanges();
MessageBox.Show(rngs.Length.ToString());
if (rngs != null)
{

for (int i = 0; i < rngs.Length; i++)
{
rngs[i].ApplyStyle(style, flag);
}
}

workbook.Save(“e:\test2\ranges_style_book.xls”);


Thank you.

Thanks. That worked perfect.

Hi,


Good to know that it works for you.

Feel free to contact us any time if you need further help or have some other issue, we will be happy to assist you soon.

Thank you.