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

Free Support Forum - aspose.com

How to import data set into excel and return as memorystream? receiving an error inside workbook.Save(stream)

 public static MemoryStream GenerateExcelReport(DataSet objDS)

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

        // Obtaining the reference of the worksheet
        Worksheet worksheet = workbook.Worksheets[0];

        // Instantiating a "Products" DataTable object
        DataTable dataTable = objDS.Tables[0];

        // Importing the contents of DataTable to the worksheet starting from "A1" cell,
        // Where true specifies that the column names of the DataTable would be added to
        // The worksheet as a header row
        worksheet.Cells.ImportDataTable(dataTable, true, "A1");
        MemoryStream stream = new MemoryStream();
        // Saving the Excel file

        return stream;


In newer versions, there is no Workbook.Save() overloaded method which has single argument when saving to stream. So, kindly correct the line, there should be two arguments which needs to be set.

Also, we are not sure about dataset/datatable. So, it is better if you could create a standalone VS.NET console application, zip the project and post us to show the issue, we will check it soon.

PS. please create dynamic dataset/datatable in code to remove any inter-dependencies of external source. Also, exclude Aspose.Cells.Dll to minimize the size of the zipped archive (project) prior attaching here.

do you have any sample codes for memory stream with two arguments?

workbook.Save(stream, SaveFormat.Xlsx);