hi i manage to export a data coming from listview to excel here is my code

Try

            ' Open output file  
            Dim os As New StreamWriter(filename)

            ' Write Headers  

            For i As Integer = 0 To ListView1.Columns.Count - 1
                ' replace quotes with double quotes if necessary  
                os.Write("""" & ListView1.Columns(i).Text.Replace("""", """""") & """,")
            Next

            os.WriteLine()

            ' Write records  
            For i As Integer = 0 To ListView1.Items.Count - 1
                For j As Integer = 0 To ListView1.Columns.Count - 1
                    os.Write("""" & ListView1.Items(i).SubItems(j).Text.Replace("""", """""") + """,")
                Next

                os.WriteLine()

            Next

            os.Close()

        Catch ex As Exception
            ' catch any errors  
            Return False
        End Try

        Return True

my problem is how to set the size of the cell in excel? i mean how to change the width?

Hi,

I thin you can find some information, here.

You can even try it this way:

Dim sb As New StringBuilder()
For i As Integer = 0 To listView1.Items.Count - 1
	sb.AppendLine()
	For j As Integer = 0 To listView1.Columns.Count - 1
		sb.Append(listView1.Items(i).SubItems(j).Text)
		If (i + 1) < listView1.Items.Count OrElse (j + 1) < listView1.Columns.Count Then
			sb.Append(",")
		End If
	Next
Next
Using sw As New System.IO.StreamWriter("C:\1\CSV_test.csv")
	sw.Write(sb.ToString())
End Using
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.