Sign in to follow this  
Followers 0
locutus243

Reading From Excel

6 posts in this topic

Hey guys,

I have a series of Excel files that I want my script to read from, preferably without opening them. I've tried opening the Excel file in @SW_HIDE mode (hidden), but when I do this then the Run fcuntion doesn't seem to work properly.

I know you can read from a text file and I tried to save my xls. file as a database but its too big.

Is there anyway that AutoIT can read data from an Excel spreadsheet???

Thanks

Mark

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Hello

I think that the best way is to use COM.

$oExcel = ObjCreate("Excel.Application")

$oExcel.Visible =  1 

If IsObj($oExcel) Then
        $oSheet = $oExcel.Application.WorkBooks.Open("c:\MySheet.xls")
        If IsObj($oSheet) Then
            msgbox(1 ," ", $oExcel.Application.Cells(1,1).Value )
        EndIf
EndIf

In this short exemple, we launch Excel, make it visible , open a Sheet and show the value of the A1 Cell.

HTH,

Francis

Edited by Francis Lennert (France)

Share this post


Link to post
Share on other sites

Hey Francis,

Thankyou for your help, this is what I want but I was wondering if there was a way to hide the Excel window so that the user is not noticeably opening it. Thats where my @SW_SHOW came in???

Thanks

Mark

Share this post


Link to post
Share on other sites

Invisible Excel:

$oExcel = ObjCreate("Excel.Application")

$oExcel.Visible =  0

If IsObj($oExcel) Then
        $oSheet = $oExcel.Application.WorkBooks.Open("c:\MySheet.xls")
        If IsObj($oSheet) Then
            msgbox(1 ," ", $oExcel.Application.Cells(1,1).Value )
        EndIf
EndIf

“Give a man a script; you have helped him for today. Teach a man to script; and you will not have to hear him whine for help.”AutoIt4UE - Custom AutoIt toolbar and wordfile for UltraEdit/UEStudio users.AutoIt Graphical Debugger - A graphical debugger for AutoIt.SimMetrics COM Wrapper - Calculate string similarity.

Share this post


Link to post
Share on other sites

Important: make certain that you do a $oExcel.quit before you exit your script or you will have an invisible instance of Excel left running on your machine with no way to shut it down other than stopping it in the task manager.

Dale


Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Share this post


Link to post
Share on other sites

Another help could be to use the RandalC Excel UDF..

Have fun with AutoIt and Excel,

Francis

(the picture at the left represents Lord Byron who didn't know that AutoIt will exist )

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0