Jump to content
SkysLastChance

[SOLVED] _Excel_RangeRead & Excel Formats Question

Recommended Posts

SkysLastChance

I am not sure what is happing at all, unfortunatlly there is no way I can put a full running code. When I enter the first and last name it works fine, However when I get to the date of birth it puts in '19760703000000' 

 

I can't figure out why "7/3/1976" is the value before the formant and "07031976" is after the format. 

 

I want it to pull the value after the format. "07031976"

 

 

$r = 1

Local $aArray = _Excel_RangeRead($oExcel, Default, Default,Default,False)

For $i = 1 To UBound($aArray) - 1   ;$i =0 Start from row A
      $sR1 = $aArray[$i][0]     ;status
      $sR2 = $aArray[$i][1]     ;first name
      $sR3 = $aArray[$i][2]     ;Last name
      $sR4 = $aArray[$i][4]     ;DOB
      $sR5 = $aArray[$i][5]     ;Email Address




WinWaitActive ("[CLASS:Notepad]")
ControlSend("[CLASS:Notepad]", "", "Edit1", $sR3 & ',' & $sR2 & @CR)
Sleep (2000)
ControlSend("[CLASS:Notepad]", "", "Edit1",("{TAB}"))
Sleep (3000)
ControlSend("[CLASS:Notepad]", "", "Edit1", $sR4 & @CR)
ControlSend("[CLASS:Notepad]", "", "Edit1",("{ENTER}"))
ControlSend("[CLASS:Notepad]", "", "Edit1",("{F12}")




$r = $r + 1
If $r > $sBox Then
   Exit
   Endif

Next

auto it demo.xlsx - excel that I am using.

Edit: I also want to mention I have tried

Local $aArray = _Excel_RangeRead($oExcel, Default, Default,3)

When I do this not even the name first and last name will write.

Edited by SkysLastChance

Life's simple. You make choices and you don't look back.

Share this post


Link to post
Share on other sites
water

The value 3 reads the displayed/formatted value. Unfortunately MS only supports to read a single cell with this parameter. 

All other values return the internal representation of the date. 

Please check the wiki for a detailed description of how Excel stores dates. 

  • Like 1

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (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
SkysLastChance

Hmmm okay. Is this really my best option?

 

1. Copy the original Data
2. Paste to Notepad (Prefer Notepad++)
3. Change the Cell Properties to TEXT
4. Copy All from Notepad
5. Paste back to Excel.

Life's simple. You make choices and you don't look back.

Share this post


Link to post
Share on other sites
water

No. If you check the wiki you will find a script that translates the internal dates you get from _Excel_RangeRead into the date format you require.

Edited by water
  • Like 1

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (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
SkysLastChance

You have did it once again. HAHA I cant figure ot how to do MM/DD/YYYY though. 

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

Func _ConvertSerialDateTime($nDT) ; this function is here to convert excel date valuse to numbers
    Local Const $dtExcel = '1899/12/31'
    Local $iDate = Int($nDT) - 1 ; Adjusted after reading wiki and why result is 1 day to much: http://www.cpearson.com/excel/datetime.htm
    Local $iTime = Mod($nDT, 1)
    $iTime = Int(24 * 3600 * $iTime)
    $dtRes = _DateAdd('D', $iDate, $dtEXcel)
    $dtRes = _DateAdd('s', $iTime, $dtRes)
    Return $dtRes
EndFunc



$r = 1

Local $aArray = _Excel_RangeRead($oExcel, Default, Default,4)

For $i = 1 To UBound($aArray) - 1   ;$i =0 Start from row A
      $sR1 = $aArray[$i][0]     ;status
      $sR2 = $aArray[$i][1]     ;first name
      $sR3 = $aArray[$i][2]     ;Last name
      $sR4 = $aArray[$i][4]     ;DOB
      $sR5 = $aArray[$i][5]     ;Email Address




WinWaitActive ("[CLASS:MGUIWin]")
ControlSend("[CLASS:MGUIWin]", "", "Edit2", $sR3 & ',' & $sR2 & @CR)
Sleep (2000)
ControlSend("[CLASS:MGUIWin]", "", "",("{TAB}"))
Sleep (3000)
ControlSend("[CLASS:MGUIWin]", "", "", (_ConvertSerialDateTime($sR4) & @CR))





$r = $r + 1
If $r > $sBox Then
   Exit
   Endif

Next

 


Life's simple. You make choices and you don't look back.

Share this post


Link to post
Share on other sites
water

Your case is even simpler. When you use Parameter = 1 then you get "19760703000000". This is YYYYMMDDHHMMSS.
So either use Stringformat, String* functions or a RegExp to format the string to your liking.

  • Like 1

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (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
SkysLastChance

 

ControlSend("[CLASS:MGUIWin]", "", "", (_ConvertSerialDateTime & StringFormat("%02i\%02i\%04i",($sR4)) & @CR))

how far off am I here.


Life's simple. You make choices and you don't look back.

Share this post


Link to post
Share on other sites
water

_ConvertSerialDateTime is not needed with the format you get (I mentioned the format in post #6).

I can't test at the moment but you need to grab the left 4 characters for year, then 2 for month and again 2 for day and then re-arrange this 3 fields in the sequence you need.

Edited by water
  • Like 1

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (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
SkysLastChance
Func FormatDate($DATE)
    $SPLIT = StringSplit($DATE," ")
    $MM = StringMid($SPLIT[1],5,2)
    $YYYY = StringLeft($SPLIT[1],4)
    $DD = StringMid($SPLIT[1],7,2)
    Return $MM & "/" & $DD & "/" & $YYYY
EndFunc


ControlSend("[CLASS:MGUIWin]", "", "", (FormatDate($sR4) & @CR))

How does that grab you?


Life's simple. You make choices and you don't look back.

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

    • ajblandford
      By ajblandford
      I have embeded an Excel file in my autoit Script and want to use it as part of my GUI. I want to be able to select a range of cells and add the cell data to an edit box. Then dump that data to an array. I am using GUICtrlCreateObj to embed the spreadsheet. I cannot find any way to let my program see what cells are active so I can add that data to the edit box. 
       
      #include <WindowsConstants.au3> #include <GUIConstantsEx.au3> #include <excel.au3> $FileName = 'C:\VLog\book1.xlsx' If Not FileExists($FileName) Then MsgBox(0, "ERROR", "File not found") Exit EndIf ;Basic GUI $oExcelDoc = ObjGet($FileName) ; Get an excel Object from an existing filename If IsObj($oExcelDoc) Then $mainGUI = GUICreate("Production Room 2", 1800, 1200, 10, 10, $WS_MINIMIZEBOX + $WS_SYSMENU + $WS_CLIPCHILDREN) $GUI_ActiveX = GUICtrlCreateObj($oExcelDoc, 10, 70, @DesktopWidth - 250, @DesktopHeight - 260) $data = GUICtrlCreateEdit("", @DesktopWidth - 225, 75, 100) $btn = GUICtrlCreateButton( "GO", @DesktopWidth - 100, 75, 75) Else MsgBox(0, "", "failed") EndIf ;------------------ ;Turns off all command bars in excel to prevent user from making changes For $Bar In $oExcelDoc.CommandBars If $Bar.Enabled = True Then $Bar.Enabled = False If $Bar.Visible = True Then $Bar.Visible = False Next $oExcelDoc.Application.DisplayFormulaBar = False $oExcelDoc.Application.CommandBars("Shadow Settings").Visible = False $oExcelDoc.Application.DisplayScrollBars = True $oExcelDoc.Application.DisplayStatusBar = False GUISetState()  
    • Skeletor
      By Skeletor
      Hi Virtual People,
      My array works perfectly fine. However, what is the best practice if the line in the array doesn't have the correct amount of columns and if I can add a placeholder?

       
      For $count = 1 To _FileCountLines($FileRead1) Step 1 $string = FileReadLine($FileRead1, $count) $input = StringSplit($string, ",", 1) $value1 = $input[1] $value2 = $input[2] $value3 = $input[3] _Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, $value2, "A1") _Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, $value1, "B1") _Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, $value3, "C1") Next  
    • Skeletor
      By Skeletor
      Hi Guys,
      Can anyone point me in the right direction. I'm trying to accomplished conditional formatting with arrows, but the code I have is wrong... 
      .Range("=$A3:$A4000").FormatConditions.Add = (xlCellValue, xlGreater, "=$A:$A") .IconSet(xl3Arrows) ;ActiveWorkbook.iconsets I also tried it like this:
      .Range("=$A3:$A4000").FormatConditions _ .Add(xlCellValue, xlGreater, "=$A:$A") .IconSet(xl3Arrows) ;ActiveWorkbook.iconsets  
    • MrCheese
      By MrCheese
      hi all,
      reviewing the forum, this thread is applicable: 
       
       
      I wanted to know if there is now a better way to do this?
      In essence, I load a tab delimited txt file into an array (works well). I used tab, as some fields in the original csv contains commas.
      However, I needed autoit to manipulate this array, and output it as a csv.
      IF my array contains items with a comma, without double quotes around the field, then how best do I get a csv out of this?
      My current workaround is to filewritefromarray tab delimited, then open it in excel and save as a csv. I will need to check this to see how the address fields behave that contain a comma.
       
      Any thoughts would be appreciated.
       
    • Skeletor
      By Skeletor
      Hi Guys,
      How would you use _Excel_FilterSet to filter the excel sheet from largest number to smallest number?
      _Excel_FilterSet($oWorkbook, "Sheet1", "A2:I2", 1, ">20", 1, "<40") ; OR _Excel_FilterSet($oWorkbook, "Sheet1", "A2:I2", 1, ">", 1, "<") Excel Sheet attached. Trying to filter on the last column "I2"
      Inventory.xlsx
×