开发者

How to open a Excel file using a command button in C#

开发者 https://www.devze.com 2023-02-22 18:37 出处:网络
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 desktopPut this in your button click event hand

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.

0

精彩评论

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

关注公众号