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

Free Support Forum - aspose.com

Styles

Received : 2008/01/02 15:31:43

I have been previewing your product and I seem to have run into a bit of a snag. What I have done is selected the range of my document and applied a style so I can set my default Font.Name and Font.Size. Then, I try to set the first cell's Font to italic ( sheet.Cells[0,0].Style.Font.IsItalic = true ), but the entire document seems to have it's font set to italics then. Shouldn't I be able to modify a single property of a style for a single cell? Thanks in advance.

Levi


This message was posted using Aspose.Live 2 Forum

Hi Levi,

Could you please post your sample code to show your problem?

And you can try:

sheet.Cells[0,0].Style = null;

sheet.Cells[0,0].Style.Copy(defaultStyle);

sheet.Cells[0,0].Style.Font.IsItalic = true;

I don’t have the exact code in front of me, but I was doing something along the lines of:

using Excel = Aspose.Cells;

//Define the font face and borders for a cell range
Excel.Range rng = sheet.Cells.CreateRange(“A1”,“D11”);

Excel.Style style = book.Styles[book.Styles.Add()];

style.Font.Name = “Calibri”;

style.Borders.SetStyle(Aspose.Cells.CellBorderType.Thin);

style.Borders.DiagonalStyle = Aspose.Cells.CellBorderType.None;

rng.Style = style;

/** This sets the style of my entire range above to be italic **/
sheet.Cells[0,0].Style.Font.IsItalic = true;

So, what you’re proposing is that I do something like this?

sheet.Cells[0,0].Style.Copy(style);
sheet.Cells[0,0].Style.Font.IsItalic = true;

Internally, is there a mapping to a Style in the Styles collection and that’s it? If the second option is what you are suggesting (using the Copy method), should it be the default behavior that when you reference a Cell’s Style property that it do an implicit copy of itself? Additionally, if I then wanted to do something like this:

Excel.Range rngColOne = sheet.Cells.CreateRange(“A1”,“A11”);
rngColOne.Style.Font.IsItalic = true;

I would just expect that for only that range the IsItalic property would be set to true while retaining the other properties of the previous Style that it had. Anyway, sorry for being wordy, I am just having a hard time figuring out why changing a Style of an individual cell would change the rest of the cells that had the same Style. Thanks for the response!


Hi,

Thanks for considering Aspose.

You may try the following sample code (suggested by Laurence), here the A1 cell will have additional italic attribute and all other cells in A1:D11 range will retain its previous attributes.

using Excel = Aspose.Cells;

//Define the font face and borders for a cell range
Excel.Range rng = sheet.Cells.CreateRange("A1","D11");
Excel.Style style = book.Styles[book.Styles.Add()];
style.Font.Name = "Calibri";
style.Borders.SetStyle(Aspose.Cells.CellBorderType.Thin);
style.Borders.DiagonalStyle = Aspose.Cells.CellBorderType.None;
rng.Style = style;

sheet.Cells[0,0].Style = null;

sheet.Cells[0,0].Style.Copy(workbook.DefaultStyle);
sheet.Cells[0,0].Style.Font.IsItalic = true;

Thank you.