Create Cursor Sample (cData C(30)) Insert into Sample values("Some text") Insert into Sample values("1.23") Insert into Sample values("999-444") Insert into Sample values("Some more text") StrToFile(ExportToExcel(),"Sample.xls") *======================================================================================== * Export the current cursor to Excel (XMLSS format) *======================================================================================== Procedure ExportToExcel *-------------------------------------------------------------------------------------- * Setup environment *-------------------------------------------------------------------------------------- Local lcPoint lcPoint = Set("Point") Set Point To "." *-------------------------------------------------------------------------------------- * Create a header *-------------------------------------------------------------------------------------- Local lcHeader Text to m.lcHeader NoShow <?xml version="1.0"?> <Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"> <Styles> <Style ss:ID="numformat"> <NumberFormat ss:Format="Fixed"/> </Style> </Styles> <Worksheet ss:Name="Sheet1"> <Table> EndText *-------------------------------------------------------------------------------------- * Assemble a string with all rows *-------------------------------------------------------------------------------------- Local lcData, lcRow, lnField, luValue lcData = "" Scan lcRow = "<Row>" For lnField = 1 to Fcount() luValue = Evaluate(Field(m.lnField)) Do case Case Vartype(m.luValue) == "C" luValue = Alltrim(Nvl(m.luValue,"")) If Transform(Val(m.luValue)) == m.luValue lcRow = m.lcRow + ; [<Cell ss:StyleID="numformat"><Data ss:Type="Number">] + m.luValue+ [</Data></Cell>] Else lcRow = m.lcRow + ; [<Cell><Data ss:Type="String">] + STRCONV(m.luValue,9)+ [</Data></Cell>] EndIf Case Vartype(m.luValue) == "N" lcRow = m.lcRow + ; [<Cell ss:StyleID="numformat"><Data ss:Type="Number">] + Transform(Nvl(m.luValue,0)) + ; [</Data></Cell>] Otherwise Assert .F. message "Type not supported" EndCase EndFor lcRow = m.lcRow + "</Row>" lcData = m.lcData + m.lcRow EndScan *-------------------------------------------------------------------------------------- * Create the footer *-------------------------------------------------------------------------------------- Local lcFooter Text to m.lcFooter noshow </Table> </Worksheet> </Workbook> EndText *-------------------------------------------------------------------------------------- * Restore environment *-------------------------------------------------------------------------------------- Set Point To m.lcPoint Return m.lcHeader + m.lcData + m.lcFooter