Microsoft.Office.Interop.Excel sehr langsam

Ich exportiere eine 1200 X 800-Matrix (indexMatrix) in eine Excel-Datei unter Verwendung des Microsoft.Office.Interop.Excel-Standards. Die App funktioniert nur, dass sie wirklich sehr sehr langsam ist (sogar für die 100 x 100 Matrix). Ich exportiere auch in eine Textdatei über einen TextWriter und es funktioniert fast sofort. Gibt es eine Möglichkeit, schneller in die Excel-Datei zu exportieren?

Hier ist mein Code:

        Excel.Application xlApp=new Excel.Application();
        Excel.Workbook xlWorkBook;
        Excel.Worksheet xlWorkSheet;
        object misValue = System.Reflection.Missing.Value;

        //xlApp = new Excel.ApplicationClass();
        xlWorkBook = xlApp.Workbooks.Add(misValue);

        xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);
        for (int i = 0; i < 800; i++)   //h
            for (int j = 0; j < 1200; j++)
                xlWorkSheet.Cells[i+1,j+1] =indexMatrix[i][j];


        xlWorkBook.SaveAs("C:\\a.xls", Excel.XlFileFormat.xlWorkbookNormal, misValue, misValue, misValue, misValue, Excel.XlSaveAsAccessMode.xlExclusive, misValue, misValue, misValue, misValue, misValue);
        xlWorkBook.Close(true, misValue, misValue);
        xlApp.Quit();

        releaseObject(xlWorkSheet);
        releaseObject(xlWorkBook);
        releaseObject(xlApp);

        MessageBox.Show("Excel file created , you can find the file c:\\csharp-Excel.xls");

Antworten auf die Frage(14)

Ihre Antwort auf die Frage