2017-12-28 4 views
0

Was ich herausfinden will, ist die beste Möglichkeit, den Kopierprozess zu wiederholen, um das Array zu inkrementieren, bis alle Zellen in meinem Master gefüllt sind, und dann nach leeren Zellen zu suchen. Es läuft durch alles gut, ich weiß wirklich nicht, wie ich das machen werde, da es 105 Mal laufen muss.Looping einer Excel-Arbeitsmappe Merge

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(); 

Antwort

0

Was versuchst du zu tun ... genau? Bereiche in ein Blatt zusammenführen? Blätter zu einem Blatt zusammenfügen? Arbeitsmappen in eine Arbeitsmappe zusammenführen? Bitte etwas mehr ausarbeiten.