日期:2014-05-19  浏览次数:20415 次

如何循环复制excel文件中的一行
我想把excel文件的第一行循环复制到第3,5,7。。。。行
请问有没有什么办法   谢谢先

------解决方案--------------------
protected void Page_Load(object sender, EventArgs e)
{
ApplicationClass oExcel = new ApplicationClass();
Workbook oBook;
Worksheet oSheet;
Range originalRange, destinationRange;
string path = Server.MapPath( "../documents/test.xls ");
int i = 3;

oBook = oExcel.Workbooks.Open(path, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
oSheet = (Worksheet)oBook.Worksheets[1];

originalRange = (Range)oSheet.Rows[1, Type.Missing];

while (i < 10)
{
destinationRange = (Range)oSheet.Rows[i, Type.Missing];
i = i + 2;
originalRange.Copy(destinationRange);
}

oExcel.DisplayAlerts = false;
oBook.Save();
oExcel.Quit();

}