Keybanger Posted February 26, 2022 Posted February 26, 2022 I hope I'm posting this in the right area. If not my apologies. I've posted before but don't remember how to get to the right place. So I've written code to pull data from hundreds of excel files one file at a time. The formatting is .csv. Cell B8 has been particularly troublesome. Instead of returning the date and time as tested in a message box it is returning a bunch of pound signs. If I open the csv file sure enough B8 is pound signs there also because the column needs to be resized to fit that long string of characters that looks like this "9/16/2021 11:03:33 AM". As I mentioned I am pulling in data from hundreds of files every week and don't have time to open each one and resize the column. Does anyone know of a workaround for this. Here is the first part of my code. You won't be able to try it without the csv file obviously. My purpose for pulling the data into Autoit is to calculate and translate it into more data and then transfer the hundreds of files to a single .xlsx file for further processing. There is at least a method to my madness even if it is turning my hair gray. Thanks in advance for any help. #include <MsgBoxConstants.au3> #include <Excel.au3> GLOBAL $FileCount = 0 Global $fileLocation, $oExcel, $oWorkbook_1 Global $ExcelTicker, $ExcelEntryDateTime, $ExcelEntryPrice, $ExcelExitDateTime, $ExcelExit1Price HotKeySet('^{1}', 'DoIt') While 1 Sleep(100) WEnd Func DoIt() $FileCount += 1 $fileLocation = @ScriptDir & '\aaaTrades\Laptop ' & $FileCount &'.csv' $oExcel = _Excel_Open(0) $oWorkbook = _Excel_BookOpen($oExcel, $fileLocation) $ExcelTicker = _Excel_RangeRead($oWorkbook, Default, "G8", 3) $ExcelEntryDateTime = _Excel_RangeRead($oWorkbook, Default, "B8", 3) $ExcelEntryPrice = _Excel_RangeRead($oWorkbook, Default, "K8", 3) $ExcelExitDateTime = _Excel_RangeRead($oWorkbook, Default, "B8", 3) $ExcelExit1Price = _Excel_RangeRead($oWorkbook, Default, "K9", 3) MsgBox(0,'$ExcelEntryDateTime',$ExcelEntryDateTime) _Excel_Close($oExcel) EndFunc
Keybanger Posted February 26, 2022 Author Posted February 26, 2022 Ok I figured it out 2 minutes after posting this. I just had to change the 3 to a 1 in this line of code $ExcelEntryDateTime = _Excel_RangeRead($oWorkbook, Default, "B8", 3) My bad.
junkew Posted February 28, 2022 Posted February 28, 2022 Your hotkey suggests you do it 1 by 1 in a manual boring process. Why not loop them all directly? Maybe a 1 time loop to make your complicating column a little wider?$ColB = $oExcel.Columns("B")$ColB.ColumnWidth = 40 Please put coding like below in a code box #include <MsgBoxConstants.au3> #include <Excel.au3> GLOBAL $FileCount = 0 Global $fileLocation, $oExcel, $oWorkbook_1 Global $ExcelTicker, $ExcelEntryDateTime, $ExcelEntryPrice, $ExcelExitDateTime, $ExcelExit1Price HotKeySet('^{1}', 'DoIt') While 1 Sleep(100) WEnd Func DoIt() $FileCount += 1 $fileLocation = @ScriptDir & '\aaaTrades\Laptop ' & $FileCount &'.csv' $oExcel = _Excel_Open(0) $oWorkbook = _Excel_BookOpen($oExcel, $fileLocation) $ExcelTicker = _Excel_RangeRead($oWorkbook, Default, "G8", 3) $ExcelEntryDateTime = _Excel_RangeRead($oWorkbook, Default, "B8", 3) $ExcelEntryPrice = _Excel_RangeRead($oWorkbook, Default, "K8", 3) $ExcelExitDateTime = _Excel_RangeRead($oWorkbook, Default, "B8", 3) $ExcelExit1Price = _Excel_RangeRead($oWorkbook, Default, "K9", 3) MsgBox(0,'$ExcelEntryDateTime',$ExcelEntryDateTime) _Excel_Close($oExcel) EndFunc FAQ 31 How to click some elements, FAQ 40 Test automation with AutoIt, Multithreading CLR .NET Powershell CMDLets
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now