Home > Software engineering >  LISTVIEW data export to EXCEL spreadsheet question (such as online urgent!)
LISTVIEW data export to EXCEL spreadsheet question (such as online urgent!)

Time:10-10

I want to put the data in a LISTVIEW export to EXCEL spreadsheet, export a problem, when export repeatedly will prompt:
Methods' ~ ' '~' role in failure
Each export, there will be a task manager EXCEL. EXE process

My code is as follows, hope everybody greatly help see
My OFFICE environment is VB6.0 by use of 2012

 Public Sub ExportExl (ByVal sName As String, ByVal sFile As String) 
On Error GoTo Error:
If ListView. ListItems. Count=0 Then
MsgBox "countless according to table, unable to export", 16, "error"
The Exit Sub
The Else
Dim objExl As Excel. Application 'statement object variables
Dim xlBook As Excel. The Workbook
Set objExl=New Excel. Application 'initializes the object variable
If Dir (App. Path + "\ Excel " & amp; SFile, vbDirectory)="" Then
ObjExl. SheetsInNewWorkbook=1 'will work the new thin number to 1
ObjExl. Workbooks. Add 'to Add a thin work
ObjExl. Sheets (objExl. Sheets. Count). The Name=sName 'modification work thin Name
The Else
The Set xlBook=objExl. Workbooks. Open (App) Path + "\ Excel " & amp; SFile) 'open the Excel file
XlBook. Sheets. The Add After:=objExl. Worksheets (Worksheets. Count) 'insert a new Sheet
XlBook. ActiveSheet. Name=sName 'rename new Sheet

End the If

ObjExl. Sheets (sName). Select 'selected work thin & lt; Book1 & gt;

ObjExl. Range (" A2 "and" E2 "). The Merge
ObjExl. Range (" A2 "). The Value="https://bbs.csdn.net/topics/staff monthly record detail"
ObjExl. Range (" A3 ", "E3"). The Merge
ObjExl. Range (" A3 "). The Value="https://bbs.csdn.net/topics/name:" & amp; SName
ObjExl. Range (" A4 "). The Value="date of https://bbs.csdn.net/topics/
"ObjExl. Range (" B4 "). The Value=
"https://bbs.csdn.net/topics/test situation"ObjExl. Range (" C4 "). The Value="https://bbs.csdn.net/topics/" pay
ObjExl. Range (" D4 "). The Value="borrow https://bbs.csdn.net/topics/
"ObjExl. Range (" E4 "). The Value="https://bbs.csdn.net/topics/to submit an expense account
"
ObjExl. ActiveWorkbook. ActiveSheet. Range (" A2 "). The HorizontalAlignment=xlCenter 'horizontal center
ObjExl. ActiveWorkbook. ActiveSheet. Range (" A2 "). The Font, Bold=True 'set to Bold
ObjExl. ActiveWorkbook. ActiveSheet. Range (" A3 "). Set to Bold Font. Bold=True '

ObjExl. ActiveWorkbook. ActiveSheet. Range (" A4 "). The HorizontalAlignment=xlCenter 'horizontal center
ObjExl. ActiveWorkbook. ActiveSheet. Range (" A4 ".) the Font, Bold=True 'set to Bold

ObjExl. ActiveWorkbook. ActiveSheet. Range (" B4 "). The HorizontalAlignment=xlCenter 'horizontal center
ObjExl. ActiveWorkbook. ActiveSheet. Range (" B4 "). Set to Bold Font. Bold=True '

ObjExl. ActiveWorkbook. ActiveSheet. Range (" C4 "). The HorizontalAlignment=xlCenter 'horizontal center
ObjExl. ActiveWorkbook. ActiveSheet. Range (" C4 "). Set to Bold Font. Bold=True '


ObjExl. ActiveWorkbook. ActiveSheet. Range (" D4 "). The HorizontalAlignment=xlCenter 'horizontal center
ObjExl. ActiveWorkbook. ActiveSheet. Range (" D4 "). Set to Bold Font. Bold=True '

ObjExl. ActiveWorkbook. ActiveSheet. Range (" E4 "). The HorizontalAlignment=xlCenter 'horizontal center
ObjExl. ActiveWorkbook. ActiveSheet. Range (" E4 "). Set to Bold Font. Bold=True '

Dim As Integer I

For I=1 To ListView. ListItems. Count
ObjExl. Range (" A "& amp; 4 + I). NumberFormatLocal="@"
ObjExl. Range (" A "& amp; (4 +). I Value=https://bbs.csdn.net/topics/Format ListView. ListItems. Item (I). SubItems (1), "yyyy - mm - dd")
ObjExl. Range (" B "& amp; 4 + I). Value=https://bbs.csdn.net/topics/ListView.ListItems.Item (I). SubItems (3)
ObjExl. Range (" C "& amp; 4 + I). Value=https://bbs.csdn.net/topics/ListView.ListItems.Item (I). SubItems (4)
ObjExl. Range (" D "& amp; 4 + I). Value=https://bbs.csdn.net/topics/ListView.ListItems.Item (I). SubItems (5)
ObjExl. Range (" E "& amp; 4 + I). Value=https://bbs.csdn.net/topics/ListView.ListItems.Item (I). SubItems (6)
Next I

'merger
ObjExl. Range (" A36 ", "E37"). The Merge
ObjExl. Range (" A36 "). The Value=https://bbs.csdn.net/topics/ReadText (StatusBar. Panels (1) Text, sName)
ObjExl. ActiveWorkbook. ActiveSheet. Range (" A36 "). Set to Bold Font. Bold=True '
'cell line wrap
ObjExl. ActiveWorkbook. ActiveSheet. Range (" A36 "). WrapText=True
ObjExl. ActiveWorkbook. ActiveSheet. Range (" A36 "). The Columns (A: A) Select
ObjExl. ActiveWorkbook. ActiveSheet. Range (" A36 ").
ColumnWidth=7.1
ObjExl. Range (" A38 ", "E38"). The Merge
ObjExl. Range (" A39 ", "E39). The Merge
ObjExl. Range (" A40 ", "E40"). The Merge
A38 objExl. Range (" "). The Value="https://bbs.csdn.net/topics/attendance and correct employee signature: year month day"
A39 objExl. Range (" "). The Value="https://bbs.csdn.net/topics/wages for employees to sign: year month day"
ObjExl. Range (" A40 "). The Value="https://bbs.csdn.net/topics/payroll staff sign: year month day"
ObjExl. ActiveWorkbook. ActiveSheet. Rows (38). 27 RowHeight=
ObjExl. ActiveWorkbook. ActiveSheet. Rows (39). 27 RowHeight=
ObjExl. ActiveWorkbook. ActiveSheet. Rows (40) RowHeight=27

'the bezel Settings
ObjExl. ActiveWorkbook. ActiveSheet. Range (" A2: E40 "). The Borders. Graphics.linestyle=1
ObjExl. ActiveWorkbook. ActiveSheet. Range (" A2: E40 "). The Borders. Weight=2
ObjExl. ActiveWorkbook. ActiveSheet. Range (" A2: E40 "). The Borders. ColorIndex=1
ObjExl. Columns (A: "E"). AutoFit 'automatically adjust the line width
ObjExl. ActiveWorkbook. SaveAs App. Path + "\ Excel " & amp; SFile

ObjExl. Workbooks. Close
ObjExl. Quit
'Set Sht=Nothing
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related