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

Free Support Forum - aspose.com

Workbook.DefaultStyle bug?

When I open a new Excel workbook, the look is shown as this picture.

I press "Ctrl+A" and change the font size to 30, and the look is shown as this picture.

I try to reproduce this behavior with Aspose Cells. The source code is shown below.

My first question is that the "attempt 1" line does not work. The look is shown as this picture. I wonder whether this is bug ?

My second question is that the "attempt 2" block does not work exactly. The look is shown as this picture. Note that the labels are also enlarged, different from the EXCEL situation.

My third question is whether there is, or will there be, a "DefaultStyle" for Worksheet ?

using System.IO;
using Aspose.Cells;

public class Program
{
public static void Main(string[] args)
{
Workbook workbook = new Workbook();

// attempt 1
// workbook.DefaultStyle.Font.Size = 30;

// attempt 2
Style defaultStyle = workbook.DefaultStyle;
defaultStyle.Font.Size = 30;
workbook.DefaultStyle = defaultStyle;

Worksheet worksheet = workbook.Worksheets[0];
Cell cell = worksheet.Cells["A1"];
cell.PutValue("Visit Aspose!");
workbook.Save("book1.xls");

}
}
It seems that I can use the Aspose.Cells.Cells object returned by Worksheet.Cells to manage per-worksheet font. However, Aspose.Cells.Cells only has GetCellStyle but not setter.

My fourth question is thus, whether there will be a corresponding setter ?

Hi,


Thanks for providing us some details and sample code.

Please try to update/ change your code as following to accomplish your task accordingly:
e.g
Sample code:

Workbook workbook = new Workbook();


// attempt 2
Style style = workbook.Styles[workbook.Styles.Add()];
style.Font.Size = 30;
StyleFlag flag = new StyleFlag();
flag.FontSize = true;

Worksheet worksheet = workbook.Worksheets[0];
worksheet.Cells.ApplyStyle(style, flag);
Cell cell = worksheet.Cells[“A1”];
cell.PutValue(“Visit Aspose!”);
workbook.Save(“e:\test2\book1.xls”);


Hope, this helps a bit.

Thank you.
Worksheet.Cells.ApplyStyle works perfectly ! :-D Thank you for your prompt answer !

Hi,


Good to know that your issue is figured out now. Feel free to contact us any time if you need further help or have some other issue or queries, we will be happy to assist you soon.

Thank you.

Thank you for your kindness again !


Just out of curiosity, why does Workbook have a DefaultStyle when Worksheet has to go through ApplyStyle ? :smiley:

Another curious (stupid) question, why “Worksheet.Cells.ApplyStyle” instead of “Worksheet.ApplyStyle” ? :smiley:

Hi,

Thanks for your posting and using Aspose.Cells.

Workbook.DefaultStyle will apply style to entire workbook. So if you will add a new worksheet inside the workbook, it will follow the default style of the workbook.

Worksheet.Cells.ApplyStyle() will apply style to current entire worksheet, if you will add a new worksheet inside the workbook, it will not be affected with the style applied to previous worksheet.

Worksheet.ApplyStyle() method does not exist.

Thank you for your helpful elaboration of the API !