У меня есть следующий код для копирования Sheet1 из рабочей книги (test1.xlsx) в другую рабочую книгу (test2.xlsx).В коде нет ошибок, его выполнение занимает вечность, и мне пришлось остановить код без изменений в файлах.Пожалуйста, дайте мне знать, что не так.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Excel = Microsoft.Office.Interop.Excel;
namespace Read_from_Excel_file
{
class Program
{
static void Main(string[] args)
{
Excel.Application xlApp = new Excel.Application();
Excel.Workbook test1 = xlApp.Workbooks.Open(@"C:\Users\namokhtar\Desktop\test1.xlsx");
Excel.Workbook test2 = xlApp.Workbooks.Open(@"C:\Users\namokhtar\Desktop\test2.xlsx");
test2.Worksheets.Copy(test1.Worksheets["Sheet1"]);
test2.Save();
test1.Close();
test2.Close();
xlApp.Quit();
}
}
}