Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
VFPxWorkbookXLSX Manual File Creation
Message
 
 
To
06/05/2021 19:31:54
General information
Forum:
Visual FoxPro
Category:
VFPX/Sedna
Miscellaneous
Thread ID:
01680200
Message ID:
01680201
Views:
50
>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.

HTH
"The creative process is nothing but a series of crises." Isaac Bashevis Singer
"My experience is that as soon as people are old enough to know better, they don't know anything at all." Oscar Wilde
"If a nation values anything more than freedom, it will lose its freedom; and the irony of it is that if it is comfort or money that it values more, it will lose that too." W.Somerset Maugham
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform