0

hi i have a code here that export my listview items to excel but i want to customize each cell size and i want to format the date and landscape environment

 Try
        Dim objExcel As New Excel.Application
        Dim bkWorkBook As Workbook
        Dim shWorkSheet As Worksheet
        Dim i As Integer
        Dim j As Integer

        objExcel = New Excel.Application
        bkWorkBook = objExcel.Workbooks.Add
        shWorkSheet = CType(bkWorkBook.ActiveSheet, Worksheet)
        For i = 1 To Me.lvList1.Columns.Count - 1
            shWorkSheet.Cells(1, i + 1) = Me.lvList1.Columns(i).Text
        Next
        For i = 1 To Me.lvList1.Items.Count - 1
            For j = 1 To Me.lvList1.Items(i).SubItems.Count - 1
                shWorkSheet.Cells(i + 2, j + 1) = Me.lvList1.Items(i).SubItems(j).Text
            Next
        Next

        objExcel.Visible = True
    Catch ex As Exception
        MsgBox(ex.Message)
    End Try
2
Contributors
1
Reply
15
Views
4 Years
Discussion Span
Last Post by G_Waddell
0

HI,

Not sure you can customise each individual cell size, Height would be determined by the row's height and width by the Columns width I have a feeling Excel does this automatically - you could look at wrapping / not wrapping text

You should be able to set the individual cells format to handle the dates though

cell(row, col).NumberFormat ="yyyy-MM-dd" 

Should do it...

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.