Wellwellwell Posted March 10, 2021 Posted March 10, 2021 Hi, I am very new to AutoIt, My goal is to copy a text content paste into excelsheet. Below are simple program are suppose to: 1.) Open a text file 2.) Copy A2 content in the text file 3.) Open Excel sheet 4.) Paste the Text content to the Excel sheet D1 The problem occured when i use _Excel_RangeRead(), no matter what content in the text file it always return 0. #include <File.au3> #include <Excel.au3> Local $aField1[2] = [1, $xlGeneralFormat] Local $aField2[2] = [2, $xlTextFormat] Local $aField3[2] = [3, $xlGeneralFormat] Local $aField4[2] = [4, $xlDMYFormat] Local $aField5[2] = [5, $xlTextFormat] Local $aFieldInfo[5] = [$aField1, $aField2, $aField3, $aField4, $aField5] Local $Excel_1 = _Excel_Open() Local $Workbook = "C:\Users\Z\Desktop\Autoit Testing\Text.txt" _Excel_BookOpenText($Excel_1, $Workbook, Default, $xlDelimited, Default, True, "|", $aFieldInfo, ",", ".") WinActivate($Workbook) Local $read2 = _Excel_RangeRead($Workbook, Default, "A2") MsgBox(0,"Read",$read2) Local $Excel_2 = _Excel_Open() Local $pWorkbook2 = "C:\Users\Z\Desktop\Autoit Testing\Book2.xls" Local $Workbook2 = _Excel_BookOpen($Excel_2, $pWorkbook2) WinActivate($Workbook2) _Excel_RangeWrite($Workbook2, Default, $read2, "D1") Text file content: May i know can _Excel_RangeRead() use in this way? or why this code doesnt not work? Thank you!
Nine Posted March 10, 2021 Posted March 10, 2021 (edited) Please use this tool when you post code. You were mixing string and object : #include <Excel.au3> Local $Excel_1 = _Excel_Open() Local $sWorkbook = @ScriptDir & "\Test.txt" Local $oWorkbook = _Excel_BookOpenText($Excel_1, $sWorkbook);, Default, $xlDelimited, Default, True, "|", $aFieldInfo, ",", ".") ConsoleWrite (@error & @CRLF) ; WinActivate($Workbook) Local $read2 = _Excel_RangeRead($oWorkbook, Default, "A2") MsgBox(0,"Read",$read2) Local $Excel_2 = _Excel_Open() Local $pWorkbook2 = @ScriptDir & "\Test.xls" Local $Workbook2 = _Excel_BookOpen($Excel_2, $pWorkbook2) ;WinActivate($Workbook2) _Excel_RangeWrite($Workbook2, Default, $read2, "D1") Edit : adding some error handling helps understand what the problems are Edited March 10, 2021 by Nine Wellwellwell 1 “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Debug Messages Monitor UDF Screen Scraping Round Corner GUI UDF Multi-Threading Made Easy Interface Object based on Tag
FrancescoDiMuro Posted March 10, 2021 Posted March 10, 2021 51 minutes ago, Nine said: Edit : adding some error handling helps understand what the problems are Which it has already been suggested, but seems that the OP is a "post and quit" fan. Wellwellwell 1 Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette
Nine Posted March 10, 2021 Posted March 10, 2021 I see...It is not very good to be remembered for those kinds of reasons FrancescoDiMuro 1 “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Debug Messages Monitor UDF Screen Scraping Round Corner GUI UDF Multi-Threading Made Easy Interface Object based on Tag
Wellwellwell Posted March 11, 2021 Author Posted March 11, 2021 Hi, Sorry if i am not replying on time, Let me put some error log and check again. I not sure how to proper error log as well. So you are saying _Excel_RangeRead return string? i should not use _Excel_RangeRead to read the _Excel_BookOpenText ? thanks ZY
Subz Posted March 11, 2021 Posted March 11, 2021 As Nine mentioned: Local $oWorkbook = _Excel_BookOpenText($Excel_1, $Workbook, ...) _Excel_RangeRead($oWorkbook, ...) not _Excel_RangeRead($Workbook, ...) Wellwellwell 1
Wellwellwell Posted March 11, 2021 Author Posted March 11, 2021 Hi Nine and Subz, Thank you very much, it could read correct value now. Thanks!
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