Error: "Cannot Find Font '?'" on call to AutoFitColumns


#1

Hello. I am receiving the following error when I call AutoFitColumns on my worksheet:

Exception Details: System.ArgumentException: Cannot find font ‘?’.
Stack Trace:
[ArgumentException: Cannot find font ‘?’.]
at System.Drawing.FontFamily.get_GenericSansSerif()
at System.Drawing.Font.CreateFontFamilyWithFallback(String familyName)
at System.Drawing.Font.Initialize(String familyName, Single emSize, FontStyle style, GraphicsUnit unit)
at System.Drawing.Font…ctor(String familyName, Single emSize)
at k.b()
at k.a()
at k.a(Worksheet A_0, Byte A_1)
at Aspose.Excel.Worksheet.AutoFitColumn(Byte columnIndex)


I am compiling my app using VS.NET 2002, so against framework version 1.0.

I have done some experiementing today, and it works in the following environments:
- Windows Server 2003 (framework 1.1)
- Windows XP (both framework 1.0 and 1.1 installed)
- Windows 2000 (both framework 1.0 and 1.1 installed)

And it does not work in the following situations:
- Windows 2000 (framework 1.1)

It seems to be directly related to the FontFamily.GenericSansSerif static property call, as I can duplicate this error behavior in my own code.

I am trying to do more research into this issue, however if you have any insight or hotfixes that would address this, that would be awesome!


#2

I guess some fonts in your designer spreadsheet are not installed in your machine. That caused this exception. I will check my code and make a hotfix in a few days. And if possible, you can also check your file and code to see what caused the exception.


#3

Thanks for the assistance. By “designer spreadsheet”, what do you mean? I am creating a new sheet from scratch, so I’m not using a template or anything that would require a specific font.

In my previous post, I may not have been clear in what I meant about what seems to be causing the problem. If I write a simple web app that only calls “FontFamily.GenericSansSerif” (in System.Drawing), I receive the same error. So, it doesn’t necessarily seem to be a problem directly related to your code, however, its still something that shouldn’t fail :slight_smile:

Also, my code that uses the control is pretty basic. I simply load data from a DataSet/DataTable, make the top row bold and frozen, and then Auto Fit the columns.

Thanks,
Jason


#4

Hi Jason,

Do you create the sheet all from code, without a template?

If so, could you post your code here? Or send them to me?

In my code, I never use FontFamily.GenericSansSerif. And it works fine if I call FontFamily.GenericSansSerif.

Do you install Arial font in your machine?


#5

Hello.

My source code is at the bottom of this post.

To answer your questions, yes, the sheet is created without a template.

Obviously I don’t know what your code looks like, but it must be something that you call that in turn calls FontFamily.GenericSansSerif (based on the stack trace I posted). But, regardless of what is causing this, I am hoping to do more research in the next few days.

Last, regarding the Arial font, I believe it is installed (would have been installed by default with W2K). The GenericSansSerif property thing actually returns Microsoft Sans Serif. If I delete both that font and Arial on the W2K machine that this works on, and then run my “FontFamily.GenericSansSerif” test app, it still works.

Sorry if this is all very confusing. I’m just trying to help out to see if I can avoid this problem on my end… :slight_smile:


private void OnExcelExport(object sender, System.EventArgs e)
{
Excel oExcel = new Excel(Constants.AsposeExcelPath);
Worksheet oSheet = oExcel.Worksheets[0];

// Get the data ready
DataSet oDS = m_oInfo.GenerateReport(ReportOutputType.Excel);
DataTable oTable = oDS.Tables[0];
int iColCount = oTable.Columns.Count;

oSheet.Cells.ImportDataTable(oTable, true, 0, 0);
oSheet.FreezePanes(“A2”, 1, iColCount);


for ( int i = 0; i < iColCount; ++i )
{
byte bIter = System.Convert.ToByte(i);
oSheet.Cells[0, bIter].Style.Font.IsBold = true;
oSheet.AutoFitColumn(bIter);
}

// Save the report
oExcel.Save(String.Format("{0}.xls", m_oInfo.Name.Replace(" ", “”)), SaveType.OpenInExcel, FileFormatType.Default, Response);
}


#6

I did some testing using your code. All worked fine. I guess it’s a setup problem of your dotnet environment.

Please try your code in another machine to see if the problem still exists. If the problem disappeares, I think you’d better check your configuration of your web app. Maybe you have to re-install your dotnet environment, or even re-install the whole system.


#7

Thanks for your assistance. We are planning to upgrade the servers that this runs on to Windows Server 2003 within the next month (I hope).