c# using excel to open xml file [duplicate]

2019-07-16 09:57发布

This question already has an answer here:

how do i open an xml file using excel with c# winforms?

i am saving data to an XML file and i need the user to be able to see the file as soon as the application updates the xml file. i need the file to be opened with excel

2条回答
男人必须洒脱
2楼-- · 2019-07-16 10:14

You need to use the Excel Interop library. Here is an example of creating a new Spreadsheet. Opening a file isn't much different. http://msdn.microsoft.com/en-us/library/ms173186%28VS.80%29.aspx

If you only need to open the file, so the user can see it, use GendoIkari's method. If you need to interact with the file or read it, then use Interop.

查看更多
一夜七次
3楼-- · 2019-07-16 10:26

Process.Start() method. Using this you will be able to launch Excel, passing in the appropriate parameters to send it your XML file.

Here's the command line switches for Excel.

Example:

System.Diagnostics.Process.Start("c:\\program files\\microsoft office\\office12\\excel.exe", "/r \"c:\\My Folder\\book1.xlsx\"");
查看更多
登录 后发表回答