|
本帖最后由 aaa21 于 2010-1-25 09:54 编辑
1 p! @( F) c! d" \+ F- G. L. n0 f& N# }4 d. w0 m6 A' ~
Dim ExportList As ListView
" N6 V, o2 D0 @2 H5 b5 aDim Exwbook As Excel.Workbook; J8 C8 d7 J5 y/ V! w: x+ N2 U- ~) j
Dim Exsheet As Excel.Worksheet
+ k$ o9 ^ j7 U' @8 r: u
7 V& v8 @% k I E. ZIf ExportList Is Nothing Then MsgBox "请选择列表框!", vbInformation, "提示": Exit Sub2 M/ S9 S1 ^8 E5 b
If ExportList.ListItems.Count = 0 Then MsgBox "没有数据!", vbInformation, "提示": Exit Sub
, ?! u7 y* i: ^3 a4 C'提取保存路径1 U c- C* O( D: l; ~1 t
PathStr = showdialog19 e u* ?8 }, _" D* ] k1 n
If PathStr = "" Then Exit Sub) \" ]2 E9 Y( `5 C
'创建EXCLE文件3 [% p) Q) |! `
Set TempApp = CreateObject("Excel.application")
$ C, p+ x) M% P( {If TempApp Is Nothing Then MsgBox "请检查是否安装Microsoft Excell软件", vbExclamation, "问题": Exit Sub
# v. V3 c5 L: m( MSet Exwbook = TempApp.Workbooks.Add
0 u2 ^: b6 `/ ZSet Exsheet = Exwbook.Worksheets(1)$ R+ ?. o) `8 g+ K4 V
If Exsheet Is Nothing Then MsgBox "请检查是否存在" + PathStr & ",输出需要输入到Excell表中去", vbExclamation, "问题": Exwbook.Close: TempApp.Quit: Exit Sub: k$ T0 K* I! `! m# I" l7 d
TempApp.Sheets(1).Select5 J( n% j/ g! n: C# A7 o
TempApp.Selection.ClearContents% c4 t4 k: T* {' C; d7 O
For Loopj = 1 To ExportList.ColumnHeaders.Count
' D7 ~6 u' |6 [' j) _9 b Exsheet.Cells(1, Loopj) = ExportList.ColumnHeaders.Item(Loopj).Text
* A3 X- S% O2 x/ j/ n8 lNext
/ V- p" q$ c U$ y. \9 k- O0 h4 p3 y2 l# x7 [+ @
For Loopi = 1 To ExportList.ListItems.Count
# j6 [! j+ z+ T1 a% w Set Itmx = ExportList.ListItems.Item(Loopi), ^! q6 F6 |7 p/ v" x: U* l2 }1 Y
For Loopj = 0 To ExportList.ColumnHeaders.Count - 1* ]1 M* g/ y; N0 k
If Loopj = 0 Then$ `( e% P: L' K3 ?9 j
Exsheet.Cells(Loopi + 2, Loopj + 1) = Itmx.Text
3 x2 F$ `, u+ c& R/ T0 S) A Else7 [6 j- _' Z4 D( L& \ W
Exsheet.Cells(Loopi + 2, Loopj + 1) = Itmx.SubItems(Loopj)
' b- e4 r. G* g. _ End If9 ^* y; j' [/ T# o, \
Next1 f5 e& @, R' u3 J' `4 q4 M. e( B
Next6 I t; [5 T# ?3 j; O6 H
Dim a As Long0 h' ?' W( ? l) ^( X
Exsheet.SaveAS (PathStr)2 P: `* e% a& G. E$ Q$ _
Exwbook.Close% W+ Y6 e2 ?4 N$ o1 N* b8 B
TempApp.Quit
% X" R! k' x9 u- B8 v) L# Y: TMsgBox "导出完成!", vbInformation, "确认" |
|