gpt4 book ai didi

excel - 在 Excel COM 中为 Autohotkey 创建数据透视表和图表

转载 作者:行者123 更新时间:2023-12-04 20:36:59 25 4
gpt4 key购买 nike

我正在尝试创建一个数据透视表,然后是来自 ahk 的数据透视图,用于嵌入到电子邮件中。我是个菜鸟,所以请原谅我的代码质量。我无法正确设置数据透视表,并且无法在我的一生中出现图表。我在这篇文章的底部包含了对我一直在工作的帖子的引用,以及期望的最终结果。

我的数据是两列,带有(可能没有)时间标题和警告我希望能够创建一个图表,显示随时间变化的警告数量和类型,从那里获取对象的句柄和将其放入 Outlook 电子邮件中,或者甚至只是复制粘贴对我有用。请告知如何完成这项工作,我想我已经很接近了。

编辑
我更新了下面的代码,明白了(我肯定草率地)创建了图表,我唯一缺少的是在数据透视表的图例字段中添加“警告”,并从“时间”更改轴(类别) "到 "小时"这将按小时而不是单独的时间戳对警告进行分组。如果我手动执行此操作,我似乎得到了我想要的结果。之后,我只想删除图表标题,然后将图表分配给要嵌入的对象,或者将其放到剪贴板上。

感谢您的任何帮助。

        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 dot com/board/topic/149544-table-pivot-vs-table-pivot-chart-com



自动热键点 com/board/topic/125719-com-excel-pivot-table

我正在寻找嵌入到 Outlook 电子邮件中的最终结果:

http://imgur.com/a/6baLe

样本输入:

http://p.ahkscript.org/?p=a0ceb3b1

最佳答案

两个可能的建议:

  • 搜索您想要作为 VBA 函数执行的操作(更有可能获得好的搜索结果以寻找 VBA 建议)
  • 在 Excel 中记录一个执行您想要执行的操作的宏,然后查看生成的 VBA 代码。换句话说,在录制宏的同时制作图表并删除标题,然后看看它是否为您提供了任何好的代码。在某些情况下,这会起作用,在某些情况下则不会。

  • 使用这些方法中的任何一种都有望让您确定需要将哪些代码或函数转换为脚本。

    关于excel - 在 Excel COM 中为 Autohotkey 创建数据透视表和图表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40828909/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com