Office Example: Spreadsheet from DBF tables
Description
This example creates a workbook with three sheets from DBF tables using AlphaSports. After the spreadsheet is populated, it is opened in Microsoft Excel.
dim DocumentFile as C = "C:\temp\A5OfficeSample4.xlsx"
dim Doc as Office::ExcelDocument ' Declare the document variable
CreateWorkbook(Doc) 'load all tables into sheets
Path = file.filename_parse(DocumentFile, "P")
on error resume next
File.Dir_Create(Path)
on error goto 0
if Doc.Save(DocumentFile)
'Release all references to the document because we are about to open it in Excel
delete Doc
sys_open(DocumentFile)
else
ui_msg_box("Error Saving Document", "Unable to save document to " \
+ DocumentFile + ":" + crlf(2) + Doc.ErrorMessage)
end if
FUNCTION CreateWorkbook as V(Doc as Office::ExcelDocument)
dim Sheet as Office::Spreadsheet ' Pointer to the spreadsheet
dim Path as C = A5.Get_Exe_Path() + "\Samples\AlphaSports\\"
' Load the tables
LoadTable(Doc, Sheet, Path, "SalesPeople")
LoadTable(Doc, Sheet, Path, "Product")
LoadTable(Doc, Sheet, Path, "Customer")
END FUNCTION
FUNCTION LoadTable as L (Doc as Office::ExcelDocument, \
BYREF Sheet as Office::Spreadsheet,\
Path as C, TableName as C)
on error goto noload
t = table.open(Path + TableName + ".DBF")
Sheet = Doc.AddSheetFromDBF(t, TableName)
noload:
END FUNCTIONSee Also
- Office
- Generate Excel Spreadsheets Programmatically
- Office::ExcelDocument
- Office::Excel2003Document
- Office::SpreadSheet
- Office::Format
- Office::Font
- Office Enumerations
- How to perform common spreadsheet operations
- Office Example: Simple Weekly sales spreadsheet
- Office Example: Multiple spreadsheets
- Office Example: Spreadsheet from SQL query
- Office Example: Spreadsheet with picture
- Office Example: Update a spreadsheet
- SQL Example: Spreadsheets from SQL schema