Worked it out and below is the source code for future reference.
Thanks @Soulfire for pointing the right direction.
For start I was not even working with Interop
since requirements just stated I need to save it to Excel.
I contacted Stimulsoft and they pointed me it cannot be done
Since it cannot be donne before the file is created I added the feature to ask user to open it.
using Excel = Microsoft.Office.Interop.Excel;
// Do lots of Stuff
SaveFileDialog saveFD = new SaveFileDialog();
saveFD.Filter = "Excel Files|*.xlsx;*.csv;*.xls|All files|*.*";
saveFD.FilterIndex = 1;
saveFD.RestoreDirectory = true;
saveFD.FileName = String.Format("MySavedFile_{0:yyyyMMddHHmmss}.xls", DateTime.Now);
if (saveFD.ShowDialog() == DialogResult.OK)
{
// In this example report is derived from the DevXpress XtraReport class
report.ExportToXls(saveFD.FileName);
// sanity note:Mensagem is a derived from devXpress XtraMessageBox
if (Mensagem.Confirm("File saved! Open it?"))
{
try
{
var excelApp = new Excel.Application();
excelApp.Visible = true;
var customEvent = new Excel.AppEvents_WorkbookOpenEventHandler(CustomWorkbookOpenEvent);
excelApp.WorkbookOpen += customEvent;
excelApp.Workbooks.Open(saveFD.FileName,
Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing);}
catch (Exception)
{
Mensagem.Erro("Excel Failed to Open");
}
}
}
The tricky part was to workout that COM Objects.
private void CustomWorkbookOpenEvent(Excel.Workbook wb)
{
Excel._Worksheet sheet = (Excel.Worksheet)wb.ActiveSheet;
sheet.Columns.AutoFit();
}
Edit
After a while we found interop is really bad for us (deploy on many users with many office versions, dll hell, etc).
We founs NetOffice is a great alternative.
Just replaced the 3 lines below:
using Excel = NetOffice.ExcelApi;
/* ... */
var customEvent = new Excel.Application_WorkbookOpenEventHandler(CustomWorkbookOpenEvent);
excelApp.WorkbookOpenEvent += customEvent;