How to open a Excel file using a command button in C#
I want to create a button so that when pressed it opens a excel document. the 开发者_C百科name of the excel file is Solution.xls and it is placed in the desktop
Put this in your button click event handler:
string filePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Solution.xls")
Process.Start(filePath);
If Excel is already open, it will open the file in the current instance; if not, a new instance of Excel will be created. This also assumes that the target PC associates .xls files with Excel, but that is a fairly safe assumption if Excel is installed.
精彩评论