FWMsExcelEx
FWMsExcelEx():New()Generates Excel-compatible XML spreadsheets by writing data directly to the file and using less memory.
Overview
FWMsExcelEx creates XML files compatible with Microsoft Excel 2003 and later versions, as well as alternative applications that can read the format. Because it writes directly to the file, it is suitable for larger data volumes. Build the output in worksheet, table, columns, rows, activation and XML-writing order.
Syntax
FWMsExcelEx():New()Minimum creation flow
User Function ExExcelXML()
Local oExcel := FWMsExcelEx():New()
oExcel:AddWorkSheet("Customers")
oExcel:AddTable("Customers", "Customer registry")
oExcel:AddColumn("Customers", "Customer registry", "Code", 1, 1, .F.)
oExcel:AddColumn("Customers", "Customer registry", "Name", 1, 1, .F.)
oExcel:AddRow("Customers", "Customer registry", {"000001", "Sample customer"})
oExcel:Activate()
oExcel:GetXMLFile("customers.xml")
ReturnCreates a worksheet, adds a two-column table and one row, then writes customers.xml.
Formatting applied to the next row
oExcel:SetCelFont("Arial")
oExcel:SetCelSizeFont(10)
oExcel:SetCelBold(.T.)
oExcel:SetCelFrColor("#FFFFFF")
oExcel:SetCelBgColor("#003366")
oExcel:AddRow("Clientes", "Cadastro de clientes", ;
{"000002", "Outro cliente"}, {1, 2})The configured style is applied to the cells listed in AddRow()’s fourth argument. Configure it immediately before the corresponding row.
Alignment, height and encoding
oExcel:SetUTF8Encode(.T.)
oExcel:SetTitleHAlign(2)
oExcel:SetHeaderHAlign(2)
oExcel:SetTitleVAlign(2)
oExcel:SetHeaderVAlign(2)
oExcel:SetLineVAlign(3)
oExcel:SetTitleHeight(24)
oExcel:SetHeadHeight(20)
oExcel:SetLineHeight(18)Configures encoding, horizontal and vertical alignment, and title, header and data-row heights.
Main methods by stage
// Ciclo de vida
New() // ClassName() // Activate() // DeActivate()
// Estrutura e dados
AddWorkSheet() // AddTable() // AddColumn() // AddRow()
IsWorkSheet() // GetXMLFile()
// Estilos gerais e específicos
SetFont() // SetFontSize() // SetBold()
SetItalic() // SetUnderLine() // SetFrGeneralColor()
SetBgGeneralColor()
SetTitleFont() // SetHeaderFont() // SetLineFont()
Set2LineFont() // SetCelFont() // SetCelBold()The class separates lifecycle, spreadsheet structure, data insertion and visual configuration. Title, Header, Line, 2Line and Cel families follow similar patterns.
- Use one instance to build the file sequentially: AddWorkSheet(), AddTable(), AddColumn(), AddRow(), Activate() and GetXMLFile().
- According to the consulted documentation, each worksheet accepts one table.
- The SetFont*, SetTitle*, SetHeader*, SetLine*, Set2Line* and SetCel* method families configure fonts, sizes, bold, italic, underline and colors.
- SetUTF8Encode() controls UTF-8 conversion; submitted content is encoded by default.
- For new projects requiring native XLSX output, compare this class with FWMsExcelXlsx and FwPrinterXlsx.
- Writing only moves forward: after starting another worksheet, do not return to the previous one. Breaking the sequence may generate an invalid file.
- Style settings must be defined before the AddRow() call to which they apply.
- AddColumn() numeric codes represent alignment (1 left, 2 center, 3 right) and format (1 general, 2 number, 3 currency, 4 date and time).
- Check parameter and method availability for your LIB version; lPrintHead is documented from LIB 20220613 onward.
- The historical documentation contains a few inconsistent descriptions and spellings; validate signatures in your environment.
