When using VS2010 for web page development, sometimes due to the needs of customers, they want to click the button to directly open the excel document, rather than pop up the open or download dialog box, which is more convenient for users to operate. In this article, I share my experience on this function as follows. I use the development language of c# and modify the syntax of other languages to realize this function.
Microsoft Visual C + + 2010 x64 runtime official installation Free Edition
- Type:Programming tools
- Language:Simplified Chinese
1. Open Microsoft Visual Studio 2010 tool normally, load an existing project or create a new project. The interface is shown in the screenshot below.
2. Choose to add a new item in the solution on the right, as shown in the figure below, or add functions to an existing page.
3. This article takes adding an existing new item as an example. After clicking Add new item, the page is as follows, adding a new itemMultiple web formsAfter naming the new page, click the Add button, as shown in red in the screenshot below.
4. In the new page, pull one from the leftButton to pageAbove, as shown in the screenshot below.
5. Page switch to“Design”The mode is shown in Figure 1 below. Double click theButton buttonAdd a double-click event to it, and the interface changes as shown in screenshot 2 belowA button1 has been added to the. CS page_ Click event。
6. InButton1_ClickAdd the following code to the event:
System.Diagnostics.Process p = new System.Diagnostics.Process();
p.StartInfo.UseShellExecute = true;
p.StartInfo. FileName = @”d:\excelopen.xlsx”;//@ Followed by the path of the excel document
This is the most critical statement to realize the function.
7. At this time, the code has been written. Run the project directly andClick the button in the IE window, you can see the excel file opened directly.