Jump to content
Sign in to follow this  
Andy2520

Need small help to read excel cell .

Recommended Posts

Andy2520

Dear Team,

I am creating one script it should read the content of Ms excel cell if content is there script should process .If content is not there in cell script should exit with msg box .

Here is the code  .could you please help me in the same  .

#include <Excel.au3>
#include <MsgBoxConstants.au3>

Local $oExcel = _ExcelBookOpen("d:\ani.xls",0)
;Local $oExcel = _ExcelBookNew() ;Create new book, make it visible

;For $i = 1 To 5 ;Loop
   ; _ExcelWriteCell($oExcel, $i, $i, 1) ;Write to the Cell
;Next

Local $sCellValue, $sCellValue1 ,$splitsrname1,$splitsrnameyear,$splitsrnamedate,$splitsrnamemonth,$splitsrnamemonth1
For $i = 2 To 3
;Loop
    $sCellValue = _ExcelReadCell($oExcel, $i, 1)
    $sCellValue1 = _ExcelReadCell($oExcel, $i, 2)
    $splitsrname1 = StringLeft($sCellValue1, 8)
    $splitsrnameyear = StringLeft($splitsrname1,4)
    $splitsrnamedate = Stringright($splitsrname1,2)
    $splitsrnamemonth =Stringright($splitsrname1,4)
    $splitsrnamemonth1 =StringLeft($splitsrnamemonth,2)
    dim $DOB =$splitsrnamedate&$splitsrnamemonth1&$splitsrnameyear
    MsgBox($MB_SYSTEMMODAL, "", "The Cell Value is: " & @CRLF & $sCellValue, 2)
    MsgBox($MB_SYSTEMMODAL, "", "The Cell Value is: " & @CRLF & $splitsrnameyear , 2)
    MsgBox($MB_SYSTEMMODAL, "", "The Cell Value is: " & @CRLF & $splitsrnamedate  , 2)
    MsgBox($MB_SYSTEMMODAL, "", "The Cell Value is: " & @CRLF & $splitsrnamemonth1 , 2)
    MsgBox($MB_SYSTEMMODAL, "", "The Cell Value is: " & @CRLF & $DOB, 2)
    if $sCellValue =" " then
       MsgBox($MB_SYSTEMMODAL, "test", "there is no data in cell now exit")
       Exit
     EndIf
Next
Edited by Andy2520

Share this post


Link to post
Share on other sites
water

Doesn't look bad. What doesn't work?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - 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
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
Andy2520

Thanks Water for your reply!! .

if one cell is empty or doesnot have any content it should exit the script .in above code script reading till last cell i.e For $i = 2 To 3.

I need as soon as if get empty value frm cell it should exit .

Share this post


Link to post
Share on other sites
water

Could you test for cells with no content ("")? Now you test for cells with a space as content:

if $sCellValue = "" then
Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - 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
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
Andy2520

Thanks Water :)

So sorry i have asked stupid help ..Simple issue . tried its working fine  .. thank you so much :)

Share this post


Link to post
Share on other sites
water

:)


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - 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
 
Tutorials:

ADO - Wiki

 

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  

  • Similar Content

    • ralph_ng
      By ralph_ng
      Hi everybody, I'm newbie to learn AutoIt, need some help... The process/ work that I'd like to automate is just for testing purpose for my job.
      Searching high and low, I found no script example for writing any random data into excel file. 
×