Export in Excel funktioniert nicht (Spaltenproblem)



  • Hallo miteinander

    Ich habe ein kleines Problem:
    Bei einem Export von grossen Arrays habe ich die Lösung über das Clipboard gewählt. Aber leider werden die Daten nicht in die Spalten getrennt.

    Ich habe diese Seite als Referenz gewählt:
    http://support.microsoft.com/kb/306023/de

    Excel.Range currentFind = null; 
    Excel.Range firstFind = null;
    Excel.Application xlApp;
    Excel.Range xlRange = null;
    Excel.Workbook xlWorkBook;
    Excel.Worksheet xlWorkSheet;
    
    xlApp = new Excel.ApplicationClass();
    xlWorkBook = xlApp.Workbooks.Open(openFileDialog1.FileName.ToString(), 
                                    0, true, 5, "", "", true, Excel.XlPlatform.xlWindows, 
                                    "\t", false, false, 0, true, 1, 0);
    xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);
    currentFind = xlWorkSheet.Cells.Find(g__strSearchKey, Type.Missing,
                                        Excel.XlFindLookIn.xlValues, Excel.XlLookAt.xlPart, 
                                        Excel.XlSearchOrder.xlByRows, Excel.XlSearchDirection.xlNext, false,
                                        Type.Missing, Type.Missing); 
    
    // Copy a string to the Windows clipboard.
    string sData = "FirstName\tLastName\tBirthdate\r\n" +
        "Bill\tBrown\t2/5/85\r\n" +
        "Joe\tThomas\t1/1/91";
    Clipboard.SetDataObject(sData);
    
    // Paste the data starting at cell A1.
    xlRange = xlWorkSheet.get_Range(currentFind.get_Address(Type.Missing, Type.Missing, 
                                                        XlReferenceStyle.xlA1, Type.Missing, 
                                                        Type.Missing),
                                    Type.Missing);
    xlWorkSheet.Paste(xlRange, false);
    
    // Save the workbook.
    xlWorkBook.SaveAs(saveFileDialog2.FileName,
                        Excel.XlFileFormat.xlXMLSpreadsheet, Type.Missing, Type.Missing,
                        false, false, Excel.XlSaveAsAccessMode.xlNoChange,
                        Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
    

    Die Daten werden an eine definiere Stelle (über Template) platziert. Soweit funktioniert es, auch der Zeilenwechsel. Aber nicht das Trennen...
    (Code ist etwas zusammengeschnitten, da noch OpenFileDialog und SaveFileDialog vorhanden sind).

    Hat jemand Rat?
    MFG
    P51D



  • Hab das Problem gefunden:

    xlWorkBook = xlApp.Workbooks.Open(openFileDialog1.FileName.ToString(),
                                    0, true, 1, "", "", true, Excel.XlPlatform.xlWindows,
                                    "\t", false, false, 0, true, 1, 0);
    

    Was eigentlich der ersten Version entspricht, aber diese läuft aus irgend einem Grund nicht.
    Tabs als Trenner ok, aber wieso werden diese dann auch bei Custem-Char nicht anerkannt?

    MFG


Anmelden zum Antworten