GemBox.Spreadsheet 使用 .net Web 服务下载 xlsx 文件



我正在编写一个.net Web服务来下载使用免费版本的GemBox.Spreadsheet创建的excel文件。 调用服务时,服务器运行但不给出任何答案。 这是代码。 任何想法(或其他库(? 谢谢

'''

<WebMethod(EnableSession:=True)>
Public Sub Download()
SpreadsheetInfo.SetLicense("FREE-LIMITED-KEY")
Dim workbook As New ExcelFile()
Dim worksheet = workbook.Worksheets.Add("Hello World")
worksheet.Cells(0, 0).Value = "English:"
worksheet.Cells(0, 1).Value = "Hello"
worksheet.Cells(1, 0).Value = "Russian:"
worksheet.Cells(2, 0).Value = "Chinese:"
Dim options As SaveOptions = SaveOptions.XlsDefault
Dim filename As String = "TestFile.xls"
Using stream As New MemoryStream
workbook.Save(stream, options)
worksheet.Clear()
worksheet = Nothing
workbook = Nothing
With System.Web.HttpContext.Current.Response
.ClearHeaders()
.ClearContent()
.Buffer = True
.ContentType = "application/vnd.ms-excel"
.AddHeader("content-disposition", "attachment; filename=" + filename)
.AppendHeader("Content-Length", stream.Length)
stream.CopyTo(.OutputStream)
.End()
End With
End Using
End Sub

'''

最好尝试这种方式,它对我有用:

'workbook.Save("DataSet to Excel file.xlsx")

Dim responseBase As HttpResponseBase = New HttpResponseWrapper(Me.Response)
' Stream spreadsheet to browser in XLSX format.
workbook.Save(responseBase, "Spreadsheet.xlsx")

相关内容

  • 没有找到相关文章

最新更新