When you use Excel as a report, you may encounter paging, which is divided into multiple sheet display, if you want to keep the header on each page, you need to copy the first page as a template design of the header part of the other sheet, then use the copy of the cell in Excel.
The following code shows how to copy the selection on one sheet to another sheet:
thisapplication = new Excel.Application (); ThisWorkbook = ThisApplication.Workbooks.Open ("Z:\\book1.xls", Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing);
Thisapplication.displayalerts = false;
Xlsheet = (Excel.Worksheet) ThisWorkbook.Worksheets.get_Item (1);
Excel.Range Range = Xlsheet.get_range ("A1", Type.Missing); Range.
Value = "123";
Excel.Worksheet Sheet1 = (Excel.Worksheet) ThisWorkbook.Worksheets.get_Item (2);
Excel.Range Range1 = Sheet1.get_range ("B1", Type.Missing); Range.
Copy (Range1); Thisworkbook.saveas ("Z:\\book2.xls", Type.Missing, Type.Missing, Type.Missing, TYP E.missing, Type.Missing, Excel.XlSaveAsAccessMode.xlNoChange, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
As you can see, the core code is very simple, is to select one of the source areas and then specify another target area, and the copy method of the source area is called to copy the entire content to the target area, but you will find that the properties of the cell are copied together, if you want to copy only the text in the cell? It's going to use the Windows clipboard:
xlSheet = (Excel.Worksheet)ThisWorkbook.Worksheets.get_Item(1);
Excel.Range range = xlSheet.get_Range("A1", Type.Missing);
range.Value = "123";
System.Windows.Forms.Clipboard.SetDataObject(range.Value.ToString());
Excel.Worksheet sheet1 = (Excel.Worksheet)ThisWorkbook.Worksheets.get_Item(2);
Excel.Range range1 = sheet1.get_Range("B1", Type.Missing);
sheet1.Paste(range1, false);
Note that this is a way to select only one cell, copy one, and not select a batch of cells to copy.
The above example only gives the main part of the code, other such as the destruction of Excel processes such as operations, please refer to the previous several Excel for the report of the essay.