Spire.XLS is a professional Excel API that enables developers to create, manage, manipulate, convert and print Excel worksheets. Get free and professional technical support for Spire.XLS for .NET, Java, Android, C++, Python.

Thu Nov 09, 2017 9:01 pm

Hello,
I am new in SPIRE.XLS and I am trying FREE SPIRE.XLS. I DOWNLOADED FROM NUGET. I AM USING VS2015. It's a web project in asp.net and c#.

MY CODE IS VERY SIMPLE:
protected void Button1_Click(object sender, EventArgs e)
{
Workbook book = new Workbook();
Worksheet sheet = book.Worksheets[0];
sheet.InsertDataTable(dt, true, 1, 1);
book.SaveToStream(file_stream);
file_stream.Close();
System.Diagnostics.Process.Start("To_stream.xls");
}

I AM getting following error when I try to save :
book.SaveToStream(file_stream);
ERROR FILE IS ATTACHED.

Can anybody help me please.
Attachments
spireerror.PNG
error Image
spireerror.PNG (38.6 KiB) Viewed 4494 times

mguha
 
Posts: 11
Joined: Thu Nov 09, 2017 8:54 pm

Fri Nov 10, 2017 2:34 am

Hello,

Thanks for your inquiry. How did you initialize the file_stream object? As per the error information you attached, it seems to indicate that you have no access to the file "To_stream.xls", or the file is readonly, please have a check.

Sincerely,
Gary
E-iceblue support team
User avatar

Gary.zhang
 
Posts: 1380
Joined: Thu Apr 04, 2013 1:30 am

Tue Nov 14, 2017 9:13 am

Hello,

Greetings from E-iceblue.
Has the issue get resolved on your side?
Thanks in advance for your valuable feedback and time.

Sincerely,
Gary
E-iceblue support team
User avatar

Gary.zhang
 
Posts: 1380
Joined: Thu Apr 04, 2013 1:30 am

Tue Nov 14, 2017 3:42 pm

If I give a full path it does solve the issue. But I REALLY like to do this but not sure how to achieve this.
The code below I did with Openxml but I like to do the same with Spire. Can you help me please.

HttpContext.Current.Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
HttpContext.Current.Response.AddHeader("content-disposition", "attachment;filename=" + fname + "_" + today.ToString("yyyyMMddhhmmss") + ".xlsx");
using (MemoryStream MyMemoryStream = new MemoryStream())
{
wb.SaveAs(MyMemoryStream);
MyMemoryStream.WriteTo(HttpContext.Current.Response.OutputStream);
HttpContext.Current.Response.Flush();
HttpContext.Current.Response.End();

}

mguha
 
Posts: 11
Joined: Thu Nov 09, 2017 8:54 pm

Wed Nov 15, 2017 6:51 am

Hello,

Thanks for your feedback. Please refer to the below code snippet to save document to HttpResponse.
Code: Select all
Workbook wb = new Workbook();
wb.LoadFromFile(fileName);
wb.SaveToHttpResponse("result.xlsx",Response, HttpContentType.Excel2010);


Best regards,
Simon
E-iceblue support team
User avatar

Simon.yang
 
Posts: 620
Joined: Wed Jan 11, 2017 2:03 am

Wed Nov 15, 2017 3:29 pm

I got the dialog box and when I opened the file I in excel it's giving the following error. Please help.

My code

Workbook book = new Workbook();
Worksheet sheet = book.Worksheets[0];
sheet.Name = "AFDCS Report";
sheet.Range["A1"].Value = "Audit Log";
sheet.Range["A1"].Style.Font.IsBold = true;
sheet.Range["A1"].Style.Font.Size = 16;
sheet.Range["A1"].Style.HorizontalAlignment = HorizontalAlignType.Center;
sheet.Range["A1:D1"].Merge();

sheet.Range["A1:D1"].Style.Font.IsBold = true;
sheet.Range["A1:D1"].Style.Font.Size = 10;
sheet.Range["A1:D1"].Style.Color = System.Drawing.Color.Silver;
sheet.Range["A1:D1"].Style.HorizontalAlignment = HorizontalAlignType.Center;

sheet.InsertDataTable(dt, true, 3, 1);
book.Worksheets.Add(sheet);

int lastFilledRow = sheet.LastRow;
for (int i = sheet.LastRow; i >= 0; i--)
{
CellRange cr = sheet.Rows[i-1].Columns[1];
if (!cr.IsBlank)
{
lastFilledRow = i;
break;
}
}
sheet.Range["B3:B" + lastFilledRow].NumberFormat = "mm/dd/yyyy hh:mm:ss AM/PM";

sheet.AllocatedRange.AutoFitColumns();
sheet.AllocatedRange.AutoFitRows();

book.SaveToHttpResponse("result.xlsx", Response, HttpContentType.Excel2010);
Attachments
spireerror.PNG
spireerror.PNG (13.26 KiB) Viewed 4449 times

mguha
 
Posts: 11
Joined: Thu Nov 09, 2017 8:54 pm

Thu Nov 16, 2017 2:13 am

Hello,

Thanks for your feedback. When creating a new Workbook, please set its version first which is the same as HttpContentType when saving.
Code: Select all
            Workbook wb = new Workbook();
            wb.Version = ExcelVersion.Version2010;
            wb.SaveToHttpResponse("result.xlsx", Response, HttpContentType.Excel2010);


Best regards,
Simon
E-iceblue support team
User avatar

Simon.yang
 
Posts: 620
Joined: Wed Jan 11, 2017 2:03 am

Fri Nov 17, 2017 9:47 am

Hello,

Greeting from E-iceblue.
Did your try the solution i provided? Is it working on your side?
Your feedback will be greatly appreciated.

Sincerely,
Simon
E-iceblue support team
User avatar

Simon.yang
 
Posts: 620
Joined: Wed Jan 11, 2017 2:03 am

Return to Spire.XLS