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
Parameters:
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 );