Author Topic: Read Excel using ADODB without using Microsoft Excel  (Read 2181 times)

0 Members and 1 Guest are viewing this topic.

mailmaverick

  • Bull Frog
  • Posts: 495
Read Excel using ADODB without using Microsoft Excel
« on: April 29, 2015, 12:32:56 PM »
I have got some LISP routines to read data but did not find any one having complete functionality.

I want to read entire sheet contents (usedrange), knowing the excel filename and sheet name.


jsowinski

  • Guest
Re: Read Excel using ADODB without using Microsoft Excel
« Reply #1 on: April 29, 2015, 05:44:28 PM »
Try this...
It will print the used range to the text screen.
Change the items in RED to your needs.

(defun test (MySpreadsheet SheetName)

(setq xlApp    (vlax-get-or-create-object "Excel.Application")
      xlBooks  (vlax-get-property xlApp "Workbooks")
      xlBook   (vlax-invoke-method xlBooks "Open" MySpreadsheet)
      xlSheets (vlax-get-property xlBook "Sheets")
      xlSheet  (vlax-get-property xlSheets "Item" SheetName)
)

; CYCLE THROUGH THE USED RANGE AND PRINT TEXT TO SCREEN...
(vlax-for itm (vlax-get-property xlSheet 'UsedRange)
 (print (vlax-variant-value (vlax-get-property itm 'Text)))   ; <<< REPLACE WITH YOUR CODE AS NEEDED.
)

(mapcar
 (function
  (lambda(x)
   (vl-catch-all-apply
    (function
     (lambda()
      (vlax-release-object (vl-symbol-value x))
      (set (read (vl-symbol-name x)) nil)
     ); _end lambda
    )
   )
  )
 )
 (list 'xlSheet 'xlSheets 'xlBook 'xlBooks 'xlApp)
)

(gc)(gc)

(princ)
)

; SEND THE PATH/FILE AND SHEET NAME TO THE FUNCTION.
(test "C:/MyPath/MyFile.xlsx" "Sheet_Name")

mailmaverick

  • Bull Frog
  • Posts: 495
Re: Read Excel using ADODB without using Microsoft Excel
« Reply #2 on: April 30, 2015, 01:15:26 AM »
Thanks but your routine uses Excel functionality.

I need it using ADODB.

VovKa

  • Water Moccasin
  • Posts: 1632
  • Ukraine

jsowinski

  • Guest
Re: Read Excel using ADODB without using Microsoft Excel
« Reply #4 on: May 01, 2015, 02:11:10 PM »
mailmaverick-
I'm sorry, I misread your question.

I hope you find an answer.

mailmaverick

  • Bull Frog
  • Posts: 495
Re: Read Excel using ADODB without using Microsoft Excel
« Reply #5 on: May 02, 2015, 04:21:22 PM »
Solution found. Thanks a lot.