Problem With DefaultStyle in Opened Workbook

This issue started with Version 4.4.1 of Aspose.Cells. It was fine in 4.4.0.0 and prior:

I have an existing workbook that has a DefaultStyle set with a Font Size of 8. When I open the workbook in Aspose.Cells, it opens it with a DefaultStyle font size of 10. It also doesn't keep my default font face of Tahoma either - it sets it to Arial. Here is sample code:

Aspose.Cells.Workbook pSourceWorkBook = new Aspose.Cells.Workbook();

pSourceWorkBook.Open(@"c:\seanb.xls");

Console.WriteLine(pSourceWorkBook.DefaultStyle.Font.Size.ToString());

Console.Read();

It outputs 10 to the console window with Version 4.4.1 (and above). Running with version 4.4.0.0 (and below) it outputs 8 (which is what I expect). I have attached the spreadsheet in question for consideration.

Thank you.

Hi,

Thanks for providing us the template file.

Yes, we found the issue after an initial test, we will fix it soon.

Thank you.

Hi,

Thanks for your template file.

Please try this fix. We have fixed this bug.

Thank you, that does fix my problem when opening a workbook, and it works when copying an entire workbook as well.

I am still having problems with the defaultstyle being lost when copying worksheets though. For example, using the same template file as before, if I do the following to copy to a new workbook, it works fine (keeps the defaultstyle):

Aspose.Cells.Workbook tempWorkBook = new Aspose.Cells.Workbook();

Aspose.Cells.Workbook pSourceWorkBook = new Aspose.Cells.Workbook();

pSourceWorkBook.Open(@"c:\seanb.xls");

tempWorkBook.Copy(pSourceWorkBook);

tempWorkBook.Save(@"c:\seanc.xls", FileFormatType.Excel2003);

But if I do the following, it loses the defaultstyle (even if I explicitly assign it):

Aspose.Cells.Workbook tempWorkBook = new Aspose.Cells.Workbook();

Aspose.Cells.Workbook pSourceWorkBook = new Aspose.Cells.Workbook();

pSourceWorkBook.Open(@"c:\seanb.xls");

tempWorkBook.DefaultStyle = pSourceWorkBook.DefaultStyle;

tempWorkBook.DefaultStyle.Font.Size = pSourceWorkBook.DefaultStyle.Font.Size;

tempWorkBook.Worksheets.Add();

tempWorkBook.Worksheets[0].Copy(pSourceWorkBook.Worksheets[0]);

tempWorkBook.Worksheets[0].Name = pSourceWorkBook.Worksheets[0].Name;

tempWorkBook.Save(@"c:\seanc.xls", FileFormatType.Excel2003);

Hi,

Well, I don't find the problem you are talking about. I got the Tohoma font with size 8 for the cells in the worksheets. I think you are talking that there is still Arial 10 in the workbook if you click menu option Format|Style and check the Normal style's font attributes in MS Excel.

Well, you may try the following code to accomplish the task:

Aspose.Cells.Workbook tempWorkBook = new Aspose.Cells.Workbook();
Aspose.Cells.Workbook pSourceWorkBook = new Aspose.Cells.Workbook();
pSourceWorkBook.Open(@"f:\test\seanb.xls");
Style style = tempWorkBook.Styles["Normal"];
style.Font.Name = pSourceWorkBook.DefaultStyle.Font.Name;
style.Font.Size = pSourceWorkBook.DefaultStyle.Font.Size;
style.Update();
tempWorkBook.Worksheets.Add();
tempWorkBook.Worksheets[0].Copy(pSourceWorkBook.Worksheets[0]);
tempWorkBook.Worksheets[0].Name = pSourceWorkBook.Worksheets[0].Name;
tempWorkBook.Save(@"f:\test\seanc.xls", FileFormatType.Excel2003);

Thank you.

You are correct, that was the area that I was still seeing Arial 10.

Applying your code does change it so I now see Tahoma 8 in the Normal style. But the copied sheet is still styled in Arial 10. I can tell by looking at the fonts of the row numbers and column letters. I wouldn't normally mind that it changes the style, but it messes up my column widths and row heights when it does this.

Hi,

.....But the copied sheet is still styled in Arial 10. I can tell by looking at the fonts of the row numbers and column letters.

Well, I don't find the problem you have described, attached is the output "seanc.xls" file running my code (in my previous post) which has Tahoma 8 as the normal style for all the worksheets (including the copied sheet) in the workbook.

Could you post your created file here, we will check it soon.

Thank you.

My seanc.xls created file looks the same as yours. I suppose I'm having trouble describing the problems I'm still seeing. I can't be sure it has to do with DefaultStyle anymore, but the sheets are still different. For example:

Open seanb.xls and seanc.xls up and flip back and forth between them. You will see that the fonts used for the row numbers and column letters are different (Arial 10 in seanc.xls, Tahoma 8 in seanb.xls).

The column widths are wider in seanc.xls compared to seanb.xls (for example column A is 8.71 in seanc.xls, it is 8.50 in seanb.xls)

I have the sheet set to "Fit to 1 page wide by 9999 pages tall" If you go to page setup in seanb.xls, you will see that it adjusts it to 100%. In seanb.xls, it adjusts it to 80% (likely to make up for the increased column widths).

If you do a page preview of each file side-by-side, you can see the font of seanc.xls is significantly shrunk compared to seanb.xls (again due to the increased column widths and fit to page settings).

I only experience this issue in version 4.4.1 and higher. If I run the code in 4.3.0.0, seanc.xls and seanb.xls look identical.

Hi,

Thanks for providing us further details.

We checked and now understood the issue involved (as you suggested). We will figure out soon.

Thank you.

Hi,

Please try this fix.

We have fixed this bug.Thanks for your patience.

In the old version, we do not change the default column width when the "Normal" style is updated.