Excel insert rows (not Add)

前端 未结 3 1030
盖世英雄少女心
盖世英雄少女心 2020-12-11 20:05

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

3条回答
  •  天命终不由人
    2020-12-11 21:03

    public static void CopyRowsDown(_Worksheet worksheet, int startRowIndex, int countToCopy)
        {
            for (int i = 1; i < countToCopy; i++)
            {
                var range = worksheet.get_Range(string.Format("{0}:{0}", startRowIndex, Type.Missing));
                range.Select();
                range.Copy();
    
                range = worksheet.get_Range(string.Format("{0}:{1}", startRowIndex + i, startRowIndex + i, Type.Missing));
                range.Select();
                range.Insert(-4121);
            }
        }
    

    works for any count

提交回复
热议问题