Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
VFPxWorkbookXLSX Manual File Creation
Message
From
06/05/2021 19:31:54
 
 
To
All
General information
Forum:
Visual FoxPro
Category:
VFPX/Sedna
Title:
VFPxWorkbookXLSX Manual File Creation
Miscellaneous
Thread ID:
01680200
Message ID:
01680200
Views:
78
I'm working with the latest non-beta release (R32) of Greg Green's VFPxWorkbookXLSX class: https://github.com/ggreen86/XLSX-Workbook-Class. My goal is to create an XLSX spreadsheet populated with VFP data.
As I see it, to start I have two options:
1. Create a basic "empty" spreadsheet in Excel, open it with the XLSX class, modify and save
2. Use XLSX class methods to create a new spreadsheet "from scratch", modify and save
I'm trying #2 as below:
loXL = NEWOBJECT( "VFPxWorkbookXLSX", "VFPxWorkbookXLSX.vcx" )
lnWB = m.loXL.CreateWorkbook( m.lcOutputFile )
* Created workbook initially has no sheets, add one:
lnWS = loXL.AddSheet( m.lnWB, "Sheet Name 1" )
* Save:
loXL.SaveWorkbook( m.lnWB )
Above code is running in a Server 2008 R2 session. It runs without error (return values from class methods are valid/non error) and the specified output file is created.
Some comments/questions:
1. According to "VFPxWorkbookXLSX Documentation R32.pdf", CreateWorkbook( ) returns an ID to a worksheet. Is this correct - it appears to return an ID to the newly created workbook (which makes more sense to me)
2. When trying to open the file, Excel comes up with a dialog "We found a problem with some content in {file}. Do you want us to try to recover as much as we can? If you trust the source of the workbook, click Yes." Clicking "No" brings up nothing. Clicking "Yes" brings up a second dialog "Excel was able to open the file by repairing or removing the unreadable content". Below that is "Removed Records: Worksheet properties from /xl/workbook.xml part (Workbook)".
The opened (repaired) workbook has a single worksheet, and that worksheet's name is "Sheet Name 1" as expected. There is an XML log file created during the repair process:
<?xml version="1.0" encoding="UTF-8" standalone="true"?>
-<recoveryLog xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main">
<logFileName>error164320_01.xml</logFileName>
<summary>Errors were detected in file 'C:\Some\Path\Test.xlsx'</summary>
-<removedRecords>
<removedRecord>Removed Records: Worksheet properties from /xl/workbook.xml part (Workbook)</removedRecord>
</removedRecords>
</recoveryLog>
I couldn't find any sample code for how to build a new XLSX file from scratch, it could well be I'm missing some crucial step(s).
Excel on the computer trying to open it is M365 Apps for Business, Version 2104 (Build 13939.20296 Click-to-Run)
Regards. Al

"Violence is the last refuge of the incompetent." -- Isaac Asimov
"Never let your sense of morals prevent you from doing what is right." -- Isaac Asimov

Neither a despot, nor a doormat, be

Every app wants to be a database app when it grows up
Next
Reply
Map
View

Click here to load this message in the networking platform