|
|
Bug with Font.Size and SetColumnWidth?
Last post 10-12-2008, 1:20 AM by cecoder. 9 replies.
-
10-05-2008, 11:25 PM |
-
cecoder
-
-
-
Joined on 09-09-2008
-
-
Posts 21
-
-
-
-
|
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
|
|
-
10-06-2008, 4:21 AM |
-
Amjad Sahi
-
-
-
Joined on 08-30-2006
-
-
Posts 5,104
-
-
-
-
|
Re: Bug with Font.Size and SetColumnWidth?
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.
Amjad Sahi Support Developer, Aspose Nanjing Team Contact Us
|
|
-
10-07-2008, 3:28 AM |
-
simon.zhao
-
-
-
Joined on 10-24-2005
-
-
Posts 213
-
-
-
-
|
Re: Bug with Font.Size and SetColumnWidth?
Attachment: Present (inaccessible)
Hi,
Please try this fix.
We have fixed the bug .
Simon Zhao Developer Aspose Nanjing Team Contact Us
|
|
-
10-09-2008, 1:03 PM |
-
cecoder
-
-
-
Joined on 09-09-2008
-
-
Posts 21
-
-
-
-
|
Re: Bug with Font.Size and SetColumnWidth?
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
|
|
-
10-09-2008, 1:30 PM |
-
Amjad Sahi
-
-
-
Joined on 08-30-2006
-
-
Posts 5,104
-
-
-
-
|
Re: Bug with Font.Size and SetColumnWidth?
Attachment: Present (inaccessible)
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.
Amjad Sahi Support Developer, Aspose Nanjing Team Contact Us
|
|
-
10-10-2008, 6:24 PM |
-
cecoder
-
-
-
Joined on 09-09-2008
-
-
Posts 21
-
-
-
-
|
Re: Bug with Font.Size and SetColumnWidth?
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
|
|
-
10-11-2008, 7:27 AM |
-
Amjad Sahi
-
-
-
Joined on 08-30-2006
-
-
Posts 5,104
-
-
-
-
|
Re: Bug with Font.Size and SetColumnWidth?
Attachment: Present (inaccessible)
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.
Amjad Sahi Support Developer, Aspose Nanjing Team Contact Us
|
|
-
10-11-2008, 3:28 PM |
-
cecoder
-
-
-
Joined on 09-09-2008
-
-
Posts 21
-
-
-
-
|
Re: Bug with Font.Size and SetColumnWidth?
Attachment: Present (inaccessible)
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);
}
Which generates the MonthlyReport_Test.xls file I have attached where the columns are only 275px wide instead of 300px.
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
|
|
-
10-12-2008, 12:45 AM |
-
Amjad Sahi
-
-
-
Joined on 08-30-2006
-
-
Posts 5,104
-
-
-
-
|
Re: Bug with Font.Size and SetColumnWidth?
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.
Amjad Sahi Support Developer, Aspose Nanjing Team Contact Us
|
|
-
10-12-2008, 1:20 AM |
-
cecoder
-
-
-
Joined on 09-09-2008
-
-
Posts 21
-
-
-
-
|
Re: Bug with Font.Size and SetColumnWidth?
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. :) Thanks,
-Christine
|
|
|
|