使用Excel的哪种方法更快?

时间:2011-06-19 14:14:39

标签: c# office-interop

我在我的程序中使用Interop.Excel。我需要改变细胞的价值。你能说更快的方法吗?

ChangeValue1()
{
 object c1, c2;
 c1 = (Range)excelworksheet.Cells[1, 1];
 c2 = (Range)excelworksheet.Cells[2,2];
 Range cell1 = (Range)excelworksheet.get_Range(c1, c2);
 cell1.Copy(Type.Missing);
 c1 = (Range)excelworksheet.Cells[3, 1];
 c2 = (Range)excelworksheet.Cells[4,2];
 Range cell2 = (Range)excelworksheet.get_Range(c1, c2);
 cell2.PasteSpecial(XlPasteType.xlPasteValuesAndNumberFormats, XlPasteSpecialOperation.xlPasteSpecialOperationNone,true, false);
}

 ChangeValue2()
 {
 object c1, c2;
 c1 = (Range)excelworksheet.Cells[1, 1];
 c2 = (Range)excelworksheet.Cells[2,2];
 Range cell1 = (Range)excelworksheet.get_Range(c1, c2);

 c1 = (Range)excelworksheet.Cells[3, 1];
 c2 = (Range)excelworksheet.Cells[4,2];
 Range cell2 = (Range)excelworksheet.get_Range(c1, c2);
 cell2.Value2=cell1.Value2;
 }

0 个答案:

没有答案