Xbasic

SQL::ResultSettoExcel Method

Syntax

result as L = toExcel(DestinationFile as C [, SheetName as C [, IncludeHeadings as L [, RowsToCopy as N [, StartRow as N [, ReferenceColumns as SQL::TableInfo [, UserContext as P]]]]]])

Arguments

DestinationFileCharacter

The name of the Excel file.

SheetNameCharacter

Optional. The name of the sheet that contains the data in the Excel file.

IncludeHeadingsLogical

Optional. Default value is .t.. Defines whether or not headings should be included in the Excel file. If .f., headings will not be included.

RowsToCopyNumeric

Optional. Default value is -1. The number of rows to copy to the Excel file.

StartRowNumeric

Optional. Default value is -1. Defines the first row of data to copy from the ResultSet.

ReferenceColumnsSQL::TableInfo

Optional. A SQL::TableInfo object that can be used to transform the data in the result set.

UserContextPointer

Optional. Used to resolve any data transformations.

Returns

resultLogical

Returns .t. if successful. Otherwise .f..

Description

Convert ResultSet to an Excel 2003 format (.xls) or 2007 format (.xlsx) file.

dim cn as SQL::Connection
dim rs as SQL::ResultSet
dim sql as C = "SELECT * FROM Customers"
dim filename as c = "C:\path\to\Northwind_Customers.xls"

' Open connection to Northwind Access database
cn.open("::Name::Northwind")
cn.execute(sql)

if (cn.ResultSet.toExcel(filename) = .f.) then
    ui_msg_box("An error occured: " + cn.ResultSet.CallResult)
end if

cn.close()