C#winform Summary of how to open an Excel document

Source: Internet
Author: User
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;    }
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.