开发者

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.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜