when i try to save a new workbook with saveformat xlsx aspose.cells downloads zip file.
the code i use is below
Protected Sub btn_Click(sender As Object, e As EventArgs) Handles btn.Click
Dim Databyte As Byte() = getBuffer()
Response.OutputStream.Write(Databyte, 0, Databyte.Length)
End Sub
Private Function getBuffer() As Byte()
Dim license As New Aspose.Cells.License
license.SetLicense(System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("TestAsposeCells.Aspose.Total.lic"))
Dim xlWorkBook As New Aspose.Cells.Workbook
'xlWorkBook.FileFormat = Aspose.Cells.FileFormatType.Excel97To2003
'Dim worksheet As Aspose.Cells.Worksheet
'worksheet = xlWorkBook.Worksheets(0)
'Dim cell As Aspose.Cells.Cell
'cell = worksheet.Cells("A1")
'cell.PutValue("ID")
'Dim cell1 As Aspose.Cells.Cell
'cell1 = worksheet.Cells("A2")
'cell1.PutValue("NewName")
Dim ms As New MemoryStream
xlWorkBook.Save(ms, Aspose.Cells.SaveFormat.Xlsx)
ms.Seek(0, SeekOrigin.Begin)
Dim buffer As Byte() = ms.ToArray()
Return buffer
End Function
If you want to save an Excel file from array of bytes, please try to change the line of code:
i.e., Response.OutputStream.Write(Databyte, 0, Databyte.Length)
to: File.WriteAllBytes("outputExcelFile.xlsx", Databyte)
For an Asp.NET or web application, it is possible. You can generate the file dynamically and send the output file directly to a client browser. The client will get a Download file dialog box and he may either save to disk or open it directly into MS Excel (viewer), see the document/section with sample code for your reference:
First of all please note that this is not the issue of Aspose.Cells by any means. Using the example code (in the suggested document) won’t save the Excel file to disk, rather, generally it will give the user a Download file dialog box (you got to configure your browser settings accordingly) and user may either save to disk or open it directly. Moreover, using Aspose.Cells API you may either save to streams or disk which works fine (you may confirm it by yourself, let me know if Aspose.Cells does not save the Excel workbook to stream). Next, if you need to perform other task using the output Excel file streams (saved by Aspose.Cells), I am afraid, you have to write your own code by yourself for your custom needs.
Anyways, another way can be as following for your requirements. The code is in C#, so you may easily convert it to VB.NET if you want:
e.g Sample code:
...........
/*Send workbook to response*/
OoxmlSaveOptions xSaveOptions = new OoxmlSaveOptions(SaveFormat.Xlsx);
MemoryStream ms = new MemoryStream();
xlWorkBook.Save(ms, xSaveOptions);
//set the position.
ms.Position = 0;
this.Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
this.Current.Response.AddHeader("content-disposition", "attachment; filename=out1.xlsx" );
Response.BinaryWrite(ms.ToArray());
Protected Sub cmdPrint_Click(sender As Object, e As EventArgs) Handles cmdPrint.Click
Dim Databyte As Byte() = CreateReportTable()
Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
Response.AddHeader("content-disposition", "attachment; filename=out1.xlsx")
Response.BinaryWrite(Databyte)
'Response.OutputStream.Write(Databyte, 0, Databyte.Length)
'Response.Clear()
'Response.AddHeader("Content-Type", "binary/octet-stream")
'Response.AddHeader("Content-Disposition", "attachment; filename=a.xlsx; size=" & Databyte.Length.ToString())
''response.AddHeader("Content-Disposition", "attachment; filename=ConversionResult.pdf; size=" & pdfBytes.Length.ToString())
'Response.Flush()
'Response.BinaryWrite(Databyte)
'Response.Flush()
'Response.End()
End Sub
Private Function CreateReportTable() As Byte()
Dim dt As New DataTable
dt = Session("ds")
If dt.Rows.Count > 0 Then
Dim license As New Aspose.Cells.License
license.SetLicense(System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("ecm_ab_for_s_server.Aspose.Total.lic"))
Dim WorkBookTable As New Aspose.Cells.Workbook
Dim i As Integer = WorkBookTable.Worksheets.Add()
Dim worksheet As Aspose.Cells.Worksheet
worksheet = WorkBookTable.Worksheets(i)
worksheet.Cells.ImportDataTable(dt, True, "A1")
Dim xSaveOptions As New Aspose.Cells.OoxmlSaveOptions(Aspose.Cells.SaveFormat.Xlsx)
Dim ms As New MemoryStream
ms.Position = 0
WorkBookTable.Save(ms, Aspose.Cells.SaveFormat.Xlsx)
Dim buffer As Byte() = ms.ToArray()
Return buffer
End If
End Function
but when i run the code i get the following “excel found unreadable content.do you want to recover the contents of this workbook? if you trust the source of this workbook click yes”
Sets consent for sending user data to Google for online advertising purposes.
Sets consent for personalized advertising.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
More info
Enables storage, such as cookies, related to analytics.
Enables storage, such as cookies, related to advertising.
Sets consent for sending user data to Google for online advertising purposes.
Sets consent for personalized advertising.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
More info
Enables storage, such as cookies, related to analytics.
Enables storage, such as cookies, related to advertising.
Sets consent for sending user data to Google for online advertising purposes.