Code: Select all
#NoEnv
#SingleInstance Force
SetBatchLines -1
#Include ExcelToArray.ahk ; <--- This file has to be in same folder as your script
; or your Lib-directory in AutoHotKey install-path (C:\Program Files\AutoHotkey\Lib)
; otherwise, you have to determine whole path
Gui, Font, s10
Gui, Add, ListView, grid AltSubmit x22 y30 w620 h450 vLV1 gLV1 HWNDhLV -Multi, A|B|C|D|E|F|G|H
Gui, Add, Button, x+30 w110 h40 gSelector, Excel File Select
Gui, Add, Button, x+30 w110 h40 gAddRow, Add
Gui, Add, Button, x+30 w110 h40 gDeleteB, Delete
Gui, Add, Button, x+30 w110 h40 gExport, Export to Excel
Gui, Add, Edit, r3 y+50 w120 h30 vCol1,
Gui, Add, Edit, r3 w120 h30 vCol2,
Gui, Add, Edit, r3 w120 h30 vCol3,
Gui, Add, Edit, r3 w120 h30 vCol4,
Gui, Add, Edit, r3 w120 h30 vCol5,
Gui, Add, Edit, r3 w120 h30 vCol6,
Gui, Add, Edit, r3 w120 h30 vCol7,
Gui, Add, Edit, r3 w120 h30 vCol8,
LvCtrl_SetWindowTheme(hLV)
LvCtrl_SetRowHeight(80)
MainWnd := "Get Listview data from excel"
Loop, 9
LV_ModifyCol(A_Index, 75)
Gui, Show,, % MainWnd
Return
ImportData:
SplashTextOn, , , Loading...
arr := ExcelToArray(ExcelFile,,, 8)
for i, dat in arr
LV_Add("", dat*)
arr := ""
SplashTextOff
Return
GuiClose:
ExitApp
Selector:
FileSelectFile, ExcelFile , , c:\Users\POYRAZ\Desktop\1\, , Excel Files (*.xls; *.xlsx)
if ExcelFile
{
Gosub ImportData
LV_MODIFY(1, "SELECT") ; preselect first row
}
return
LV1:
if !(A_GuiEvent == "I")
return
if A_EventInfo
{
ControlGet, values, List, Selected,, ahk_id %hLV%
values := StrSplit(values, "`t")
}
else
values := ""
Loop, 8
GuiControl,, Col%A_Index%, % values[A_Index]
return
LvCtrl_SetRowHeight(Height) {
LV_SetImageList( DllCall( "ImageList_Create", Int,2, Int, Height, Int,0x18, Int,1, Int,1 ), 1 )
}
LvCtrl_SetWindowTheme(hLV) {
DllCall("UxTheme.dll\SetWindowTheme", "Ptr", hLV, "WStr", "Explorer", "Ptr", 0)
GuiControl, +LV0x14000, %hLV%
}
DeleteB:
LV_Delete()
return
AddRow:
Gui, submit, nohide
LV_Add("", Col1, Col2, Col3, Col4, Col5, Col6, Col7, Col8)
return
Export:
RowNumbers := LV_GetNext()
ControlGet, Content, List,, SysListView321, % MainWnd
Content := StrReplace(Content, "`t", "¨")
Content := StrReplace(Content, "`n", "|")
Content := StrReplace(Content, "`r")
xlApp := ComObjCreate("Excel.Application")
xlApp.Visible := True
xlApp.Workbooks.Add
xlApp.Cells.Select
xlApp.Selection.NumberFormat := "@"
xlApp.Rows("1:1").Select
xlApp.Selection.Font.Name := "Arial"
xlApp.Selection.Font.Size := 14
xlApp.Selection.Font.Bold := True
xlApp.ActiveWindow.SplitRow := 1
CList = A|B|C|D|E|F|G|H
stringsplit, inp_, CList, |
Row := 1
Columns := Object(1,"A",2,"B",3,"C",4,"D",5,"E",6,"F",7,"G",8,"H") ;array of column letters
For Key, Value In Columns
xlApp.Range(Value . Row).Value := inp_%A_Index% ;set values of each cell in a row
Faktor_Splash := Round(100/RowNumbers,5)
Progress, h80 w400,, Kopiere ausgewählte Elemente der Datenbank, Export nach Excel
Loop, parse, Content, |
{
CountSplash := Round(A_Index*Faktor_Splash)
Progress, %CountSplash%, % CountSplash . " %", Kopiere ausgewählte Elemente der Datenbank, Export nach Excel
Stringsplit, Feld_, a_LoopField, ¨
if (A_Index > 20)
break
Row := A_Index + 1
For Key, Value In Columns
xlApp.Range(Value . Row).Value := Feld_%A_Index% ;set values of each cell in a row
}
Progress, off
xlApp.Cells.EntireColumn.AutoFit
xlApp=
return