Thank you so much
@tmplinshi, now AHK class is more clear to me,
tmplinshi wrote: ↑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.
comobjget working for me, it was because of line 77 condition "if last_row && last_column" the code did not worked for me I changed it
Code: Select all
ExcelToArray(FileName, nSheet := 1, last_row := "", last_column := "")
{
return ExcelToArray.DoIt(FileName, nSheet, last_row, last_column)
}
class ExcelToArray
{
DoIt(FileName, nSheet := 1, last_row := "", last_column := "")
{
if !FileExist(FileName)
throw, "File Not Exist!"
safeArr := this.GetSafeArrFromXlFile(FileName, nSheet, last_row, last_column)
ret := this.SafeArr_To_AHKArr(safeArr)
return ret
}
GetSafeArrFromXlFile(FileName, nSheet := 1, last_row := "", last_column := "")
{
fPath := this.GetFullPath(FileName)
if !wb {
wb:= ComObjGet(fPath)
}
safeArr := this.GetSafeArr(wb, nSheet, last_row, last_column)
xlObj.Quit
return safeArr
}
SafeArr_To_AHKArr(SafeArr)
{
ret := []
rowCount := SafeArr.MaxIndex(1)
colCount := SafeArr.MaxIndex(2)
Loop, % rowCount
{
row := A_Index
arr := []
Loop, % colCount
arr.push( SafeArr[row, A_Index] )
ret.push(arr)
}
return ret
}
GetSafeArr(oWorkbook, nSheet := 1, last_row := "", last_column := "")
{
sheet := oWorkbook.Sheets(nSheet)
if (last_row = "") or (last_column = "")
return sheet.UsedRange.FormulaR1C1
else
{
cell_begin := sheet.cells(1, 1)
cell_end := sheet.cells(last_row, last_column)
return safeArr := sheet.Range(cell_begin, cell_end).FormulaR1C1
}
}
GetFullPath(FileName)
{
Loop, % FileName
return A_LoopFileLongPath
}
}
"When there is no gravity, there is absolute vacuum and light travel with no time" -Game changer theory