大塊資料填充Excel快速演算法

來源:互聯網
上載者:User
ListView中存放了大約1000條記錄,每條記錄有50多個欄位,若用for迴圈將資料搬移到excel中速度異常緩慢,有沒有快速演算法?請高手指導~~

用數組,或DataTable填充,速度賊快
使用多個儲存格寫入的速度遠快於對儲存格進行逐個寫入,因此是提高產生Excel速度的一個重要途徑。   
    
 範例程式碼  
   
  Excel.Application   xApp   =   new   Excel.ApplicationClass();  
  string[,]   strs   =   new   string[9,   9];  
  for(int   i   =   0;   i   <   9;   i++)  
  for(int   j   =   0;   j   <   9;   j++)  
  strs[i,   j]   =   Convert.ToString((i   +   1)   *   (j   +   1));  
   
  Excel.Workbook   xBook   =   xApp.Workbooks.Add(Missing.Value);  
  Excel.Worksheet   xSheet   =   (Excel.Worksheet)xBook.Worksheets[1];  
  xSheet.get_Range(xSheet.Cells[1,   1],   xSheet.Cells[9,   9]).Value   =   strs;  

如同List.AddRange()比迴圈用List.Add()速度快

先把資料填充到一個二維數組   
再將二維數組填充到RANGE   
用種方法匯入過5萬行資料   
只用了10秒

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.