ListView数据或数组生成Excel

许多实用脚本和封装函数, 可以让您编写脚本更加便捷高效
tmplinshi
Posts: 1087
Joined: 01 Oct 2013, 14:57

ListView数据或数组生成Excel

26 Sep 2015, 10:40

生成 Excel 文件主要有几下几个方法:
  1. 把数据保存到剪贴板,然后一次性粘贴到 Excel
  2. 逐个设置每个单元格的数据...
  3. 设置 Excel 某个矩形区域的值为安全数组(SafeArray)
    示例

Class_Excel.ahk 用的是方法3。

例1 - 用数组生成 Excel 文件

Code: [Select all] [Download] (例1 - 用数组生成 Excel 文件.ahk)GeSHi © Codebox Plus

#Include Class_Excel.ahk

arr := [ ["编程语言", "官网"]
, ["AutoHotkey", "http://ahkscript.org"]
, ["aardio", "http://bbs.aau.cn/"] ]

Excel.CreateByArray("test.xlsx", arr)


例 2 - 用 ListView 数据生成 Excel 文件

Code: [Select all] [Expand] [Download] (例 2 - 用 ListView 数据生成 Excel 文件.ahk)GeSHi © Codebox Plus



Class_Excel.ahk --> https://gist.github.com/tmplinshi/7e2d75794e58def0d43e
bolang
Posts: 2
Joined: 14 Jan 2014, 09:44

Re: ListView数据或数组生成Excel

29 Oct 2015, 04:59

谢谢,最近一直在处理excel,用VBA方便很多。
Marvin1023
Posts: 45
Joined: 10 Nov 2015, 12:49

Re: ListView数据或数组生成Excel

07 Dec 2016, 23:10

This work with [Class] LV_Colors ?
Asus Maximus VIII Extrême - DDR4 16Go - Intel Core i7 - GTX 1080
tmplinshi
Posts: 1087
Joined: 01 Oct 2013, 14:57

Re: ListView数据或数组生成Excel

07 Dec 2016, 23:37

Marvin1023 wrote:This work with [Class] LV_Colors ?

Hi, this library is used to creating Excel file, data either from array or listview.

  • Excel.CreateByArray(OutputFileName, InputArray)
  • Excel.CreateByHLV(OutputFileName, ListViewHwnd)

LV_Colors does not affect ListView data. So yes.
Marvin1023
Posts: 45
Joined: 10 Nov 2015, 12:49

Re: ListView数据或数组生成Excel

07 Dec 2016, 23:41

Thank for reply
I will look at how to add color in excel file.
Asus Maximus VIII Extrême - DDR4 16Go - Intel Core i7 - GTX 1080
tmplinshi
Posts: 1087
Joined: 01 Oct 2013, 14:57

Re: ListView数据或数组生成Excel

08 Dec 2016, 00:13

Oh, I misunderstood you question before. I thought you were asking "is it working", but your real qustion is "Does this library save cell colors as well to the Excel file?". :) Well, I'll have a try.
tmplinshi
Posts: 1087
Joined: 01 Oct 2013, 14:57

Re: ListView数据或数组生成Excel

08 Dec 2016, 02:41

v1.01 (2016-12-8) - Added support for saving listview cell colors

Example:

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus

tmplinshi
Posts: 1087
Joined: 01 Oct 2013, 14:57

Re: ListView数据或数组生成Excel

08 Dec 2016, 04:19

v1.02 (2016-12-8) - Fixed some color bugs
Marvin1023
Posts: 45
Joined: 10 Nov 2015, 12:49

Re: ListView数据或数组生成Excel

08 Dec 2016, 10:14

Omg. good job :)
Asus Maximus VIII Extrême - DDR4 16Go - Intel Core i7 - GTX 1080
Marvin1023
Posts: 45
Joined: 10 Nov 2015, 12:49

Re: ListView数据或数组生成Excel

08 Dec 2016, 14:22

work with LV_Colors.Cell() and LV_Colors.Row()

Can you add LV_Colors.AlternateRows() and LV_Colors.AlternateCols() And Title column of Gui ListView.

I think your script will be complete.

Thank you.
Asus Maximus VIII Extrême - DDR4 16Go - Intel Core i7 - GTX 1080
tmplinshi
Posts: 1087
Joined: 01 Oct 2013, 14:57

Re: ListView数据或数组生成Excel

09 Dec 2016, 04:03

Done.

Code: [Select all] [Download] GeSHi © Codebox Plus

v1.03 (2016-12-9) - Added support for LV_Colors's AlternateRows/AlternateCols
- Added 'IncludeLvHeader' option
Marvin1023
Posts: 45
Joined: 10 Nov 2015, 12:49

Re: ListView数据或数组生成Excel

09 Dec 2016, 05:20

Powerful :roll:
thank you very much :)

with two listview or more use:

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

Asus Maximus VIII Extrême - DDR4 16Go - Intel Core i7 - GTX 1080
tmplinshi
Posts: 1087
Joined: 01 Oct 2013, 14:57

Re: ListView数据或数组生成Excel

09 Dec 2016, 08:38

You're welcome. :)

I modified a bit.
v1.04 (2016-12-9) - 'IncludeLvHeader' option now doesn't need to change default listview

Return to “脚本函数”

Who is online

Users browsing this forum: No registered users and 1 guest