2017-12-28 5 views
0

루프를 이해하려고 시도하는 것은 무엇입니까 알아 내려는 시도는 복사 프로세스를 반복하여 배열을 증가시켜 주인의 모든 셀을 채울 때까지 빈 셀을 확인합니다. 그것은 모든 것을 통해 잘 실행됩니다. 실제로 105 번 실행해야하기 때문에이 루프를 반복하는 방법을 모릅니다.Excel 통합 문서 루핑

class ExcelCopy 
    { 
    static void Main() 
    { 

     string[] filePaths = Directory.GetFiles(@"filelocation", "*.csv"); 
     Excel.Application srcxlApp; 
     Excel.Workbook srcworkBook; 
     Excel.Worksheet srcworkSheet; 
     Excel.Range srcrange; 
     Excel.Application destxlApp; 
     Excel.Workbook destworkBook; 
     Excel.Worksheet destworkSheet; 
     Excel.Range destrange; 
     string srcPath; 
     string destPath; 

     srcPath = filePaths[0];    
     srcxlApp = new Application(); 
     srcworkBook = srcxlApp.Workbooks.Open(srcPath);    
     srcworkSheet = srcworkBook.Worksheets.get_Item(1); 
     srcrange = srcworkSheet.Cells[1,1]; 
     srcrange.Copy(Type.Missing); 

     destPath = @"filelocaton.xlsx"; 
     destxlApp = new Excel.Application(); 
     destworkBook = destxlApp.Workbooks.Open(destPath, 0, false); 
     destworkSheet = destworkBook.Worksheets.get_Item(1); 
     destrange = destworkSheet.Cells[2, 3]; 
     destrange.Select(); 

     destworkSheet.Paste(Type.Missing, Type.Missing); 

     Range currentFind = null; 
     Range firstFind = null; 

     Range NetSales = destworkSheet.Range["C2", "C106"];  
     currentFind = NetSales.Find(null, Excel.XlFindLookIn.xlValues); 

while(currentFind != null) 
{ 
    // Keep track of the first range you find. 
    if (firstFind == null) 
    { 
     firstFind = currentFind; 
    } 


    else if (currentFind.get_Address(Excel.XlReferenceStyle.xlA1) 
      == firstFind.get_Address(Excel.XlReferenceStyle.xlA1)) 
    { 
       break; 
    }  

    currentFind = NetSales.FindNext(currentFind); 

} 
     destworkBook.SaveAs(@"filelocation" + DateTime.Now.ToString("MM_dd_yyyy") + ".xlsx"); 
     srcxlApp.Application.DisplayAlerts = false; 
     destxlApp.Application.DisplayAlerts = false; 
     destworkBook.Close(true, null, null); 
     destxlApp.Quit(); 
     srcworkBook.Close(false, null, null); 
     srcxlApp.Quit(); 

답변

0

정확히 무엇을하려고합니까? 범위를 하나의 시트로 병합 하시겠습니까? 한 장에 시트를 병합 하시겠습니까? 통합 문서를 하나의 통합 문서로 병합 하시겠습니까? 좀 더 자세히 설명해주세요.

관련 문제