Access Violation when opening xlsx template file - Flexcel

I'm using Flexcel for VCL v.7.22.1 in C++ Builder v.12.1. Previously I was using Flexcel v.3, and have to convert my report templates by ReportConverter.exe tool. When I convert my old XLS template and use it, everything is ok, but when I open this converted template in LibreOffice and save it in newest XLSX format, then trying to execute my report with this xlsx template ends with Access Violation exception while opening template.
Screenshot 2024-09-26 12-17-54
When I create in LibreOffice new empty XLSX file, and then copy to it the content of problematic template, define needed range - then report executes fine in XLSX.
Can you say me what is wrong in converted xlsx template?

KarDlk.NT1.xlsx - template causing AccessViolation
KarDlk.NT1a.xlsx - template made by copying, non problematic

KarDlk.NT1a.xlsx (6.0 KB)
KarDlk.NT1.xlsx (6.3 KB)

Hi,
I am at the tms days today and tomorrow, I will look at this as soon as I come back next week. But in the meantime, can you confirm if the file "KarDlk.NT1.xlsx" is the correct one?

I tried here in C++ builder 12.0, win32 and win64 platforms, and it worked fine.
Are you using win64, win32 or win64x? Any other idea of what could be going wrong? Where does the debugger stop? If you just open the file and save it, it also crashes?

Hi,
Yes it's correct template.

I'm using RAD Studio 12.1 exactly, and project is in C++ Builder 64bit classic Clang compiler.
I'm executing Run procedure from TFlexCelReport, and this is call stack:

:00007FFBCF7349F6 RtlWaitOnAddress()
:00007FFBCF6FFCB4 RtlEnterCriticalSection()
:00007FFBCF6FFAE2 RtlEnterCriticalSection()
:00007FFBA51EEE74 GdipGetGenericFontFamilySansSerif()
:000000005E7E6477 _Gdiplusuiclasses::TGdipUIFont::TGdipUIFont(System::UnicodeString, double, System::Set<_Uiclasses::Tuifontstyle::TUIFontStyle, (_Uiclasses::Tuifontstyle::TUIFontStyle)0, (_Uiclasses::Tuifontstyle::TUIFontStyle)1>)()
:000000005E7F213A _Gdiplusgraphicsfactory::TGDIPlusGraphicsFactory::CreateFont(System::UnicodeString, double, System::Set<_Uiclasses::Tuifontstyle::TUIFontStyle, (_Uiclasses::Tuifontstyle::TUIFontStyle)0, (_Uiclasses::Tuifontstyle::TUIFontStyle)1>)()
:000000005E297234 _Uiclasses::Tuifont::TUIFont::InternalCreateOnly(_Uiclasses::Fontcreatingeventargs::TFontCreatingEventArgs*)()
:000000005E296EAC _Uiclasses::Tuifont::TUIFont::InternalCreate(System::UnicodeString, double, System::Set<_Uiclasses::Tuifontstyle::TUIFontStyle, (_Uiclasses::Tuifontstyle::TUIFontStyle)0, (_Uiclasses::Tuifontstyle::TUIFontStyle)1>, bool)()
:000000005E296CF7 _Uiclasses::Tuifont::TUIFont::CreateNew(System::UnicodeString, double, System::Set<_Uiclasses::Tuifontstyle::TUIFontStyle, (_Uiclasses::Tuifontstyle::TUIFontStyle)0, (_Uiclasses::Tuifontstyle::TUIFontStyle)1>)()
:000000005E2F661D _Uexcelfont::Excelfont::TExcelFont::CreateFont(System::UnicodeString, double, System::Set<_Uiclasses::Tuifontstyle::TUIFontStyle, (_Uiclasses::Tuifontstyle::TUIFontStyle)0, (_Uiclasses::Tuifontstyle::TUIFontStyle)1>)()
:000000005E2F6F8C _Uexcelmetrics::Excelmetrics::TExcelMetrics::DoFullGetFont0Width(_Uflxformats::Tflxfont::TFlxFont const&, System::DelphiInterface<_Ucoreinterfaces::Irowcolsize::IRowColSize>, double&, double&, double&)()
:000000005E2F6B79 _Uexcelmetrics::Excelmetrics::TExcelMetrics::GetFont0Width(System::DelphiInterface<_Ucoreinterfaces::Irowcolsize::IRowColSize>, bool)()
:000000005DD3F83C _Uxlsxrecordloader::Txlsxrecordloader::TXlsxRecordLoader::ReadSheetFormatPr(_Uxlssheet::Tsheet::TSheet*)()
:000000005DD35463 _Uxlsxrecordloader::Txlsxrecordloader::TXlsxRecordLoader::ReadSheet(_Uxlssheet::Tsheet::TSheet*, int, _Umiscclasses::Tlegacyinfo::TLegacyInfo*)()
:000000005DD3470A _Uxlsxrecordloader::Txlsxrecordloader::TXlsxRecordLoader::ReadSheet(System::UnicodeString, _Uexcelrecords::Tsheetlist::TSheetList*, __Flexceltypes::TFlexCelObject*)()
:000000005DD74F70 _Uexcelrecords::Tworkbook::TWorkbook::LoadXlsxWorkbook(_Uxlsxrecordloader::Txlsxrecordloader::TXlsxRecordLoader*, bool&)()
:000000005DD752D0 _Uexcelrecords::Tworkbook::TWorkbook::LoadFromStream(_Uxlsxrecordloader::Txlsxrecordloader::TXlsxRecordLoader*, _Uprotect::Tprotection::TProtection*, bool&)()
:000000005DCB87F7 _Uxlsadapter::Xlsfile::TXlsFile::OpenXlsx(System::Classes::TStream*, bool)()
:000000005DCB7665 _Uxlsadapter::Xlsfile::TXlsFile::Open(System::Classes::TStream*, _Ucoreenums::Tfileformats::TFileFormats, wchar_t, int, int, System::DynamicArray<_Ucoreenums::Columnimporttype::TColumnImportType>, System::DynamicArray<System::UnicodeString>, System::Sysutils::TEncoding*, bool)()
:000000005DCB74EA _Uxlsadapter::Xlsfile::TXlsFile::Open(System::UnicodeString, _Ucoreenums::Tfileformats::TFileFormats, wchar_t, int, int, System::DynamicArray<_Ucoreenums::Columnimporttype::TColumnImportType>, System::DynamicArray<System::UnicodeString>, System::Sysutils::TEncoding*, bool)()
:000000005E4CDB7F _Exceladapter::Excelfile::TExcelFile::Open(System::UnicodeString, _Ucoreenums::Tfileformats::TFileFormats, wchar_t, int, int, System::DynamicArray<_Ucoreenums::Columnimporttype::TColumnImportType>, System::Sysutils::TEncoding*, bool)()
:000000005E4CDB14 _Exceladapter::Excelfile::TExcelFile::Open(System::UnicodeString, _Ucoreenums::Tfileformats::TFileFormats, wchar_t, int, int, System::DynamicArray<_Ucoreenums::Columnimporttype::TColumnImportType>)()
:000000005E4CDAAA _Exceladapter::Excelfile::TExcelFile::Open(System::UnicodeString)()
:000000005CE40D39 _Flexcelreport::Flexcelreport::TFlexCelReport::Run(System::UnicodeString, System::UnicodeString)()
:000000005CFDD7FD TEwidRapFrm::ExecuteReportXls(System::UnicodeString, System::UnicodeString, bool, System::UnicodeString, Data::Db::TDataSet*)(this=0x000001896965dd50, szablon="KarDlk.NT1.xlsx", plikWynik="wynik.xls", uruchomEdyt=true, dataSetName="MainODS", dataSet=0x000001897274a600)

The call stack is strange. As we discussed by mail, it looks to be something in the font handling of GDI+, but it shouldn't cause an AV. (and here the file opens fine).

The difference between the file that opens fine in your machine and the one that doesn't with respect to fonts seem to be that the libreoffice file is trying to open "Arial CE" while the other just tries to open "Arial"

But trying it here, when it tries to open "Arial CE" GDI+ just returns "Arial" so this shouldn't be a problem.

Assuming there is an error trying to open the font, FlexCel has a backup of trying to open the "Generic Sans Serif", which seems to be where your error is. But manually forcing it here to call that line, it just returns the font "microsoft sans serif", it doesn't crash as it does in the stack trace. I think it could be a problem of GDI+ not being initialized correctly, but then the other file wouldn't work either.

So some ideas to try:

  1. I made a small C++ app that tries to call GdipGetGenericFontFamilySansSerif (the method that crashes in your code). You can find it here: https://download.tmssoftware.com/flexcel/samples/cppgdip.zip
    Please try it (in the platform you are using, I tried all win32, win64 and win64x, but we should focus in where the problem is) and let me know if it crashes or returns valid values.
  2. I manually modified the file that is giving trouble just to change the "Arial CE" line by just "Arial". You can get the file here: https://download.tmssoftware.com/flexcel/samples/_KarDlk.NT1b.xlsx
    Can you tell me if that file works fine? If it does, then the problem is the "Arial CE" thing.
  3. Can you verify if your app doesn't work also in a different machine? As said, it works here, and I see no real reason for it to not work elsewhere, so I wonder if this is something with your machine or something different. Do you have Arial and Microsoft sans serif installed in the machine?

Hi,

  1. This is result from your app on win64:
    Screenshot 2024-10-02 20-10-49

And this on win32:
Screenshot 2024-10-02 20-11-58

  1. Template modified by you causes the same AccessViolation:
    Screenshot 2024-10-02 20-16-12
    and the call stack is exactly the same.

  2. We have verified our app on another computer, and there is the same AV:

First chance exception at $00007FF8A3FB49F6. Exception class 0xc0000005 with message 'Exception 0xc0000005 encountered at address 0x7ff8a3fb49f6: Access violation writing location 0x00000024'. Process aaa.exe (23944)
First chance exception at $00007FF8A199B699. Exception class EAccessViolation with message 'Access violation at address 00007FF8A3FB49F6 in module 'ntdll.dll' (offset 649F6). Write of address 0000000000000024'. Process aaa.exe (23944)
First chance exception at $00007FF8A3FB49F6. Exception class 0xc0000005 with message 'Exception 0xc0000005 encountered at address 0x7ff8a3fb49f6: Access violation writing location 0x00000024'. Process aaa.exe (23944)
First chance exception at $00007FF8A199B699. Exception class EAccessViolation with message 'Access violation at address 00007FF8A3FB49F6 in module 'ntdll.dll' (offset 649F6). Write of address 0000000000000024'. Process aaa.exe (23944)
First chance exception at $00007FF8A199B699. Exception class EAccessViolation with message 'Access violation at address 00007FF8A3FB49F6 in module 'ntdll.dll' (offset 649F6). Write of address 0000000000000024'. Process aaa.exe (23944)

Yes, I have Arial and Microsoft sans serif installed.

Hi,
Have You any new information or ideas?