We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Export datatable to excel without saving to a file

Hi

Is there a direct method call in Aspose.cells to export a datatable or datareader to excel file and stream it to the client browser without saving to a file as per your below sample code. I would like to transmit the exported file to client without having to save to a file. Is there any direct method to do this. Please share.

//Instantiating a Workbook object Workbook workbook = new Workbook();

//Adding a new worksheet to the Workbook object int i = workbook.Worksheets.Add();

//Obtaining the reference of the newly added worksheet by passing its sheet index Worksheet worksheet = workbook.Worksheets[i];

//Creating an array containing names as string values string[] names = new string[] { "laurence chen", "roman korchagin", "kyle huang" };

//Importing the array of names to 1st row and first column vertically worksheet.Cells.ImportArray(names, 0, 0, true);

//Saving the Excel file workbook.Save("C:\\DataImport.xls");

Thanks

Hi Satish,

Thanks for your posting and using Aspose.Cells.

I think, you are trying to send your file in a response stream to client browser like Internet Explorer, Chrome, FireFox etc.

You can send your xls file to client browser using the following code.

C#


workbook.Save(HttpContext.Current.Response, “DataImport.xls”, ContentDisposition.Attachment, new XlsSaveOptions(SaveFormat.Excel97To2003));

HttpContext.Current.Response.End();

i am also looking something like this where i do not have to physically save excel file and than i want to pass that stream to Client Aspose.GridWeb as source ..

is this posible ??

GridWeb1.WebWorksheets.ImportExcelFile(wb.SaveToStream());
form1.Controls.Add(GridWeb1);

Thanks for the response.

I could not get your solution working as I keep getting "The ContentDispostion does not exist in current context".

Anyway I was able to achieve the same using similar solution as below :

MemoryStream

mem = new MemoryStream();

workbook.Save(mem,

SaveFormat.Xlsx);

HttpContext.Current.Response.AddHeader("content-disposition", string.Format("attachment; filename={0}", fileName));

HttpContext.Current.Response.ContentType = "application/vnd.ms-excel";

mem.WriteTo(

HttpContext.Current.Response.OutputStream);

HttpContext.Current.Response.End();

Hi Satish,

Thanks for your posting and using Aspose.Cells.

It seems, you are using some wrong Aspose.Cells dll. May be you are using ClientProfile dll. Please use some other Aspose.Cells dll. For example, you can try the dll inside the net2.0 folder. You will find these folders in the installation directory of Aspose.Cells. I have attached the readme.txt file for your reference.

  • net2.0
  • net2.0_AuthenticodeSigned
  • net3.5
  • net3.5_AuthenticodeSigned
  • net3.5_ClientProfile
  • net3.5_ClientProfile_AuthenticodeSigned

It is good to know that you were able to sort out this issue. Let us know if you encounter any other issue. We will look into it and help you asap.


Hi,

piyushpatel:

i am also looking something like this where i do not have to physically save excel file and than i want to pass that stream to Client Aspose.GridWeb as source ..

is this posible ??

GridWeb1.WebWorksheets.ImportExcelFile(wb.SaveToStream());
form1.Controls.Add(GridWeb1);


Please refer to your other thread for your reference:
https://forum.aspose.com/t/80521

Thank you.