Yes that is the issue we are spacing while open the excel sheet
@Balarega09,
When I use the following code to resave the file you provided, the result file can be opened correctly. Please refer to the attachment (9.0 KB).
Workbook wb = new Workbook(filePath + "BNYM Quant_London_4PM_Daily_LIBOR_Single_CDS_Markit_CompCrvLon1615_21Aug2023012557_V1.xlsx");
wb.Save(filePath + "out.xlsx");
While Downloading we are spacing this issue from stream content to xlsx saving we are spacing this issue
Response.Clear()
Response.ClearHeaders()
Response.Buffer = True
fileName = Path.GetFileName(fileName)
Response.ContentType = "application/ms-excel"
Response.AppendHeader(“content-disposition”, “attachment; filename=” & fileName & “; size=” & reportInput.Length - 1)
Response.OutputStream.Write(stream.ToArray(), 0, stream.Length)
Response.Flush()
Response.SuppressContent = True
HttpContext.Current.ApplicationInstance.CompleteRequest()
Its reading file from file path but we have only stream data.
our stream data : E680429A-7C3E-EE11-B887-0050568B3BDF
Can you give some sample console application
@Balarega09,
When creating a new Workbook, Aspose.Cells support directly passing in stream data. You can refer to the following code.
//set your file stream
Stream fileStream = null;
// Load your source workbook
Workbook workbook = new Workbook(fileStream);
if (Response != null)
{
// Save in Xlsx format
workbook.Save(Response, dataDir + "output.xlsx", ContentDisposition.Attachment, new OoxmlSaveOptions());
Response.End();
}
Hope helps a bit.
Already I have but showing error
image.png (2.9 KB)
which version is included we are using
image.png (8.4 KB)
Thanks for the screenshots.
Since you are using an older version (v8.6.3) of Aspose.Cells for .NET, so you may not use Workbook.Save overloaded method used in the sample code (shared by @John.He in his reply).
We are sorry but we cannot evaluate your issue based on older versions of the APIs (i.e., Aspose.Cells for .NET vv8.6.3). Neither we can include any fixes to older versions the APIs, the fixes are based on latest APIs set only. We recommend you to kindly upgrade to and try latest version of Aspose.Cells for .NET v23.8:
In case you still find this issue with Aspose.Cells for .NET v23.8, kindly do create a sample console demo application in VS.NET with resource file(s), zip the project and post us, we will check and look into your issue soon.
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Aspose.Cells;
using System.Web;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
byte[] ss = Encoding.ASCII.GetBytes("E680429A - 7C3E - EE11 - B887 - 0050568B3BDF");
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
HttpResponse Response = null;
Workbook workbook = new Workbook();
Response.Clear();
Response.ClearHeaders();
Response.Buffer = true;
Response.ContentType = "application/ms-excel";
if (Response != null)
{
// Save in Excel2003 XLS format
workbook.Save(Response, dataDir + "output.xls", ContentDisposition.Inline, new XlsSaveOptions());
Response.End();
}
Response.Flush();
Response.SuppressContent = true;
HttpContext.Current.ApplicationInstance.CompleteRequest();
}
}
}
This My code but not working with v23.8
image.png (7.6 KB)
Please check now
image.png (15.8 KB)
byte[] ss = Encoding.ASCII.GetBytes("E680429A - 7C3E - EE11 - B887 - 0050568B3BDF");
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
It looks like you are copying/pasting code snippet from Github examples repos to your application. Please note RunExamples is a custom class which has static method “GetDataDir” to get the source source/destination files directory path. Please download the source VS.NET project from Github Examples repos here, open the project/solution file into VS.NET manually, build it and then run it, it will work fine. Alternatively, just replace line(s) for dataDir variable (in code) with your physical (valid) path to your desired directory/folder of your hard drive or project folder.
Let us know if you still have any issue or confusion?
Actually I dont want save to any physical path.
I want download file with XLSX file format but I have only stream content at that time I am getting corrupts file error.
When I click yes , then file will be validating content and sharing content.
This issue only I am facing BNYM Quant_London_4PM_Daily_LIBOR_Single_CDS_Markit_CompCrvLon1615_21Aug2023012557_V1.zip (8.0 KB)
Please find attched excel sheet file for corrupts file
Please create a standalone VS.NET application with latest version, zip the project with resource files and share with us to reproduce the issue on our end. We will check your issue soon.
PS. when zipping the sample project, please exclude Aspose.Cells.Dll to minimize the size of the zipped archive.
MemoryStream stream = new MemoryStream(ss);
HttpResponse Response = System.Web.HttpContext.Current.Response;
Response.Clear();
Response.ClearHeaders();
Response.Buffer = true;
fileName = Path.GetFileName(fileName);
Response.ContentType = "application/ms-excel";
int length = ss.Length - 1;
Response.AppendHeader("content-disposition", "attachment; filename=" + fileName + "; size=" + length);
Response.OutputStream.Write(stream.ToArray(), 0, (int)stream.Length);
Response.Flush();
Response.SuppressContent = true;
System.Web.HttpContext.Current.ApplicationInstance.CompleteRequest();
This our Code
byte value : 7C02602A-F83F-EE11-B887-0050568B3BDF
Dim stream As New MemoryStream(reportInput)
Response.Clear()
Response.ClearHeaders()
Response.Buffer = True
fileName = Path.GetFileName(fileName)
Response.ContentType = "application/ms-excel"
Response.AppendHeader(“content-disposition”, “attachment; filename=” & fileName & “; size=” & reportInput.Length - 1)
Response.OutputStream.Write(stream.ToArray(), 0, stream.Length)
Response.Flush()
Response.SuppressContent = True
HttpContext.Current.ApplicationInstance.CompleteRequest()
Our vb.net code
Our Sample project in MVC Please check now and please suggest what code we need to change