开发者

C# Create Excel (Done) then show/open it? Help

I can create an excel and save it, however I would prefer to show the document! Any help would be great!! Thanks

Excel.Application   xlApp;
Excel.Workbook      xlWorkBook;
Excel.Worksheet     xlWorkSheet;

object misValue = System.Reflection.Missing.Value;

xlApp       = new Excel.ApplicationClass();
xlWorkBook  = xlApp.Workbooks.Add(misValue);

xlWorkSheet         = (Excel.Worksheet)xlWorkBook.Sheets["Sheet1"];
xlWorkSheet.Name    = "Exported Data";

xlWorkSheet.Cells[1, 1] = "Demo";
xlWorkSheet             = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);

xlWorkBook.SaveAs("Filename.xl开发者_如何转开发s", Excel.XlFileFormat.xlWorkbookNormal, misValue, misValue, misValue, misValue, Excel.XlSaveAsAccessMode.xlExclusive, misValue, misValue, misValue, misValue, misValue);

xlWorkBook.Close(true, misValue, misValue);
xlApp.Quit();

System.Runtime.InteropServices.Marshal.ReleaseComObject(xlWorkSheet);
System.Runtime.InteropServices.Marshal.ReleaseComObject(xlWorkBook);
System.Runtime.InteropServices.Marshal.ReleaseComObject(xlApp);

xlWorkSheet = null;
xlWorkBook  = null;
xlApp       = null;
GC.Collect();


You can always display the xlApp using

xlApp.Visible = true;


Insert this line xlApp.Visible = true;, and don't call Close() and Quit() methods

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜