Excel file and data access

Source: Internet
Author: User

First, you must add the MS Office component to the project, and then use the namespace in the code file.
Using Excel;
Then you can use an Excel object.
Declare the following three objects
Application MyApp = NULL;
Workbook mybook = NULL;
Worksheet mysheet = NULL;

MyApp = new application (); // create an Excel application object
// Open the specified Excel file template
Mybook = MyApp. workbooks. Open (fullpathfile, missing, missing );
Mysheet = (worksheet) mybook. worksheets [1]; // specify a data table
Mysheet. Name = sheetname; // you can specify a table name.

Enter data:
Mysheet. cells [row, Col] = data;
Row and column operations:
Range rng1, rng2; // declares row and column objects.
Rng1 = mySheet. get_Range (mySheet. Cells [srow1, scol1], mySheet. Cells [srow2, scol2]); // reference the source row and column
Rng2 = mySheet. get_Range (mySheet. Cells [trow1, tcol1], mySheet. Cells [trow2, tcol2]); // reference target Columns
Srow1 and scol1 are the upper left cell coordinates of the first row (source), srow2 and scol2 are the lower right cell coordinates of the first row (source.
Trow1, tcol1 is the upper left cell coordinate of the second row (target), trow2, tcol2 is the lower right cell coordinate of the second row (target.
Row and column Replication
Rng1.Select ();
Rng1.Copy (missing );
Rng2.PasteSpecial (XlPasteType. xlPasteAll, XlPasteSpecialOperation. xlPasteSpecialOperationNone, missing, missing );

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.