Hi,
Because of the two Excel file formats - XLSX and XLS, there are two different programing codes for each of the formats. To know which one to execute we need to know the extension or the whole name of the file. Assuming that anyway, the user will know the full name ( hardcoded or taken from file chooser) we decided to use EXL_NewBook(filePath) instead of EXL_NewBook(fileExtension).
EXL_NewBook(filePath) returns TRUE because the initial XLS or XLSX code was successfully executed. But the real file is created only after calling EXL_SaveAndCloseBook(filePath).
Technically, an empty string could be used in EXL_NewBook(''). In this case, the "XLSX" code will be executed by default. But if at the end, the book is saved and closed as "*.XLS", the file extension will differ from the file format. And an error will appear when opening this file using the Excel application.
Here is a short script example. I hope you find it useful.
PROCEDURE TestExcel;
VAR
newname : STRING;
res : BOOLEAN;
shNum : INTEGER;
BEGIN
newname:= 'C:\\Temp\\Test.xlsx';
res := EXL_NEWBOOK('');
res := EXL_ADDSHEET('NEW_SHEET');
res := EXL_GETSHEETINDEX('NEW_SHEET',shNum);
IF ( res = TRUE) THEN
BEGIN
res := EXL_SETCELLSTRING(shNum,0,0,newname);
END;
res := EXL_SAVEANDCLOSEBOOK(newname);
END;
Run(TestExcel);
Best regards,
Ivaylo.