Aspose.Cells AutoFitColum doesn't work on formatted column

AutoFitterOptions options = new AutoFitterOptions();
options.FormatStrategy = CellValueFormatStrategy.DisplayString;

//auto fit width
foreach (Worksheet w in workbook.Worksheets)
{
//Resize columns
w.AutoFitColumns(options);
}

However, the column with currency format did not get autofit on width.

@lfan
We have tested the code with some sample data but cannot find the issue. Would you please provide the template file which can reproduce the issue so we can investigate it?

Here’s the code used to autofitcolumn width:

internal static void AutoFitColumns(string fileName, string sheetName)
{
// Step 1:Create a License object
License license = new License();

// Set the license of Aspose.Cells to avoid the evaluation limitations
license.SetLicense(GetAsposeLicensePath());

//get workbook
Workbook workbook = new Workbook(fileName);

AutoFitterOptions options = new AutoFitterOptions();
options.FormatStrategy = CellValueFormatStrategy.DisplayString;

try
{
    //get worksheet by name
    Worksheet worksheet = workbook.Worksheets[sheetName];
                    

    //auto fit width
    foreach (Worksheet w in workbook.Worksheets)
    {
        //Auto fit column width
        w.AutoFitColumns(options);
        Debug.WriteLine("Sheet {0} formatteed", w.Name);
    }

}
catch (Exception ex) { }


//get the directory of the filename
string directory = Path.GetDirectoryName(fileName);

if (directory != null)
{
    string tempFilePath = Path.Combine(directory, "_temp_output.xlsx");

    workbook.Save(tempFilePath, SaveFormat.Xlsx);

    // Replace the original file with the temporary file
    File.Replace(tempFilePath, fileName, null);

    Debug.WriteLine("Modifications saved back to the original file successfully.");
}
else
{
    Debug.WriteLine("directory not found");
}

}

I attach a screenshot of the Excel file since it not accept the spreadsheet format in attachement:
image.png (56.3 KB)

@lfan,

Thanks for the screenshot and sample code segment.

I am afraid that the provided screenshot won’t be enough as we need your template Excel file to evaluate your issue precisely. Kindly zip your template Excel file and attach the zipped archive here, so we could look into your issue soon. By the way, which version of Aspose.Cells for .NET are you using? Please try using the latest version/fix: Aspose.Cells for .NET v24.5 if you are not already using it.

AutoFitIssue.zip (8.2 KB)

I attached the zipped spreadsheet. I updated the Aspose.Cells version to 24.5.0 but no luck.

@lfan,

Thanks for the template XLSX file.

After an initial test, I was able to reproduce the issue (as per your screenshot) you mentioned by using your template XLSX file. I found Worksheet.AutoFitColum doesn’t work on the formatted column.

We require thorough evaluation of the issue. We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): CELLSNET-55945

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.

@lfan
Please install Courier font. After installing it, we got the following result:
24.5.5 (2).zip (8.2 KB)
And please check documnt about configuring fonts:

And if there is still any issue after installing Courier font, please share your Courier font file here, we will check it soon.