I have an Excel \'07 Template file for a purchase order. On the template, there\'s only room for 3 rows worth of items, then the template shows the Total.
So, basica
First of all, I don't see where you are setting your xlWorksheet
but that would be the first place I'd check to see why your cells are being inserted on the wrong sheet.
Secondly, I don't think your Excel.Range
object is being set up properly. You could be running into trouble because you're only specifying row numbers in the WorkSheet.Cells
property and not column names. When I tried that I was getting cells inserted after the used range of cells, not where I wanted. I would be inclined to use the get_Range()
method of the Worksheet
object since that usually works in a more predictable manner.
Given all that, depending on whether you want specific cells shifted down, or the entire row, you can use one of the following:
// To shift down a set of cells from columns A to F
Excel.Range r = xlWorkSheet.get_Range("A" + row.ToString(), "F" + row.ToString());
r.Insert(Excel.XlInsertShiftDirection.xlShiftDown);
// To shift down all of a row
Excel.Range r = xlWorkSheet.get_Range("A" + row.ToString(), "A" + row.ToString()).EntireRow;
r.Insert(Excel.XlInsertShiftDirection.xlShiftDown);