Quantcast
Channel: AutoIt v3 - General Help and Support
Viewing all articles
Browse latest Browse all 12506

Searching an Excel file

$
0
0

Hello all, I was really hoping I would figure this out on my own but so far no good.

Basicaly, what I'm trying to achieve: 

 

I need to be able to search for a username in autoit and it return the computer name for that user.

I have a list of usernames and computer names in two different columns in an Excel (.xlsx) file. 

 

I'm really struggling to grasp how the different Excel UDF stuff works. 

When I run the script shown below, I'm only getting a result of "Sheet1||$A$1993|username|username|"

I need it to return something like "username|computer-name" from column A and column B.
 

From using example scripts, this is what I have so far: 

AutoIt         
#include <Array.au3> #include <Excel.au3> #include <MsgBoxConstants.au3> ; Create application object and open an example workbook Local $oAppl = _Excel_Open() If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_RangeRead Example", "Error creating the Excel application object." & @CRLF & "@error = " & @error & ", @extended = " & @extended) Local $oWorkbook = _Excel_BookOpen($oAppl, @ScriptDir & "\Extras\_Excel1.xls") If @error Then     MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_RangeRead Example", "Error opening workbook '" & @ScriptDir & "\Extras\_Excel1.xls'." & @CRLF & "@error = " & @error & ", @extended = " & @extended)     _Excel_Close($oAppl)     Exit EndIf ; ***************************************************************************** ; Read the formulas of a cell range (all used cells in column A and B) ; ***************************************************************************** Local $aResult = _Excel_RangeRead($oWorkbook, Default, $oWorkbook.ActiveSheet.Usedrange.Columns("A:B"), 2) If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_RangeRead Example 3", "Error reading from workbook." & @CRLF & "@error = " & @error & ", @extended = " & @extended) ;MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_RangeRead Example 3", "Data successfully read." & @CRLF & "Please click 'OK' to display all formulas in column A.") _ArrayDisplay($aResult, "Excel UDF: _Excel_RangeRead Example 3 - Formulas in column A and B") ; ***************************************************************************** ; Find all occurrences of value "username" (partial match) ; ***************************************************************************** Local $aResult2 = _Excel_RangeFind($oWorkBook, "username") If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_RangeFind Example 1", "Error searching the range." & @CRLF & "@error = " & @error & ", @extended = " & @extended) ;MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_RangeFind Example 1", "Find all occurrences of value 'username' (partial match)." & @CRLF & "Data successfully searched.") _ArrayDisplay($aResult2, "Excel UDF: _Excel_RangeFind Example 1")

I'm open to any recommendations. 

I feel like there is a simple solution to this, I just can't figure it out. 

 

I can use a different way to store the username/computer name information if there is a better way. 

I have tried searching for a solution on the forums and on google and haven't found what i'm looking for. 

(I've attached what my excel spreadsheet looks like format wise)

 

 

Attached Thumbnails

  • excelexample.jpg

Viewing all articles
Browse latest Browse all 12506

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>