Free Support Forum - aspose.com

Request : Access the Workbook.Styles collection from Worksheet object

Hi,

I’d like to request an access to the Workbook.Styles collection from the Worksheet object. It would facilitate working with styles when each worksheet is created by many different functions, or even classes…

Let’s say I have something alongside the following code :
private void GenerateWorkbook() {
Aspose.Cells.Workbook book = new Aspose.Cells.Workbook();
Aspose.Cells.Worksheet sheet

DefineStyles(book);

for (int i=0; i<10; i++) {
sheet = book.Worksheets[book.Worksheets.Add()];

GenerateHeader(sheet);
GenerateMainBody(sheet, i);
GenerateFooter(sheet);
}
}

Accessing the defined styles from the GenerateX() functions is frustating… You have to pass the whole Workbook as a parameter or use a membre attribute for the workbook only to be able to assign a style to some cell…

Providing an access to the Styles collections from the Worksheet object would help write “cleaner” code in my opinion…

Alternatively, you could provide an access to the parent workbook from the worksheet object, that could work too…

Thanks for considering this,

Dominic.

Hi Dominic,

We will check the feasibility of your suggestion and reply you soon.

Thank you.

Hi Dominic,

Please add a param Workbook to your method.Such as :GenerateMainBody(workbook,sheet, i);

Thanks for the reply, but it’s little off the point as I’m suggesting adding an access to the Styles collection from the worksheet object especially NOT to have to pass the workbook as a parameter (see original post).

I’m not asking for a way to make it work, I got that already, I’m only providing some customer insight to help you make things even better with Aspose.Cells, that is all…

It’s more conceptual than technical…

Cheers,

Dominic.

Dear Dominic,

Thanks for you suggestion.

However, Styles collection is for Workbook range, not for a separate Worksheet. So to avoid confusion, we think it's better to keep our current design.

Granted.

And for the other alternative from the original post ?

"Alternatively, you could provide an access to the parent workbook from the worksheet object, that could work too… "

Dominic.

Hi Dominic,

Thanks for your advice.

Please try this fix. You can use worksheet.Workbook property to access Workbook object.

Great, thanks a lot.