C # Open Excel document Method 1: Call the Excel COM Component
Open the Add reference dialog box in the project, select the com column, and find "Microsoft Excel 11.0 Object Library" (Office 2003) in the com list ), add it to the project references. Visual C #. Net automatically generates the corresponding. NET component file.
The button clicking event is as follows:
- Privatevoid button#click (Object sender, eventargs E)
- {
- Excel. Application Excel =
- New excel. Application (); // reference an Excel Object
- Excel. Workbook book =
- Excel. application. workbooks. Add ("C: \ test.xls ");
- // Reference an Excel Workbook
- Excel. Visible = true; // make Excel visible
- }
C # open an Excel file Method 2: Use the command line
Enter c: \ test.xls in start → run. If Excel is installed on the computer, the file is automatically opened. The Code is as follows:
- Privatevoid button#click (Object sender, eventargs E)
- {
- System. Diagnostics. process. Start ("C: \ test.xls ");
- }
C # Here is an introduction to the specific methods for opening the Excel document. I hope you can understand and learn C # how to open the Excel document.
My opinion:
Private void button#click (Object sender, eventargs E)
{
Microsoft. Office. InterOP. Excel. Application APP = new Microsoft. Office. InterOP. Excel. Application ();
Workbook WKB = app. workbooks. Add (@ "E: \ work \ demobase_091111 \ csharpopenexcel \ cshapropenexcel.xlsx ");
// Open an existing Excel file,
// Open an existing SHP through gdal. The method is
// Osgeo. gdal. gdal. allregister ();
// Osgeo. gdal. dataset = osgeo. gdal. gdal. Open (@ "E: \ work \ demobase_091111 \ gdaltest \ testshapefile \ point_out.shp", access. ga_readonly );
// The two are similar. One uses the add method and the other uses the open method, and the other gets the files that can be used for the next operation. The technology is similar.
App. Visible = true;
}