找回密码
 加入
搜索
查看: 10563|回复: 10

[GUI管理] 怎样实现选择多个ListView内的行导出EXCEL[已解决]

 火.. [复制链接]
发表于 2011-8-20 05:20:57 | 显示全部楼层 |阅读模式
本帖最后由 清风飘飘 于 2011-8-25 18:33 编辑

最近写数据库操作时遇到了一个问题,搜索到以前朋友的代码,可以实现导出整个ListView内的项目到Excel,我想改成选择单个或多个的导出,改了半夜代码也没有搞清楚,特来请教朋友们帮我改一下,最好能注释一下,英语不咋地,那帮助文档有些英文介绍看不太懂,金山词霸翻译的又不对头。谢谢啦!

别人的代码:
#include <Excel.au3>
#include <Array.au3>
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <ListViewConstants.au3>
#include <TabConstants.au3>
#include <WindowsConstants.au3>
Local $ListView[2], $Test[2] = ["编号|姓名|QQ号码"]
$Form1 = GUICreate("Form1", 623, 444, 192, 124)
$ListView[0] = GUICtrlCreateListView($Test[0], 40, 64, 530, 294)
GUICtrlCreateListViewItem('1|张三|65786315', $ListView[0])
GUICtrlCreateListViewItem('2|李四|56454688', $ListView[0])
GUICtrlCreateListViewItem('3|王五|86575765', $ListView[0])
GUICtrlCreateListViewItem('4|孙六|87654832', $ListView[0])
GUICtrlCreateListViewItem('5|赵七|96325478', $ListView[0])
GUICtrlCreateListViewItem('6|成八|64651873', $ListView[0])
GUICtrlCreateListViewItem('7|冯九|96437251', $ListView[0])
GUICtrlCreateListViewItem('8|钱十|64976835', $ListView[0])
$Button1 = GUICtrlCreateButton("导出Excel", 40, 384, 75, 25)
GUISetState(@SW_SHOW)
While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit
                                        Case $Button1
                                                new()
        EndSwitch
WEnd


Func new()
        Local $array[1]
                        For $i = 0 To UBound($ListView) - 1
                                $Count = _GUICtrlListView_GetItemCount($ListView[$i])
                                _ArrayAdd($array, $Test[$i])
                                If $Count <> 0 Then
                                        For $ii = 0 To $Count - 1
                                                _ArrayAdd($array, _GUICtrlListView_GetItemTextString($ListView[$i], $ii))
                                        Next
                                EndIf
                        Next
                        $excel = _ExcelBookNew(1)  ;创建一个新的工作表并设置显示,(0=不可见, 1=可见)
                        For $i = 1 To UBound($array) - 1   ;返回数组维度的大小
                                $htest = StringSplit($array[$i], "|")  ;以指定分隔符把字符串拆分成若干子串
                                For $ii = 0 To $htest[0]
                                        _ExcelWriteCell($excel, $htest[$ii], $i, $ii)
                                Next
                                                        Next
                                                EndFunc
                                                
参考别人的代码已经解决:首先获取到选中的项目数量,然后循环获取每个选中的值,添加到数组,导入EXCEL即可。
发表于 2011-8-21 12:16:48 | 显示全部楼层
ListView选中事件,有很过例子的。论坛里很多ListView操作都有这个!
发表于 2011-8-22 13:46:53 | 显示全部楼层
各位坛友,我是新手 请大家多多关照小弟我啊
发表于 2011-9-2 14:00:03 | 显示全部楼层
学习啦  
发表于 2012-11-6 12:59:45 | 显示全部楼层
好源码,谢谢共享
发表于 2014-8-13 16:38:23 | 显示全部楼层
請問怎麼會show:
Line 44
$excel = ExcelBookNew(1)
$excel = ^ ERROR

Error:Unknow function name
发表于 2015-2-24 14:06:47 | 显示全部楼层
学习下,感谢,非常感谢
发表于 2015-5-19 02:49:59 | 显示全部楼层
支持!!收藏!!
发表于 2015-6-4 11:11:52 | 显示全部楼层
请问怎么导出时可以选择路径和输入文件名。如果文件名没有文件后缀名,自动添加后缀名。
发表于 2018-5-31 22:12:26 | 显示全部楼层
正在寻找这个,研究一下
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-5-2 06:04 , Processed in 0.082456 second(s), 23 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表