The following small series for everyone to bring a C # WinForm open Excel Document Method Summary (must read). Small series feel very good, now share to everyone, also for everyone to make a reference. Let's take a look at it with a little knitting.
C # Open Excel document method One: Calling Excel's COM component
Open the Add Reference dialog box in the project, select the COM bar, and then find the Microsoft Excel 11.0 Object Library in the COM list (Office 2003), and then add it to the project's references. Visual C #. NET automatically generates the corresponding. NET component files that can be used in the future.
The Click event for the button is as follows:
Privatevoid Button1_Click (object sender, EventArgs e) { Excel.Application Excel = new Excel.Application (); Reference the Excel object excel.workbook book = Excel. APPLICATION.WORKBOOKS.ADD ("C:\\test.xls"); Reference Excel workbook Excel. Visible = true; Make Excel Visible}
C # Open Excel document Method II: Using the command line
We enter C:\\test.xls in the start → run, and if the computer is installed with Excel, he will automatically open the file, the code is as follows:
Privatevoid Button1_Click (object sender, EventArgs e) { System.Diagnostics.Process.Start ("C:\\test.xls");}
A description of how C # opens an Excel document is introduced here and is useful for you to learn and learn about C # Open Excel documents.
My point of view:
private void Button1_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 already existing Excel, //and open the existing SHP by GDAL, by// OSGeo.GDAL.Gdal.AllRegister (); OSGeo.GDAL.Dataset Dataset = OSGeo.GDAL.Gdal.Open (@ "E:\Work\DemoBase_091111\GDALTEST\testshapefile\point_ Out.shp ", access.ga_readonly); The two are similar, one with the Add method, an open method, all get the next steps can be done by the file, the technology has the same sex app. Visible = true; }