How to save a file to stream?
8 Dec 20232 minutes to read
XlsIO provides support to save a workbook to a .NET stream. The following code snippet illustrates this.
using (ExcelEngine excelEngine = new ExcelEngine())
{
IApplication application = excelEngine.Excel;
FileStream inputStream = new FileStream("Sample.xlsx", FileMode.Open, FileAccess.Read);
IWorkbook workbook = application.Workbooks.Open(inputStream, ExcelOpenType.Automatic);
//Save the workbook to stream
FileStream fileStream = new FileStream("Output.xlsx", FileMode.OpenOrCreate, FileAccess.ReadWrite);
workbook.SaveAs(fileStream);
workbook.Close();
excelEngine.Dispose();
}
using (ExcelEngine excelEngine = new ExcelEngine())
{
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Excel2013;
IWorkbook workbook = application.Workbooks.Open("Sample.xlsx", ExcelOpenType.Automatic);
//Save the workbook to stream
FileStream fileStream = new FileStream("Output.xlsx", FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite);
workbook.SaveAs(fileStream);
}
Using excelEngine As ExcelEngine = New ExcelEngine()
Dim application As IApplication = excelEngine.Excel
application.DefaultVersion = ExcelVersion.Excel2013
Dim workbook As IWorkbook = application.Workbooks.Open("Sample.xlsx", ExcelOpenType.Automatic)
'Save the workbook to stream
Dim fileStream As New FileStream("Output.xlsx", FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite)
workbook.SaveAs(fileStream)
End Using
See Also
-
How to open an Excel file from stream?
How to save an Excel workbook to stream? - How to resolve the File does not contain workbook stream error in Syncfusion.XlsIO.Base.dll?
- How to resolve Excel cannot open the file filename.xlsx… error?
- How to open an existing XLSX workbook and save it as XLS?
- How to merge excel files from more than one workbook to a single file?
- Does XlsIO support Excel files with macros that are digitally signed?
- How does Excel file with uninstalled fonts is converted to PDF/Image?