Note that there are some explanatory texts on larger screens.

plurals
  1. POExport sql query to Excel 97 file using vb.net
    primarykey
    data
    text
    <p>I have a desktop app, I use this code to create a .xls file using a FileStream object:</p> <pre><code>Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim i As Integer Dim strLine As String = "" Dim fileExcel As String Dim objFileStream As FileStream Dim objStreamWriter As StreamWriter Dim cnn As SqlConnection = New SqlConnection("...Connection...") 'Create a pseudo-random file name. fileExcel = "c:\temp\test.xls" 'Use FileStream to create the .xls file. objFileStream = New FileStream(fileExcel, FileMode.OpenOrCreate, FileAccess.Write) objStreamWriter = New StreamWriter(objFileStream) 'Use a DataReader to connect to the Pubs database. cnn.Open() Dim sql As String = "select top 5 idWO, Number, Comment from tblWorkorder (nolock)" Dim cmd As SqlCommand = New SqlCommand(sql, cnn) Dim dr As SqlDataReader dr = cmd.ExecuteReader() 'Enumerate the field names and records that are used to build the file. For i = 0 To dr.FieldCount - 1 strLine = strLine &amp; dr.GetName(i).ToString &amp; Chr(9) Next 'Write the field name information to file. objStreamWriter.WriteLine(strLine) 'Reinitialize the string for data. strLine = "" 'Enumerate the database that is used to populate the file. While dr.Read() For i = 0 To dr.FieldCount - 1 strLine = strLine &amp; dr.GetValue(i) &amp; Chr(9) Next objStreamWriter.WriteLine(strLine) strLine = "" End While 'Clean up. dr.Close() cnn.Close() objStreamWriter.Close() objFileStream.Close() End Sub </code></pre> <p>This works fine, but when I open the .xls file created, I get: "The file you are trying to open, is in a different format than specified in the file extension..." so I guess that it creates a .xlsx (2007) file instead a .xls (97-2003). So I wonder if there is any way to specify the version in which I want the excel file?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload