ExcelToArray - Read excel data to AHK array

Post your working scripts, libraries and tools
tmplinshi
Posts: 1218
Joined: 01 Oct 2013, 14:57

ExcelToArray - Read excel data to AHK array

22 Jun 2018, 03:21

Source (GitHub)

Usage
arr := ExcelToArray(FileName, nSheet, last_row, last_column)

  • FileName - The excel file path.
  • nSheet - (Optional) Sheet number. Default is 1.
  • last_row - (Optional) Last row number.
  • last_column - (Optional) Last column number.
Example of output array:

Code: [Select all] [Expand] [Download] (Untitled.txt)GeSHi © Codebox Plus




Example: Load excel data to Listview


Note: This function uses sheet.Range(cell_begin, cell_end).FormulaR1C1 (instead of .Value) to read the data, it can avoids the numbers such as 1.2 converted into 1.200000. But if the cell contains formula, the formula code itself will be read, not the actual value.

Related script: Create excel file from array or listview
Last edited by tmplinshi on 22 Jun 2018, 09:13, edited 1 time in total.
burque505
Posts: 522
Joined: 22 Jan 2017, 19:37

Re: ExcelToArray - Read excel data to AHK array

22 Jun 2018, 07:43

@tmplinshi, thank you! That works very well. Nice trick using dat* to add any number of colums.
Regards,
burque505
tmplinshi
Posts: 1218
Joined: 01 Oct 2013, 14:57

Updated to v1.1

19 Jul 2018, 11:03

Replaced ComObjGet with ComObjCreate. ComObjGet has issues on some Excel versions (or Windows version?), it will make the already opened Excel window blank.
burque505
Posts: 522
Joined: 22 Jan 2017, 19:37

Re: ExcelToArray - Read excel data to AHK array

21 Jul 2018, 10:38

Thanks for the update. This is extremely useful.
Regards, burque505

Return to “Scripts and Functions”

Who is online

Users browsing this forum: rousni and 17 guests