1
In the code below was assigned a Query for the variable sQuery.
I need to somehow export this Query for Excel using some resource available to C# Webform other than Interop.
Dim da = New OleDbDataAdapter(sQuery, ConnectionString)
Dim dt = New DataTable()
da.Fill(dt)
Dim GridView1 As New GridView()
Dim iTipoExport As Byte
Dim sstr As String
Session("Arquivo") = sNomeArquivo
CaminhoDiretorio = Server.MapPath("~/Download/" & sNomeArquivo & ".txt")
FileOpen(1, CaminhoDiretorio, OpenMode.Binary)
sstr = ""
For k As Integer = 0 To dt.Columns.Count - 1
sstr = sstr & dt.Columns(k).ColumnName + "^"
Next
sstr = Mid(sstr, 1, Len(sstr) - 1)
sstr = sstr & vbCrLf
FilePut(1, sstr)
For i As Integer = 0 To dt.Rows.Count - 1
sstr = ""
For k As Integer = 0 To dt.Columns.Count - 1
sstr = sstr & dt.Rows(i)(k).ToString() + "^"
Next
sstr = Mid(sstr, 1, Len(sstr) - 1)
sstr = sstr & vbCrLf
FilePut(1, sstr)
Next
FileClose(1)
AppExcelExport = CreateObject("Excel.Application")
AppExcelExport.Workbooks.OpenText(CaminhoDiretorio, StartRow:=1, DataType:=Excel.XlTextParsingType.xlDelimited, TextQualifier:=Excel.XlTextQualifier.xlTextQualifierNone, Other:=True, OtherChar:="^")
WboExcelExport = AppExcelExport.Workbooks(1)
WshExcelExport = WboExcelExport.Sheets(1)
WshExcelExport.Select()
RngExcelExport = WshExcelExport.Rows(1)
See if it helps https://answall.com/q/15590/101
– Maniero
Got it, I can use Epplus or Linq to Excel to convert a csv to xlsx?
– user109093
Maybe you need to see if you can get what you need, but I think you can.
– Maniero
I believe that the options of this post are to generate an Excel, in case I need to export it from my data table.
– user109093
The question clearly asks to convert an Excel file.
– Maniero