Xbasic
Generate Excel Spreadsheets Programmatically
IN THIS PAGE
Description
The Office class can read and write Excel files. It doesn't require Microsoft Excel. Use it to
Generate a new spreadsheet from scratch
Generate a new spreadsheet from your databases
Edit an existing spreadsheet
Merge an existing spreadsheet with new data
The overall sequence used to generate an Excel spreadsheet is
Create a new document object
For an Excel 2007 spreadsheet
dim Doc as Office::ExcelDocument
for an Excel 2003 spreadsheet
dim Doc as Office::Excel2003Document
Add one or more sheets to the document
dim Sheet as Office::Spreadsheet Sheet=Doc.AddSheet("My sheet name")
Create your fonts and formats
dim Format as Office::Format dim Font as Office::Font Format = Doc.AddFormat() Font = Doc.AddFont() Font.Color = Office::Color::DarkBlue Font.Name = "Tahoma" Font.Size = 14 Font.Bold = .t. Format.Font = Font Format.HorizontalAlignment = Office::HorizontalAlignment::Center
Add cells to the sheets
Sheet.Write(1,1,"Hello, World",Format) Sheet.Write(2,1,3.14159,Format)
Save the document, Use .xls for Excel 2003
Doc.Save("MySheet.xlsx")
Release references to the in-memory document
delete Doc
See Also
- Office
- Office::ExcelDocument
- Office::Excel2003Document
- Office::SpreadSheet
- Office::Format
- Office::Font
- Office Example: Hello, World Spreadsheet
- 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 from DBF tables
- Office Example: Spreadsheet with picture
- Office Example: Update a spreadsheet
- SQL Example: Spreadsheets from SQL schema