Export Excel Files to Stream using C#

In various cases, you may need to export or save the Excel XLSX/XLS files to memory streams. For such cases, this article covers how to export Excel files to FileStream objects dynamically using C#. Moreover, you will learn how to load an Excel file from stream.

C# API to Export Excel Files to Stream

In order to export an Excel file to stream, we’ll use Aspose.Cells for .NET. It is a feature-rich API that lets you create and manipulate Excel files. You can either download the API’s DLL or install it via NuGet.

PM> Install-Package Aspose.Cells

Export an Excel File to Stream in C#

The following are the steps to export an Excel file to stream using C#.

The following code sample shows how to export an Excel XLSX file to a FileStream object.

Load Excel File from Stream

Aspose.Cells for .NET also allows you to load the Excel files from stream. The following are the steps to achieve this.

  • Create a new FileStream object and load the Excel file into it.
  • Create a new Workbook object and initialize it with the FileStream object.
  • Perform the desired operations on the Excel file using Workbook object.

The following code sample shows how to load an Excel file from a FileStream.

Get a Free License

You can get a free temporary license and use the API without evaluation limitations.

Conclusion

In this article, you have learned how to export Excel files to stream using C#. Moreover, you have seen how to load the Excel files from the stream dynamically. In addition, you can explore other features of Aspose.Cells for .NET using the documentation. Also, you can ask your questions via our forum.

See Also