尝试编写代码以在Excel中的N行移动块,但到目前为止没什么。建议您可以这样做:
namespace MoveBlockExcel
{
class Program
{
static void Main(string[] args)
{
Application objExcel = new Application();
objExcel.DisplayAlerts = false;
objExcel.Range range = ObjWorkSheet.get_Range("B10:F15");
range.Paste(ObjWorkSheet.get_Range("B1:F5"));
Workbook objWorkBook = objExcel.Workbooks.Open("C:\\Template_Modified.xls");
Worksheet objWorkSheet = objWorkBook.Sheets[3];
}
}
}
但根据未找到的objExcel,代码未编译。
答案 0 :(得分:0)
这应该缩小范围B10:F15
并将其粘贴到B1:F5
。
var app = new Microsoft.Office.Interop.Excel.Application();
app.Visible = true;
var workbook = app.Workbooks.Open("C:\\Template_Modified.xls");
Worksheet worksheet = app.ActiveSheet;
worksheet.Range["B10:F15"].Cut(worksheet.Range["B1:F5"]);
确保您的refences包含Microsoft.Office.Interop.Excel: