Home | Forums | Contact | Search | Syndication  
 
 [login] [create account]   Thursday, May 2, 2024 
 
slxdeveloper.com Community Forums  
   
The Forums on slxdeveloper.com are now retired. The forum archive will remain available for the time being. Thank you for your participation on slxdeveloper.com!
 Architect Forums - ADO General
Forum to discuss ADO specific questions for use with SalesLogix. View the code of conduct for posting guidelines.
Forums RSS Feed


 Back to Forum List | Back to ADO General | New ThreadView:  Search:  
 Author  Thread: Reading a range in Excel
Rohan Verghese
Posts: 40
 
Reading a range in ExcelYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 17 Dec 07 1:11 PM
I'm trying to read some data from a range in Excel. However, the standard range identifiers do not work, and causes the Saleslogix (7.0) client to crash with an Access Violation in vbscript.dll. First, is there any way for me to access a specific range, and second, is there a method I can use to cause the VBScript to fail gracefully and not bring down the client with it?

This code will work correctly:

dgPrices.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=G:\Data\Pricelists\TestList.xls;Extended Properties=Excel 8.0;"
dgPrices.SQL = "select * from [Sheet1$]"

However, this code is blowing up:

dgPrices.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=G:\Data\Pricelists\TestList.xls;Extended Properties=Excel 8.0;"
dgPrices.SQL = "select * from [Sheet1$A1:E5]"
[Reply][Quote]
John H. Hedges
Posts: 62
 
Re: Reading a range in ExcelYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 18 Dec 07 3:26 AM
Does the Excel file have field-name headers in the first row? If so, you could specify HDR=Yes in the Extended Properties to limit the number of columns, and then you could say "SELECT TOP 5 F1, F2, F3, F4, F5 FROM [Sheet1$]" to limit the number of rows, hopefully without it blowing up in the process.

I've not tried the latter, however - I don't see why TOP 5 wouldn't work, though, it's standard syntax...?

For the "failing gracefully" part, if you're already using the usual "On Error" stuff and it still happens, there might not be a good solution for that - I've run into that myself on occasion. You might end up having to read the sheet into ListView via the COM API instead, or else dump it into a temporary table in the database.
[Reply][Quote]
Rick Smith
Posts: 96
 
Re: Reading a range in ExcelYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 18 Dec 07 10:12 AM
I have had success treating well-formatted Excel files as a database using:
Sub GetWorksheetSchema(Path, Worksheet)
'connection object needed to connect to Excel/Access
Dim objConn
Set objConn = CreateObject("ADODB.Connection")
Dim strProvider
strProvider ="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Path & _
";Extended Properties=""Excel 8.0;HDR=Yes;"""
objConn.Open strProvider

'treat the workbook as a database catalog, the catalog at the connection
Dim objWbkAsDatabase
Set objWbkAsDatabase = CreateObject("ADOX.Catalog")
objWbkAsDatabase.ActiveConnection = objConn

'get the catalogs tables, which in this case is the worksheets
Dim objTables
Set objTables = objWbkAsDatabase.Tables

'for each table/sheet in the catalog/workbook display the name
Dim objTable
objTable = objTables(Worksheet)
...
End Sub
[Reply][Quote]
Rohan Verghese
Posts: 40
 
Re: Reading a range in ExcelYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 18 Dec 07 11:33 AM
Thanks for the help everyone. I think my issue was that I was attempting to work with the DataGrid directly.

Working with ADO Connection/Recordset objects instead, and then binding an open Recordset to the DataGrid for display, is working a lot better, and is matching expected behaviour.
[Reply][Quote]
 Page 1 of 1 
  You can subscribe to receive a daily forum digest in your user profile. View the site code of conduct for posting guidelines.

   Forum RSS Feed - Subscribe to the forum RSS feed to keep on top of the latest forum activity!
 

 
 slxdeveloper.com is brought to you courtesy of Ryan Farley & Customer FX Corporation.
 This site, and all contents herein, are Copyright © 2024 Customer FX Corporation. The information and opinions expressed here are not endorsed by Sage Software.

code of conduct | Subscribe to the slxdeveloper.com Latest Article RSS feed
   
 
page cache (param): 5/2/2024 3:11:32 PM