Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
VFPxWorkbookXLSX Manual File Creation
Message
From
06/05/2021 20:35:12
 
General information
Forum:
Visual FoxPro
Category:
VFPX/Sedna
Miscellaneous
Thread ID:
01680200
Message ID:
01680202
Views:
39
>>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)
>
>This is an extract from one of my application functions that creates a spreadsheet from a cursor.
>
>
>
>*-- CursorName is the name of the cursor where data reside. I suppose it could be a DBF file as well.
>*-- lcCursorName
>*-- This cursor has to be selected at this point. 
>
>tcWorkSheetName = "Report Data"
>
>*-- User specifies the cExcelFileName, name of the xlsx file
>cExcelFileName = FORCEEXT( cExcelFileName, "XLSX" )
>
>WAIT WINDOW "Creating Excel file ... Please wait" NOWAIT NOCLEAR 
>loExcel = NEWOBJECT("VFPxWorkbookXLSX", "VFPxWorkbookXLSX.vcx")
>
>loReturn = loExcel.SaveTabletoWorkbook(lcCursorName, cExcelFileName, .T., .T., tcWorkSheetName)
>
>
>
>The above is somewhat simplified code (I removed the declarations of LOCAL, etc.). But it works.
>
>Let me know if you have any questions.

That method .SaveTabletoWorkbook( ) basically does everything in one step. I don't know if I've used that exact method in the past but I have used one-call methods when I just want to dump a table or cursor to an Excel file, it works fine.

My goal is to create a multi-sheet workbook, with one "header" sheet and then other sheets representing the children of one-to-many relationships. The data will be pulled from multiple views/cursors so I need to manually build it. What I'm doing above is an attempt to build the whole thing from scratch, but if it's problematic I'll try with an existing, basic/empty spreadsheet.
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
Previous
Reply
Map
View

Click here to load this message in the networking platform