400 개의 엑셀 파일이있는 폴더가 있습니다. 이 모든 Excel 파일의 워크 시트를 하나의 Excel 파일로 복사해야합니다.C#을 사용한 Excel 자동화
Interop 및 Reflection 네임 스페이스를 사용하면 heres가 지금까지 수행 한 작업입니다.
folderBrowserDialog를 사용하여 폴더를 탐색하고 선택하면 폴더 내의 파일 이름을 가져 와서이 파일을 반복 할 수 있습니다.이 파일은 내가받은만큼 도움이 될 것입니다.
if (result == DialogResult.OK)
{
string path = fbd1.SelectedPath; //get the path
int pathLength = path.Length + 1;
string[] files = Directory.GetFiles(fbd1.SelectedPath);// getting the names of files in that folder
foreach (string i in files)
{
MessageBox.Show("1 " + i);
myExcel.Application excelApp = new myExcel.ApplicationClass();
excelApp.Visible = false;
MessageBox.Show("2 " + i);
myExcel.Workbook excelWorkbook = excelApp.Workbooks.Add(excelApp.Workbooks._Open(i, 0, false, 5, "", "", false, myExcel.XlPlatform.xlWindows, "", true, false, 0, true));
myExcel.Sheets excelSheets = excelWorkbook.Worksheets;
MessageBox.Show("3 " + i);
excelApp.Workbooks.Close();
excelApp.Quit();
}
MessageBox.Show("Done!");
}
복사 한 시트를 대상 파일에 추가하려면 어떻게합니까? 질문이 명확하길 바래요?
감사합니다.
덕분에, 그것을 밖으로 시도 할 것이다 – tecno