|
-
Mar 3rd, 2006, 01:42 PM
#1
[RESOLVED] Creating An Excel Spreadsheet
I have the following code which creates an Excel spreadsheet and dumps the contents of a Listview, including the Listview columnheaders, to the spreadsheet. (Only the code that pertains to the question is posted.)
It all works great (and thanks to RobDog, the columns that I need to be centered are )
My headers go from A:1 to E:1 and the listview contents are dumped from
A:3 across to E:3 and on down for as many rows as the listview has.
Again, everything is working great, but (there is always a "but" right? ), now I've been told that my column headers need to start at A:7 and run across to E:7 and the lisview contents start at A:9 and run across to E:9 and down, plus I need to add some free text to A:1 A:2 A:3 A:4 and A:5
So, two questions: How do I modify what I have to move everything down to the A:7 starting point?
How do I write my text to the various columns of row A?
VB Code:
Set objExcel = New Excel.Application
Set bkWorkBook = objExcel.Workbooks.Add
Set shWorkSheet = bkWorkBook.ActiveSheet
With lvwAR
For i = 1 To .ColumnHeaders.Count
shWorkSheet.Cells(1, Chr(64 + i)) = .ColumnHeaders(i)
Next
objExcel.Workbooks(1).Sheets(1).Columns("A:A").HorizontalAlignment = xlCenter
objExcel.Workbooks(1).Sheets(1).Columns("C:C").HorizontalAlignment = xlCenter
objExcel.Workbooks(1).Sheets(1).Columns("d:d").HorizontalAlignment = xlCenter
objExcel.Workbooks(1).Sheets(1).Columns("E:E").HorizontalAlignment = xlCenter
For i = 1 To .ListItems.Count
shWorkSheet.Cells(i + 2, "A") = .ListItems(i).Text
For j = 2 To .ColumnHeaders.Count
shWorkSheet.Cells(i + 2, Chr(64 + j)) = .ListItems(i).SubItems(j - 1)
Next
Next
shWorkSheet.Columns("A:BZ").AutoFit
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|