C # How to Use winform to open the Excel document!

Source: Internet
Author: User

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:

  1. Privatevoid button#click (Object sender, eventargs E)
  2. {
  3. Excel. Application Excel =
  4. New excel. Application (); // reference an Excel Object
  5. Excel. Workbook book =
  6. Excel. application. workbooks. Add ("C: \ test.xls ");
  7. // Reference an Excel Workbook
  8. Excel. Visible = true; // make Excel visible
  9. }

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:

  1. Privatevoid button#click (Object sender, eventargs E)
  2. {
  3. System. Diagnostics. process. Start ("C: \ test.xls ");
  4. }

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;

}

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.