![]() |
Chilkat HOME Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi DLL Go Java Node.js Objective-C PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(VB.NET) XLSX Spreadsheet in AI QuerySee more AI ExamplesThis 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.
Dim success As Boolean = False ' This example assumes the Chilkat API to have been previously unlocked. ' See Global Unlock Sample for sample code. ' .xlsx files are Zip archives Dim zip As New Chilkat.Zip success = zip.OpenZip("qa_data/excel/fakeCompanies.xlsx") If (success = False) Then Debug.WriteLine(zip.LastErrorText) Exit Sub End If Dim csv As New Chilkat.Csv Dim sheetNames As New Chilkat.StringTable success = csv.XlsxGetSheets(zip,sheetNames) If (success = False) Then Debug.WriteLine(csv.LastErrorText) Exit Sub End If If (sheetNames.Count = 0) Then Debug.WriteLine("There are no sheets in the .xlsx") Exit Sub End If ' Get the name of the 1st sheet. Dim sheetName As String = sheetNames.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. success = csv.XlsxLoadSheet(zip,sheetName) If (success = False) Then Debug.WriteLine(zip.LastErrorText) Exit Sub End If Dim sbCsv As New Chilkat.StringBuilder csv.SaveToSb(sbCsv) ' ------------------------------------------ Dim ai As New Chilkat.Ai ai.Provider = "openai" ' Use your provider's API key. ai.ApiKey = "MY_API_KEY" ' Choose a model. ai.Model = "gpt-4o" ' Add text inputs ai.InputAddText("Describe what is contained in the following CSV data.") ai.InputAddTextSb(sbCsv) ' Ask the AI for text output. success = ai.Ask("text") If (success = False) Then Debug.WriteLine(ai.LastErrorText) Exit Sub End If ' Get the text response. Dim sbResponse As New Chilkat.StringBuilder ai.GetOutputTextSb(sbResponse) Debug.WriteLine(sbResponse.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. ' ------------------------------------------------------------- |
||||
© 2000-2025 Chilkat Software, Inc. All Rights Reserved.