Пример #1
0
 public void copyRange(Excel.Worksheet source, Excel.Worksheet dest, String startCell, String endCell, String startDest)
 {
     // get the length of the range - this might need to change later, figured it would be
     // easier if this just adapted by itself.
     int end = System.Convert.ToInt32(endCell.Substring(1)) + System.Convert.ToInt32(startDest.Substring(1));
     String col = startDest.Substring(0, 1);
     String row = end.ToString();
     String destEnd = col + row;
     // select the source worksheet
     source.Select();
     // get the cell range
     Excel.Range reel = source.get_Range(startCell, endCell);
     // copy our data
     reel.Copy();
     // select the destination worksheet
     dest.Select();
     // pick our destination cell
     Excel.Range targetCell = dest.get_Range(startDest, destEnd);
     try
     {
         targetCell.Select();
     }
     catch (Exception e)
     {
         System.Windows.Forms.MessageBox.Show(e.Message.ToString(), "Error - target cells not empty", System.Windows.Forms.MessageBoxButtons.OK);
         return;
     }
     // paste our data
     dest.Paste(targetCell);
 }