npoi导出大批量数据性能优化

npoi导出大批量数据性能优化

 

优化后的代码:

确保每次下载的执行线程只有1个
private static ConcurrentDictionary<string, string> concurrent_dictionary_download_thread = new ConcurrentDictionary<string, string>();

  

 if (concurrent_dictionary_download_thread.get_val_by_key("key_big_data_download") == "1")
            {
                return false;
            }

            concurrent_dictionary_download_thread.try_add_x("key_big_data_download", "1");

  

 

var workbook = new SXSSFWorkbook(new XSSFWorkbook(), 1000); //20250707



if (rowIndex % 1000 == 0)
                    {
                        ((SXSSFSheet) sheet).FlushRows();
                    }





workbook.Dispose(); //20250707

  

 

测试结果:

 

 

 

 

done

 

posted @ 2025-07-10 16:02  liskov_design  阅读(11)  评论(0)    收藏  举报