What I have is an Excel document created by ClosedXML which I can write to a perfectly valid XLSX file. However, what I am looking for is to show the document in Excel without writing it to a disk file. The user can view the contents in a user-friendly way, and then decide whether to save to disk or not. This would be much more effective than first writing to a disk file, which needs a Save As dialog, and then showing it in Excel, and then, if the user does not need the output, having him or her delete that file.
Here is code that I cobbled together from various sources for opening an Excel file in a running instance of the Excel application, which will stay open even after my C# app closes:
using Excel = Microsoft.Office.Interop.Excel;
//needs ref to COM: Microsoft Excel Object Library
public void ShowFile()
{
Excel.Application _ExcelApp = new Excel.Application();
_ExcelApp.Visible = true;
_ExcelApp.Workbooks.Open(@"C:\temp\us1.xlsx");
}
What I am missing is a way to Open from a MemoryStream. In many other projects, there exists a Open methods for either file or stream objects, but here I could not find it.
Another route would be to not use Open(Stream), if any, but to use that library to build one or more workbooks using OpenXml or ClosedXml libraries, because those libs can load from a stream, but that did not work. I found some code for conversion from ClosedXml to OpenXml. But I did not really found code to build a workbook that is compatible to the above fragment.
Any help is appreciated.