Chilkat Examples

ChilkatHOMEAndroid™AutoItCC#C++Chilkat2-PythonCkPythonClassic ASPDataFlexDelphi DLLGoJavaNode.jsObjective-CPHP ExtensionPerlPowerBuilderPowerShellPureBasicRubySQL ServerSwiftTclUnicode CUnicode C++VB.NETVBScriptVisual Basic 6.0Visual FoxProXojo Plugin

Visual FoxPro Examples
Web API Categories

AI
ASN.1
AWS KMS
AWS Misc
Amazon EC2
Amazon Glacier
Amazon S3
Amazon S3 (new)
Amazon SES
Amazon SNS
Amazon SQS
Async
Azure Cloud Storage
Azure Key Vault
Azure Service Bus
Azure Table Service
Base64
Box
CAdES
CSR
CSV
Cert Store
Certificates
Cloud Signature CSC
Code Signing
Compression
DKIM / DomainKey
DNS
DSA
Diffie-Hellman
Digital Signatures
Dropbox
Dynamics CRM
EBICS
ECC
Ed25519
Email Object
Encryption
FTP
FileAccess
Firebase
GMail REST API
GMail SMTP/IMAP/POP
Geolocation
Google APIs
Google Calendar
Google Cloud SQL
Google Cloud Storage
Google Drive
Google Photos
Google Sheets
Google Tasks
Gzip
HTML-to-XML/Text
HTTP
HTTP Misc
IMAP
JSON
JSON Web Encryption (JWE)
JSON Web Signatures (JWS)
JSON Web Token (JWT)
Java KeyStore (JKS)
MHT / HTML Email
MIME
Markdown
Microsoft Graph
Misc
NTLM
OAuth1
OAuth2
OIDC
Office365
OneDrive
OpenSSL
Outlook
Outlook Calendar
Outlook Contact
PDF Signatures
PEM
PFX/P12
PKCS11
POP3
PRNG
REST
REST Misc
RSA
Regular Expressions
SCP
SCard
SFTP
SMTP
SSH
SSH Key
SSH Tunnel
ScMinidriver
Secrets
SharePoint
SharePoint Online
Signing in the Cloud
Socket/SSL/TLS
Spider
Stream
Tar Archive
ULID/UUID
Upload
WebSocket
X
XAdES
XML
XML Digital Signatures
XMP
Zip
curl
uncategorized

 

 

 

(Visual FoxPro) XLSX Spreadsheet in AI Query

See more AI Examples
This example shows how to convert a .xlsx spreadsheet to CSV text for input in an AI query. Currently, most AIs can't handle Excel file inputs directly. If the spreadsheet is small, you can convert it to CSV text and use it as a text input.

Note: This example requires Chilkat v11.3.0 or greater.

Chilkat ActiveX Downloads

ActiveX for 32-bit and 64-bit Windows

LOCAL lnSuccess
LOCAL loZip
LOCAL loCsv
LOCAL loSheetNames
LOCAL lcSheetName
LOCAL loSbCsv
LOCAL loAi
LOCAL loSbResponse

lnSuccess = 0

* This example assumes the Chilkat API to have been previously unlocked.
* See Global Unlock Sample for sample code.

* .xlsx files are Zip archives
loZip = CreateObject('Chilkat.Zip')
lnSuccess = loZip.OpenZip("qa_data/excel/fakeCompanies.xlsx")
IF (lnSuccess = 0) THEN
    ? loZip.LastErrorText
    RELEASE loZip
    CANCEL
ENDIF

loCsv = CreateObject('Chilkat.Csv')
loSheetNames = CreateObject('Chilkat.StringTable')
lnSuccess = loCsv.XlsxGetSheets(loZip,loSheetNames)
IF (lnSuccess = 0) THEN
    ? loCsv.LastErrorText
    RELEASE loZip
    RELEASE loCsv
    RELEASE loSheetNames
    CANCEL
ENDIF

IF (loSheetNames.Count = 0) THEN
    ? "There are no sheets in the .xlsx"
    RELEASE loZip
    RELEASE loCsv
    RELEASE loSheetNames
    CANCEL
ENDIF

* Get the name of the 1st sheet.
lcSheetName = loSheetNames.StringAt(0)

* Load the 1st sheet into the CSV.
* We could've also loaded the 1st sheet by passing an empty string for the sheet name.
lnSuccess = loCsv.XlsxLoadSheet(loZip,lcSheetName)
IF (lnSuccess = 0) THEN
    ? loZip.LastErrorText
    RELEASE loZip
    RELEASE loCsv
    RELEASE loSheetNames
    CANCEL
ENDIF

loSbCsv = CreateObject('Chilkat.StringBuilder')
loCsv.SaveToSb(loSbCsv)

* ------------------------------------------
loAi = CreateObject('Chilkat.Ai')

loAi.Provider = "openai"

* Use your provider's API key.
loAi.ApiKey = "MY_API_KEY"

* Choose a model.
loAi.Model = "gpt-4o"

* Add text inputs
loAi.InputAddText("Describe what is contained in the following CSV data.")
loAi.InputAddTextSb(loSbCsv)

* Ask the AI for text output.
lnSuccess = loAi.Ask("text")
IF (lnSuccess = 0) THEN
    ? loAi.LastErrorText
    RELEASE loZip
    RELEASE loCsv
    RELEASE loSheetNames
    RELEASE loSbCsv
    RELEASE loAi
    CANCEL
ENDIF

* Get the text response.
loSbResponse = CreateObject('Chilkat.StringBuilder')
loAi.GetOutputTextSb(loSbResponse)
? loSbResponse.GetAsString()

* Sample output:

* The CSV data contains information about five companies, including the following fields:
* 
* 1. **CompanyName**: The name of the company.
* 2. **Address**: The street address of the company.
* 3. **City**: The city where the company is located.
* 4. **State**: The state where the company is located, abbreviated.
* 5. **Zip**: The ZIP code for the company's location.
* 6. **Phone**: The phone number of the company.
* 
* Each row in the dataset corresponds to a different company with details provided for each of these fields:
* 
* ...
* ...

* -------------------------------------------------------------
* The response is in markdown format.
* Also see Markdown to HTML Conversion Examples.
* -------------------------------------------------------------

RELEASE loZip
RELEASE loCsv
RELEASE loSheetNames
RELEASE loSbCsv
RELEASE loAi
RELEASE loSbResponse


 

© 2000-2025 Chilkat Software, Inc. All Rights Reserved.