Jump to content
Sign in to follow this  
helebek

Excel to IE decimal change

Recommended Posts

helebek

Hi,

I have script that reads and array of values from an Excel Worksheet.

I live in Turkey and in Turkish decimal separator is "," (comma). In my Excel all my data use "," as a decimal separator.

However, when I read these values with AutoIt and then output it (at different place, stdout, msgbox, set IE form values etc.) I always get a "." (period) for the decimal separator. I tried assigning the data to string and then do a stringreplace, but that didn't succeed either. Any idea how to play with the decimal separator character? Maybe it is an internal AutoIt option?

BTW: All my local settings in windows point to the local regional settings ("," as decimal separator).

Many Thanks.

Share this post


Link to post
Share on other sites
helebek

post your code. I suspect your stringreplace needs tweaking

Local $value = String(Round($data_values[$i],2))
StringReplace($value, ".", ",")

Does the "." and "," need some kind of escape character?

Thx.

Share this post


Link to post
Share on other sites
JLogan3o13

Your StringReplace works fine if a simple string is inputted as $value. Can you post the whole script, or a short reproducer, so we can see how you're defining the array?


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites
helebek

#include <IE.au3>
#include <Excel.au3>
#include <Array.au3>

Opt("WinTitleMatchMode", 2)


Local $oExcel = _ExcelBookAttach("my_excel_file.xls", "FileName")
Local $aArray1 = _ExcelReadSheetToArray($oExcel, 2, 5,60, 11)

Local $num_rows = UBound($aArray1) - 1


If not WinExists("Sample") Then
MsgBox(0, "", "Window does not exists")
Exit
EndIf


WinActivate("Sample")
WinWaitActive("Sample")

MouseClick("left", 113, 240, 1, 0)
Sleep(10000)


Local $oIE = _IEAttach("Sample")

For $i = 1 To $num_rows Step 1

ConsoleWrite("i = "& $i & Chr(13))


;Get the frame!
Local $oFrame = _IEFrameGetObjByName($oIE, "Frame")

Local $oForm = _IEFormGetObjByName($oFrame, "Form")

Local $oText = _IEFormElementGetObjByName($oForm, "ID")
_IEFormElementSetValue($oText, $aArray1[$i][1])

Local $oSelect = _IEFormElementGetObjByName($oForm, "Name")
_IEFormElementOptionSelect($oSelect, "X1", 1, "byText")
Sleep(2000)

Local $oSelect = _IEFormElementGetObjByName($oForm, "Coast")
_IEFormElementOptionSelect($oSelect, "X2", 1, "byText")

Local $oSelect = _IEFormElementGetObjByName($oForm, "Type")
_IEFormElementOptionSelect($oSelect, $aArray1[$i][2], 1, "byText")


Local $oText = _IEFormElementGetObjByName($oForm, "latDeg")
_IEFormElementSetValue($oText, $aArray1[$i][5])

Local $oText = _IEFormElementGetObjByName($oForm, "latMin")
_IEFormElementSetValue($oText, $aArray1[$i][6])

Local $oText = _IEFormElementGetObjByName($oForm, "latSec")
_IEFormElementSetValue($oText, $aArray1[$i][7])

Local $oText = _IEFormElementGetObjByName($oForm, "latHemis")
_IEFormElementSetValue($oText, "N")


Local $oText = _IEFormElementGetObjByName($oForm, "lonDeg")
_IEFormElementSetValue($oText, $aArray1[$i][9])

Local $oText = _IEFormElementGetObjByName($oForm, "lonMin")
_IEFormElementSetValue($oText, $aArray1[$i][10])

Local $oText = _IEFormElementGetObjByName($oForm, "lonSec")
Local $value = String(Round($aArray1[$i][11], 2))
StringReplace($value, ".", ",")
_IEFormElementSetValue($oText, $value)

Local $oSubmit = _IEFormElementGetObjByName($oForm, "submit")
_IEAction($oSubmit, "click")
_IELoadWait($oIE)
Sleep(10000)

Next

My Excel file for the given columns basically includes this data (columns 5, 6, 7, 9, 10, 11)

27 53 18,42 E 40 56 24,84
Edited by helebek

Share this post


Link to post
Share on other sites
helebek

I am not sure what was wrong, but eventually I exported my excel table to a tab separated text file and proceeded with the text file without any problem. I suspect it was a conversion problem while AutoIt was reading the excel cells.

Thx.

Share this post


Link to post
Share on other sites
Juvigy

Autoit converts on the fly when possible whithout complaining, so if you want to make sure something is String or a Number use the functions String() or Number().

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.