In my app allows excel export on several of it's grids. When the export is completed, I save it to a file on the hard drive, and then open it in a separate process. My question is if it is possible to open excel with the data that was just exported without saving to the hard drive.
My application used to allow this by creating an excel object using Microsoft.Interop.Excel, and row by row manually adding to the excel sheet. One of the many down sides to this was that it was painfully slow. The infragistcs excel library takes care of the speed issues (thanks!!!), but my users want to be able to just open the workbook from memory without saving it.
Any ideas?
Thanks,
Justin
Justin,
You should be able to save the workbook to a memory stream and then feed it to excel somehow. I didn't want to spend a lot of time trying to figure it out so I just save the workbook to a temp file and load it in excel as read-only which prompts the user to choose the save location when they try to save the file. No need to worry about filename collisions or deleting old temp files as windows takes care of that in the System.IO.Path.GetTempFileName() method.
/// <summary>
/// Opens the specified workbook in excel as a read-only temporary file.
/// </summary>
/// <param name="workbook">The workbook.</param>
public static void Open(Infragistics.Excel.Workbook workbook)
{
string filepath = System.IO.Path.GetTempFileName();
workbook.Save(filepath);
ProcessStartInfo startInfo = new ProcessStartInfo("Excel.exe", String.Format("/r \"{0}\"", filepath));
Process.Start(startInfo);
}
Hi Justin,
I don't beleive there is any way to do this. The Infragistics.Excel.Workbook object has no relation to the Microsoft.Interop.Excel classes.