title: Using how to import data set into excel and return as memorystream? receiving an error inside workbook.Save(stream)
body: <p><img src="https://i.stack.imgur.com/bmNmV.png" alt="enter image description here" /></p>
  <pre><code>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 &quot;Products&quot; DataTable object
          DataTable dataTable = objDS.Tables[0];
  
  
          // Importing the contents of DataTable to the worksheet starting from &quot;A1&quot; 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, &quot;A1&quot;);
          MemoryStream stream = new MemoryStream();
          // Saving the Excel file
          workbook.Save(stream);
  
  
          return stream;
      }
  </code></pre>