Я написал код для экспорта данных в файл xlsx. Но я не понимаю, как показать приглашение окна для загрузки этого xlsx-файла на стороне клиента. Вот мой код:Как показать окно подсказки для загрузки файла excel?
Private Sub DataTableToExcel(ByVal tbl As DataTable)
Dim Excel As Object = CreateObject("Excel.Application")
Dim strFilename As String
Dim intCol, intRow As Integer
Dim strPath As String = "C:\"
If Excel Is Nothing Then
MsgBox("It appears that Excel is not installed on this machine. This operation requires MS Excel to be installed on this machine.", MsgBoxStyle.Critical)
Return
End If
Try
With Excel
.SheetsInNewWorkbook = 1
.Workbooks.Add()
.Worksheets(1).Select()
.cells(1, 1).value = "Complaint Detail Report" 'Heading of the excel file
.cells(1, 1).EntireRow.Font.Bold = True
Dim intI As Integer = 1
For intCol = 0 To tbl.Columns.Count - 1
.cells(2, intI).value = tbl.Columns(intCol).ColumnName
.cells(2, intI).EntireRow.Font.Bold = True
intI += 1
Next
intI = 3
Dim intK As Integer = 1
For intCol = 0 To tbl.Columns.Count - 1
intI = 3
For intRow = 0 To tbl.Rows.Count - 1
.Cells(intI, intK).Value = tbl.Rows(intRow).ItemArray(intCol)
intI += 1
Next
intK += 1
Next
If Mid$(strPath, strPath.Length, 1) <> "\" Then
strPath = strPath & "\"
End If
strFilename = strPath & "ComplaintDetail.xlsx"
.ActiveCell.Worksheet.SaveAs(strFilename)
End With
System.Runtime.InteropServices.Marshal.ReleaseComObject(Excel)
Excel = Nothing
MsgBox("Data's are exported to Excel Succesfully: Location: '" & strFilename & "'", MsgBoxStyle.Information)
' Response.AddHeader("content-disposition", "attachment;filename=ComplaintDetail.xlsx")
'Response.ContentType = "application/vnd.excel"
Catch ex As Exception
MsgBox(ex.Message)
End Try
Dim pro() As Process = System.Diagnostics.Process.GetProcessesByName("EXCEL")
For Each i As Process In pro
i.Kill()
Next
End Sub
Здесь я спасаю .xlsx файл непосредственно в «C Drive». Почему я выбираю C Drive? : Потому что у 99% людей есть C: in there pc. Но у меня есть сценарий, когда пользователь не разрешает доступ к своему приводу C или не дает права писать что-либо внутри c-диска. Вот почему я пытаюсь добавить это окно, где пользователь решит, где сохранить этот файл. Но у меня проблема с кодом выше. Не могли бы вы помочь мне добавить приглашение окна в код выше?
Почему вы положили тег C#? – Gab
использовать временный файл% tmp% –
Это приложение для Windows? Если да, вы не должны помечать его asp.net. – Priyank