File name with spaces

Hi Aspose team,

When I try to export to Excel/Word/PDF with spaces in the file name like “Test Excel.xlsx”, everything after the space get truncated. The file name will come as “Test.xlsx”. I’m using the latest version of aspose. I’m setting the Workbook.FileName to “Test Excel”. Did I miss something here?

Regards,

Hi,


Workbook.FileName is not necessary to be set and normally used when you open a template file from streams and there are some external formulas in it, so you may specify the file name dynamically.

I have tested the following code and it works fine, e.g

Sample code:

FileStream fstream = new FileStream(@“e:\test2\Book1.xlsx”, FileMode.Open);
Workbook _workbook = new Workbook(fstream);
//Specify the filename
_workbook.FileName = “e:\test2\Test Excel.xlsx”;
_workbook.Save(_workbook.FileName);

The output file is fine having the name “Test Excel.xlsx”;

However, you may simply use the lines in bold instead, it should work fine:
string fileName = “e:\test2\Test Excel.xlsx”;
_workbook.Save(fileName);

Thank you.

And, I am using the latest version/fix, please try it out: Aspose.Cells for .NET v7.4.0.2.

Thank you.

I’m creating the file name dynamically, and I’m trying to use

var ms = new MemoryStream();
workbook.Save(ms, new OoxmlSaveOptions());

How can I set the File name for this scenario?

Regards,


Hi,


Please see the following code on how to create the file (by specifying its name) while after saving the workbook to memory streams:

Sample code:

Workbook workbook = new Workbook();
workbook.Open(@“d:\test\Book1.xls”);
MemoryStream ms = new MemoryStream();
workbook.Save(ms, FileFormatType.Excel2003);
byte[] arr = ms.ToArray();
FileStream fs = File.Create(@“d:\test\mynewfile.XLS”);

fs.Write(arr, 0, arr.Length);
fs.Close();

Thank you.

But this approach forces me to specify the path where I want to save the file. What I need is, when a user clicks on a button to open up a pop up with Open or Save option. So they can save anywhere they like or just open and view.

Hi,

Thanks for your posting and using Aspose.Cells for .NET.

Well, you will have to use a single file name which user will download after clicking on the process button and Aspose.Cells will generate it.

You can change file name by using some date time variable or with some user session id.

Hi,


For a web application scenario, if you want to response the file to the client by displaying a download dialog in his browser (e.g IE), please use the Workbook.Save() overload which has Response object as its parameter, see the sample line of code for your needs:
workbook.Save(HttpContext.Current.Response, “MyFile.xlsx”, ContentDisposition.Attachment, new OoxmlSaveOptions(SaveFormat.Xlsx));

Also, you may try using Response object directly without involving Aspose.Cells APIs (e.g Workbook.Save method):

e.g
//…
MemoryStream tempStream = new MemoryStream();
workbook.Save(tempStream, xSaveOptions);
//You may change it accordingly if you are saving in XLS file format
Response.ContentType = “application/vnd.openxmlformats-officedocument.spreadsheetml.sheet”;
Response.AppendHeader(“Content-Disposition”, “attachment; filename=” + workbook.FileName);
Response.Flush();
Response.BinaryWrite(tempStream.ToArray());
Response.End();


Thank you.