Bug with Font.Size and SetColumnWidth?

Hi,

When I have a default style for the workbook and set its font size to 14, the SetColumnWidthPixel function does not seem to behave as expected.

This is my default style:

// Set a default style
Aspose.Cells.Style defaultStyle = workbook.DefaultStyle;
defaultStyle.Font.Name = “Tahoma”;
defaultStyle.Font.Size = 14;
defaultStyle.Font.IsBold = true;
workbook.DefaultStyle = defaultStyle;

And here is where I set the column width of columns 1 - 15 to be 100px:

for (i = 1; i < 16; i++)
cells.SetColumnWidthPixel(i, 100);

But when the excel sheet generates the columns are only 70px wide each instead of 100px. Similarly, SetColumnWidth does not set it to the specified size either. However, both functions behave correctly if I comment out the line where it sets the Font.Size = 14.

Is there a way to specify a default font size and still be able to reliably set a column width afterwards? SetRowWidth and SetRowWidthPixel are not similarly effected.

Thanks,
-Christine Coder

Hi Christine Coder,

Thanks for pointing out the issue.

Sorry for my mistake, We have found the issue (you have described) evaluating our test case. Hopefully, we will figure it out and provide you a fix tomorrow.

Thank you.

Hi,

Please try this fix.

We have fixed the bug .

Thank you very much!

It works for default workbook font sizes such as 8, 10, 12, 14, and 30. I only need 8, 10, and 12, so I am happy, although I did notice that the SetColumnWidthPixel() function still seems to misbehave for default workbook font size = 16. Columns set to 118px generate as being 108px, and 300px turns out as 276px.

Like I said, I don’t need 16 to work, but thought I would mention it anyway.

Thanks again,
Christine

Hi Christine,

Could you try the attached version as I don't get any problem with the size of the columns in pixel related Tahoma 16 Bold as workbook's default font.

Sample code:

Workbook workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets[0];
Cells cells = worksheet.Cells;
// Set a default style
Aspose.Cells.Style defaultStyle = workbook.DefaultStyle;
defaultStyle.Font.Name = "Tahoma";
defaultStyle.Font.Size = 16;
defaultStyle.Font.IsBold = true;
workbook.DefaultStyle = defaultStyle;
for (int i = 1; i < 16; i++)
cells.SetColumnWidthPixel(i, 300);
//Or this also works fine.
//cells.SetColumnWidthPixel(i, 118);

workbook.Save("f:\\test\\defstyleandcolwidth.xls");

Thank you.

That does work, however when I comment out the line:

defaultStyle.Font.IsBold = true;

The column widths mess up again. Please let me know if it happens for you too. Thanks,

-Christine

Hi Christine,

No, I don't get any problem commenting out the line i.e.., defaultStyle.Font.IsBold = true;

Attached is my output file.

Could you post your generated file with sample code.

Thank you.

Hmm. Well, I have a “Generate Report” button on my page, and and when it is clicked, I have this test function called:


protected void GenerateMonthlyReport(object sender, EventArgs e)

{

Workbook workbook = new Workbook();

Worksheet worksheet = workbook.Worksheets[0];

Cells cells = worksheet.Cells;

// Set a default style

Aspose.Cells.Style defaultStyle = workbook.DefaultStyle;

defaultStyle.Font.Name = “Tahoma”;

defaultStyle.Font.Size = 16;

//defaultStyle.Font.IsBold = true;

workbook.DefaultStyle = defaultStyle;

for (int i = 1; i < 16; i++)

cells.SetColumnWidthPixel(i, 300);

//Or this also works fine.

//cells.SetColumnWidthPixel(i, 118);



string workbookname = “MonthlyReport_Test.xls”;

workbook.Save(workbookname, FileFormatType.Default, SaveType.OpenInExcel, this.Response);

}

When I use this same exact function but do not comment out the Font.IsBold line, like so:


protected void GenerateMonthlyReport(object sender, EventArgs e)

{

Workbook workbook = new Workbook();

Worksheet worksheet = workbook.Worksheets[0];

Cells cells = worksheet.Cells;

// Set a default style

Aspose.Cells.Style defaultStyle = workbook.DefaultStyle;

defaultStyle.Font.Name = “Tahoma”;

defaultStyle.Font.Size = 16;

defaultStyle.Font.IsBold = true;

workbook.DefaultStyle = defaultStyle;

for (int i = 1; i < 16; i++)

cells.SetColumnWidthPixel(i, 300);

//Or this also works fine.

//cells.SetColumnWidthPixel(i, 118);



string workbookname = “MonthlyReport_Test.xls”;

workbook.Save(workbookname, FileFormatType.Default, SaveType.OpenInExcel, this.Response);

}

Then the column widths are correct. I have attached the output from this test function as well, named MonthlyReport_Test-2.xls



I did download the new .dll posted earlier in this thread and it is the
one I am currently using. The absolute only change I am making is
commenting or uncommenting out that one line, and the result is having
the column widths = 300px like they should or 275px when it messes up.



Thanks,

Christine

Hi Christine,

Thanks for providing us the generated files

Well, I did test the second code snippet in an asp.net application and it works fine as the column widths are exactly 300px. It looks really strange that you are getting this problem commenting out the specific line of code (i.e.., //defaultStyle.Font.IsBold = true;).

I tested it with MS Excel 2000, 2003, 2007 etc. and all the versions show exactly 300px.

Anyways, We will investigate and look into your issue soon.

Thank you.

Thanks, but no need to worry about it. I don’t want to use the default font size of 16 anyway, and that was the only one I found that did not work for me. I am using either 10 or 12 and both of those work perfectly. :slight_smile: Thanks,

-Christine