AutoFit columns in .Net Core

I am trying to autofit columns in a .NET Core Console application.

This statement causes a FileNotFoundException:

worksheet.Columns[i].AutoFit(1, worksheet.Rows[1], worksheet.Rows[worksheet.Rows.Count - 1]);

I have cloned your examples from GitHub.

You can reproduce the issue by slightly modifying your example RowAndColumnAutoFit.
Open the RowAndColumnAutoFit.csproj file and change the TargetFrameworks:

From: <TargetFrameworks>net48;netcoreapp3.1</TargetFrameworks>
To: <TargetFrameworks>netcoreapp3.1</TargetFrameworks>

You will now get the error.

If you add a reference to System.Drawing.Common, the issue is resolved

Hi Dermot,

Yes, System.Drawing.Common is needed for this task because of the text measurer.
I’ll update the example project on our GitHub.

Let me know if you need anything else.

Regards,
Mario