Microsoft.Office.Interop.Excel really slow

前端 未结 8 1535
执笔经年
执笔经年 2020-11-27 13:43

I am exporting a 1200 X 800 matrix (indexMatrix) to a excel file using the standard Microsoft.Office.Interop.Excel. The app works, just that it is really really really slow(

8条回答
  •  有刺的猬
    2020-11-27 14:34

    There are three ways to do this, 2 of which are mentioned in different answers by others:

    1. Directly set the value of a range in excel to the 2D array.
    2. Write data to a CSV file, then use interop to save the CSV file as an xls or xlsx file.
    3. Write data to a CSV file, then use the data connections feature to use the CSV as a data source and import the data.

    All the three methods above are very fast. I could write data with a size of 90000 rows and 100 columns in around 6 seconds.

    P.S. They didn't however solve my problem with formatting the data for borders, font styles, colors, cell merging etc.

提交回复
热议问题