我正在使用 ExcelLibrary在此处输入链接描述,因为我不想安装 Microsoft Office Excel (microsoft.interop.office.excel)
Public Function ObtenerExcel() As ActionResult
Dim workbook As New Workbook()
Dim worksheet As New Worksheet("Sheet1")
worksheet.Cells(5, 5) = New Cell(999999)
worksheet.Cells(10, 10) = New Cell(12354)
workbook.Worksheets.Add(worksheet)
Dim stream As New System.IO.MemoryStream
workbook.SaveToStream(stream)
stream.Position = 0
Dim buffer(4096) As Byte
stream.Read(buffer, 0, buffer.Length)
Return File(buffer, "application/vnd.ms-excel", "mytestfile.xls")
End Function
此代码返回一个 excel 文件,但是当我尝试打开此文件时,它显示一条错误消息(Excel 在 'text.xls' 中找到不可读的内容。您要恢复此工作簿的内容吗?如果您信任此工作簿,单击是。)它不显示任何内容。
我在 Windows 8.1(64 位)和 Microsoft Office 2013 上工作