We often submit it to an Excel file. Let's talk about how to operate Excel in the C # program today. Here, we mainly import and export data. On the page, you may often see clicking a button to download the display information of controls such as GridView. How does one download data in a program? In fact, the simple method is to save this set of regular data to the local file system in Excel mode. Let me call this method a "program method. The following shows the specific Code implementation: View Code when we call this method by clicking the Button, we will be surprised to find that the page is running, as shown in the following scenarios: are you "stunned. Haha, it is clear that my control Gridview is placed in a form with runat = server? In fact, you only need to override the VerifyRenderingInServerForm event. The Code is as follows: View Code here describes a similar solution. You do not need to rewrite the above event. The method is as follows: View Code is a lot of similar methods) both are written to the local file system by writing the HTTP Response output stream. We know that Excel is a small database model. I would like to call it the "Oledb" method. Therefore, we can consider using data access to achieve the above effect. First, introduce Microsoft. Office. Interop. Excel; View Code and above are the export of Excl. Let's take a look at the View Code imported from Excel. connection strings are involved here. For details, see: string strConn = @ "Provider = Microsoft. jet. oleDb.4.0; "+" data source = "+ filePath +"; Extended Properties = 'excel 8.0; HDR = Yes; IMEX = 1' "; // This connection can only operate on the top of excel2007(.xls) file string strCon = @ "Provider = Microsoft. ace. oleDb.12.0; "+" data source = "+ fileName +"; Extended Properties = 'excel 12.0; HDR = Yes; IMEX = 1' "for different office versions, the connection string is also different. The idea is that when we use a program to export data and then import data using Excel "Oledb", the following problems may occur. Check: This is a non-standard excel file caused by program export. This is a disadvantage of program export. Appropriate processing is required. During the export process, we will introduce it here for time reasons. The following is my ExcelOperation class: View Code Haha. It's a bit late. I'm going to bed for cainiao. Prepare for tomorrow's miserable life. January 16.