Jump to content
gahhon

Problem with Excel Read

Recommended Posts

Hi Guys,

I was trying to read some data from the excel file and without opening the file. But I tried a lot of methods, it still open the file.

And also, I am able to capture the ColumnA value but not Column B.

Thanks for advance information.

Global $oDataA, $oDataB

Call ("ExcelRead", "B2", "C2")

Func ExcelRead($oColumnA, $oColumnB)
    Local $oPath = @ScriptDir & "\MyFile.xlsx"
    Local $oExcel = _Excel_Open()
    Local $oWorkbook = _Excel_BookOpen($oExcel, $oPath, 1, 0)

    $oDataA = _Excel_RangeRead($oWorkbook, "Sheet 1", $oColumnA)
    $oDataB = _Excel_RangeRead($oWorkbook, "Sheet 1", $oColumnB)
    MsgBox(0, "Test Value", $oDataA & ", " & $oDataB)
EndFunc

 

Edited by gahhon

Share this post


Link to post
Share on other sites

How about:

Local $oWorkbook = _Excel_BookOpen($oExcel, $oPath, True, False)

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2019-10-24 - Version 1.4.14.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2019-11-30 - Version 1.4.0.0) - Download - General Help & Support - Example Scripts - Wiki
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
Task Scheduler (NEW 2019-12-03 - Version 1.5.1.0) - Download - General Help & Support - Wiki

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

So the Excel application AND the workbook is visible?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2019-10-24 - Version 1.4.14.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2019-11-30 - Version 1.4.0.0) - Download - General Help & Support - Example Scripts - Wiki
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
Task Scheduler (NEW 2019-12-03 - Version 1.5.1.0) - Download - General Help & Support - Wiki

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Then try:

Local $oExcel = _Excel_Open(False)
    Local $oWorkbook = _Excel_BookOpen($oExcel, $oPath, True)

 


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2019-10-24 - Version 1.4.14.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2019-11-30 - Version 1.4.0.0) - Download - General Help & Support - Example Scripts - Wiki
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
Task Scheduler (NEW 2019-12-03 - Version 1.5.1.0) - Download - General Help & Support - Wiki

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
Just now, gahhon said:

The Excel application is showed, but is empty. There's no workbook.

So it WAD ;)
To make the application invisible you have to specify this when calling _Excel_Open.
To make the workbook invisible you have to specify this when calling _Excel_BookOpen. Not needed when the whole application is invisible.

 


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2019-10-24 - Version 1.4.14.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2019-11-30 - Version 1.4.0.0) - Download - General Help & Support - Example Scripts - Wiki
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
Task Scheduler (NEW 2019-12-03 - Version 1.5.1.0) - Download - General Help & Support - Wiki

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Assume you also meant Sheet1 not "Sheet 1", you should also add _Excel_BookClose, _Excel_Close as well for example:

#include <Excel.au3>
Global $oDataA, $oDataB

ExcelRead("B2", "C2")

Func ExcelRead($oColumnA, $oColumnB)
    Local $sPath = @ScriptDir & "\MyFile.xlsx"
    Local $oExcel = _Excel_Open(False, False, False, False)
    Local $oWorkbook = _Excel_BookOpen($oExcel, $sPath, True, False)
    $sUsername = _Excel_RangeRead($oWorkbook, Default, $oColumnA)
    $sPassword = _Excel_RangeRead($oWorkbook, Default, $oColumnB)
    _Excel_BookClose($oWorkbook, False)
    _Excel_Close($oExcel)
    MsgBox(0, "Test Value", $sUsername & ", " & $sPassword)
EndFunc

 

Share this post


Link to post
Share on other sites
6 minutes ago, Subz said:

Assume you also meant Sheet1 not "Sheet 1", you should also add _Excel_BookClose, _Excel_Close as well for example:

#include <Excel.au3>
Global $oDataA, $oDataB

ExcelRead("B2", "C2")

Func ExcelRead($oColumnA, $oColumnB)
    Local $sPath = @ScriptDir & "\MyFile.xlsx"
    Local $oExcel = _Excel_Open(False, False, False, False)
    Local $oWorkbook = _Excel_BookOpen($oExcel, $sPath, True, False)
    $sUsername = _Excel_RangeRead($oWorkbook, Default, $oColumnA)
    $sPassword = _Excel_RangeRead($oWorkbook, Default, $oColumnB)
    _Excel_BookClose($oWorkbook, False)
    _Excel_Close($oExcel)
    MsgBox(0, "Test Value", $sUsername & ", " & $sPassword)
EndFunc

 

 

9 minutes ago, water said:

Then try:

Local $oExcel = _Excel_Open(False)
    Local $oWorkbook = _Excel_BookOpen($oExcel, $oPath, True)

 

Both of the solution is work fine to me. But with Subz solution, I am able to capture the ColumnB value and I dont know why. :o

And also, I did use a button trigger this function, but every 2nd time it showed the Excel Activation Error and showed 0, 0. Any idea?

Share this post


Link to post
Share on other sites

What do you mean by:

10 minutes ago, gahhon said:

Excel Activation Error

Can you please post the error message or a screen shot?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2019-10-24 - Version 1.4.14.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2019-11-30 - Version 1.4.0.0) - Download - General Help & Support - Example Scripts - Wiki
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
Task Scheduler (NEW 2019-12-03 - Version 1.5.1.0) - Download - General Help & Support - Wiki

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

image.png.27a624abd0f964964a27fc87fe0069f2.png

Here you go. Sometime it work okay, sometime are not.

If got value, then it work fine.

But if value = 0, it will showed this error.

Share this post


Link to post
Share on other sites

Is this an activated version of Excel you run?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2019-10-24 - Version 1.4.14.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2019-11-30 - Version 1.4.0.0) - Download - General Help & Support - Example Scripts - Wiki
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
Task Scheduler (NEW 2019-12-03 - Version 1.5.1.0) - Download - General Help & Support - Wiki

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
3 minutes ago, water said:

Is this an activated version of Excel you run?

Haha. No.

But I thought I open file, read and store, then close. It shouldn't be showing any error like that.

And also, When I got value from the MsgBox other than 0. It no showing any activation error.

Share this post


Link to post
Share on other sites
6 minutes ago, gahhon said:

Haha. No.

Unfortunately the Excel UDF can't help here. Active Excel and the problem will disappear ;)


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2019-10-24 - Version 1.4.14.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2019-11-30 - Version 1.4.0.0) - Download - General Help & Support - Example Scripts - Wiki
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
Task Scheduler (NEW 2019-12-03 - Version 1.5.1.0) - Download - General Help & Support - Wiki

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
1 minute ago, water said:

Unfortunately the Excel UDF can't help here. Active Excel and the problem will disappear ;)

Even the value issue?

Share this post


Link to post
Share on other sites

The Excel UDF calls Excel functions using COM. How Excel reacts to an unregistered version can't be handled by the UDF.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2019-10-24 - Version 1.4.14.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2019-11-30 - Version 1.4.0.0) - Download - General Help & Support - Example Scripts - Wiki
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
Task Scheduler (NEW 2019-12-03 - Version 1.5.1.0) - Download - General Help & Support - Wiki

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
56 minutes ago, water said:

The Excel UDF calls Excel functions using COM. How Excel reacts to an unregistered version can't be handled by the UDF.

Understood. In the meantime, then I will import the TextFile method instead. Thanks for help :D

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

  • Similar Content

    • By topgundcp
      Hi, 
      This is my very first post in this forum and am also new with Autoit programming so be easy on me.
      Below is the code that I am trying to get the index of the item selected. No problem getting the text.
      Case $listEdition   ; handle of the list             local $index=0             $item=GUICTRLRead($listEdition)    ; This will return the text in the list             ; ==============   The loop below always fails  ==================             ; Meaning _GUICtrlListView_GetItemSelected($listEdition, $i) always return FALSE. WHY ???????              For $i = 0 To $editionArray[0] - 1   ; The content of the list in an array where editionArray[0] contains total count of items                 If _GUICtrlListView_GetItemSelected($listEdition, $i) Then                     $index = $i                     exitloop                 EndIf              Next              ;===================================================             ConsoleWrite( "Select Edition:     " & $item & "  index: " & $index & @CR) ....... Please look at the comments in the code & the pix attached.
      _GUICtrlListView_GetItemSelected($listEdition, $i) always returns FALSE.
      Another problem is on the list. It also populate  the total count of items from the Array. How can I skip this item from populating to the list ?.
      Please advise and thanks

    • By n0ktar
      is it possible to make a wall chams in rainbow six siege using autoit scripts? tell me please and how . 
    • By Rskm
      Hi, I am using excel as input media for my program. The excel file (i tried with .xls, .xlsx and .xlsm format) has inputs which the autoit script reads during the run and performs few calculations. Some times (not always), after the run, when i try to open the excel file manually, the file doesnt open at all in excel. see the screenshot attached. However, if the execute the autoit script, the scripts still reads the existing data from that excel and performs the calcs. I copied the excel file to another computer and there too, it doesnt open.  So, after this, i cannot edit the excel forever (if i need to change any inputs). It is only this particular file that got affected. other excel files works normal.  What could be the problem here.  please help as this is a new challenge for me during my program development. 

    • By TheAutomator
      Hi everyone!

      I'm using AutoIt for several years now and I really get the hang of it!
      I'm quite the curious OCD perfectionist kind of guy, so I can't help wondering..
      what would be the best way to program stuff for the compiler / interpreter / scripting engine?
      We're talking about the inner workings of the AutoIt's core here, and how to give it as less friction as possible but also take care of the machine running the script.
      For example,
      Imagine a script where we would constantly have to assign a Boolean value to a variable:
      ; A: local $bool = false $bool = true $bool = true $bool = false ; B: local $bool = false check(true) check(true) check(false) func check($b) if $bool = $b then return $bool = $b endfunc In this case, would it be better to just overwrite (A) the variable or first check if we really need to (B)?
      What would be best for the computers memory if it had to do this for a year non stop?
      Another example, imagine you're writing a function with an if statement.
      If you would look under the hood of AutoIt, what would be the best way to give your computer as less work / code nesting stack filling as possible:
      ; A: func decide($b_Input) if $b_Input then ;do something else ;do something else endif endfunc ; B: func decide($b_Input) if $b_Input then ;do something return endif ;do something else endfunc Last one for now:
      ; A: while 1 ; do stuff wend ; B: while true ; do stuff wend Isn't AutoIt taking an extra step in converting 1 to a Boolean in example (A)?
      Or is it the other way around and does the (B) way make AutoIt first convert a keyword (true or false) to a numerical value (0 or 1).
      I think this kinda detail stuff is quite interesting, makes me wonder how AutoIt converts and runs our code.
      What are your opinions on this topic?
      Any coders who know more about the inner workings of AutoIt?
      Any people like me who ask themselves similar questions (with examples)?

      Let me know! 😉
×
×
  • Create New...