I monitored it using stopwatch in segments and found that the most time-consuming function was savetoexcel.
This function is used to repeat all data rows in the column, replace the tag to generate an Excel row, and then accumulate the row data to a string.
CopyCodeThe Code is as follows: String excelstring = "";
Foreach (VAR item in list ){
Excelstring + = string. Format ("<row>... {0} </row>", list. Title );
}
See this .. I immediately remembered the warnings of countless martyrs and the memory operating principles of String concatenation. As a result, the code was completely deleted and changed to the following format:Copy codeThe Code is as follows: String excelstring = new stringbuilder ();
Foreach (VAR item in list ){
Excelstring. appendformat ("<row>... {0} </row>", list. Title );
}
The test again immediately increased the efficiency by dozens of times. The first 8000 rows require 30 s, and now only 2 S