Autofit does not work properly if a style with a font name "Calibri" is applied and a zoom is less than 100 is set to a worksheet

Hello,


I’ve already reported about the issue with a column auto fit when zoom is set:
http://www.aspose.com/community/forums/405161/autofit-does-not-work-properly-if-a-style-with-a-bold-font-is-applied-and-a-zoom-lt-100-is-set-to/showthread.aspx#405161


Today we faced with another one. If we set a style with font name (for example) "Calibri" auto fit also does not work properly if zoom < 100 is set. I attached the sample project for your convinience. The exported document contains 2 columns: for the 1st one "Calibri" font is set and "Arial" font - for the 2nd. We call "AutoFitColumn" method for both columns and it works fine with "Arial" but does not with "Calibri" font. This behavior is observed if zoom < 100 only.

Please let me know if it's the bug.
Hi,

Thanks for the sample project.

I can find the issue as you have mentioned. The auto-fitting of columns are not applied when the zoom is set less than 100 and a style (with font "Calibri") is applied to a range of cells.

Sample code:


using System.Diagnostics;
using System.IO;
using Aspose.Cells;

namespace AsposeZoomAutofitIssue
{
class Program
{
private const string WorksheetName = "Test";

static void Main()
{
var workbook = ExportTable();

Worksheet worksheet = workbook.Worksheets[WorksheetName];
ApplyTextStyle(worksheet);

worksheet.AutoFitColumn(0);
worksheet.AutoFitColumn(1);
worksheet.AutoFitColumn(2);

worksheet.Zoom = 70; // Important. Does not work with zoom only.

const string filePath = @"2mExportedFile.xls";
using (var workBookWriteStream = File.Create(filePath))
workbook.Save(workBookWriteStream, SaveFormat.Excel97To2003);

Process.Start(filePath);
}

private static Workbook ExportTable()
{
var workbook = new Workbook();
workbook.Worksheets.Clear();
Worksheet worksheet = workbook.Worksheets.Add(WorksheetName);

worksheet.Cells.ImportArray(new[] {"Col", "Col2"}, 0, 0, false);
worksheet.Cells.ImportArray(new[] {"SAMPLE TEXT IN UPPER CASE", "a"}, 1, 0, false);
worksheet.Cells.ImportArray(new[] { "SAMPLE TEXT IN UPPER CASE SAMPLE TEXT IN UPPER CASE - CALIBRI", "SAMPLE TEXT IN UPPER CASE SAMPLE TEXT IN UPPER CASE - ARIAL" }, 2, 0, false);
worksheet.Cells.ImportArray(new[] { "SAMPLE TEXT IN UPPER CASE SAMPLE ", "b"}, 3, 0, false);

return workbook;
}

private static void ApplyTextStyle(Worksheet worksheet)
{
Style style1 = new Style();
style1.Font.Size = 10;
style1.Font.Name = "Calibri";

Style style2 = new Style();
style2.Font.Size = 10;
style2.Font.Name = "Arial";

var range = worksheet.Cells.CreateRange(0, 0, 10, 1); // apply style to "Col1"
range.ApplyStyle(style1, new StyleFlag { All = true });

range = worksheet.Cells.CreateRange(0, 1, 10, 1); // apply style to "Col2"
range.ApplyStyle(style2, new StyleFlag { All = true });
}
}
}

I have logged a ticket with an id: CELLSNET-40989 for your issue. We will look into your issue to figure it out soon.

Thank you.