我想創建一個數據透視表,然後從ahk創建一個數據透視表以嵌入到電子郵件中。我是一個完全noob,所以請原諒我的代碼質量。我無法讓數據透視表正確設置,並且無法爲我的生活出現圖表。我已經列出了我一直在處理的帖子的引用,以及本帖子底部的最終結果。創建數據透視表和圖表在Excel COM for Autohotkey
我的數據是兩列,帶有(可以使它不帶)時間標題,並且警告我希望能夠創建一個圖表,顯示數量和隨着時間的推移的警告類型,從那裏得到一個句柄在對象上,並將其放入Outlook電子郵件,甚至只是一個副本粘貼將爲我工作。請告知如何完成這件事,我想我非常接近。
編輯 我更新了下面的代碼,它得到的點(馬虎IM肯定),該圖被創建,唯一的東西我在想念透視表中添加「警告」傳說場,並將Axis(分類)從「時間」更改爲「小時」,這將按小時而不是單個時間戳將警告分組。如果我手動這樣做,我似乎得到了我想要的結果。之後,我只想刪除圖表標題,然後將圖表分配給要嵌入的對象,或者將其放到剪貼板上。
謝謝你的幫助。
f1::Reload
Pause::Pause
f2::ListVars
Pause
!`::
function()
return
function()
{
when:=[]
what:=[]
Nothing:="Nothing to report, have a wonderful day."
TMP:=""
RMRKS:=""
Date1:=""
Date2:=""
EMOUT:=""
EMIN := Clipboard ; Email text var
Loop, Parse, EMIN,`n,`r ; parse email by line
{
tmp := StrSplit(A_LoopField, ";") ; for each line break it into chunks by ";"
rmrks := tmp.6 ; Warn code is in 6th index
If (InStr(rmrks, "Warning")) ; If this is a warning line
{
date1:=StrSplit(tmp.1, "/") ; date/time is in DD/MM/YYYY , split it up by "/"
date2= % date1.2 "/" date1.1 "/" date1.3 ; Rearrange the date into MM/DD/YYYY
EMOUT .= date2 "`t" rmrks "`n" ; Push into VAR "11/24/2016 13:40:45 WARNING MESSAGE"
}
}
EMOUT := StrReplace(EMOUT,"""") ; Replace all of the quotes in the var with Null
Loop, Parse, EMOUT,`n,`r ; Split output by line and then...
{
tmp := StrSplit(A_LoopField, ["`t"]) ; split lines by tab
when.insert(tmp.1) ; insert date/time stamp into "when" array
what.insert(tmp.2) ; insert Warn Code into "what" array
}
if (emout!="") ; If there was stuff to put into array
{
XL := ComObjCreate("Excel.Application") ; create an excel object
wbk := xl.Workbooks.Add ; add a workbook to the object
Xl.Visible := True ; make it visible
XL.Range("A1").Value := "Time" ;Create Time header
XL.Range("A:A").columnwidth := "20"
XL.Range("B:B").columnwidth := "56.86"
XL.Range("B1").Value := "Warning" ; Create Warning Header
for index in when
Xl.Range("A" . index+1).Value := when[index] ;add everything in the "when" array
for index in what
Xl.Range("B" . index+1).Value := what[index] ;add everything in the "what" array
rng := xl.Sheets(1).UsedRange.address
trgt := xl.Sheets(1).range("c1")
pvt := xl.ActiveWorkbook.PivotCaches.Create(xlDatabase:=1, rng, xlPivotTableVersion12:=3).CreatePivotTable(trgt, "PivotTable1", ,xlPivotTableVersion12:=3)
pvt.PivotFields("warning").Orientation := 1
pvt.PivotFields("warning").Position := 1
pvt.PivotFields("time").Orientation := 1
pvt.PivotFields("time").Position := 2
pvt.AddDataField(pvt.PivotFields("Warning"), "Count of Warning", -4112)
Sheet := xl.Sheets(1)
Sheet.Shapes.AddChart.Select
wbk.ShowPivotChartActiveFields := false
xl.ActiveChart.ChartType := 51
xl.ActiveChart.PivotLayout.PivotTable.PivotFields("Warning").Orientation = xlColumnField
xl.ActiveChart.PivotLayout.PivotTable.PivotFields("Warning").Position = 1
return
}
if (emout="")
Msgbox, %Nothing%
Reload
}
我從工作源論壇的帖子是
AutoHotkey的點com /板/主題/ 149544表樞軸-VS-表樞軸表-COM
和
autohotkey dot com/board/topic/125719-com-excel-pivot-table
最終結果我在尋找嵌入Outlook電子郵件:
樣品輸入:
http://p.ahkscript.org/?p=a0ceb3b1