2016-09-19 179 views
-3

當我進行AJAX調用以接收在此C#代碼中定義的JSON對象時,我必須等待46+秒以接收此對象。該對象本身只有12kb大。是否因爲我的C#代碼(這不需要很長的時間來執行?)是另一回事。我在我的本地主機IIS服務器上測試它。爲什麼我的ajax調用需要這麼長時間?

這是我的代碼:

[AcceptVerbs(HttpVerbs.Post)] 
    public JsonResult LoadAudit(int id, string sheet) 
    { 
     FactsCustomerRepository<Cateringaudit> repo = new FactsCustomerRepository<Cateringaudit>(); 
     //IQueryable<Cateringaudit> result = repo.GetAll(i => i.State == 1); 
     Cateringaudit result1 = repo.Get(id); 
     WorkBook wb = new WorkBook(); 
     wb.read(new MemoryStream(result1.ExcelData)); 
     object[] jsonObjects = new object[3]; 
     //sheetnames to collect data from 
     string[] sheetNames = { "contract", "proces", "output" }; 
     //itterate trough all sheets in excel file 
     for (int sheetCount = 0; sheetCount < sheetNames.Length; sheetCount++) 
     { 
      wb.Sheet = wb.findSheetByName(sheetNames[sheetCount]); 
      //Create new array with same lenght as rows with data 
      Dictionary<string, string[]> excelData = new Dictionary<string, string[]>(); 
      //iterate trough all rows in worksheet 
      for (int i = 1; i < wb.LastRow + 2; i++) 
      { 
       excelData.Add(blabla); 
       jsonObjects[sheetCount] = excelData; 
      } 
     } 
     return Json(jsonObjects); 
    } 
+0

是以上所有代碼需要的問題? –

+3

嘗試記錄重要行的每一步。日誌應該有時間戳。然後,你可以從那裏調查。 –

+0

問題在哪裏涉及到上面的代碼?這絕對與AJAX毫無關係。請修改您的問題 – Radinator

回答

0

走出去的肢體在這裏:在C#中打開Excelsheets是可笑緩慢。有大圖書館在那裏它們的方式更快:

EEPLUS:http://epplus.codeplex.com/

但要排除Excel首先:你嘗試返回一個靜態的JSONObject,而不是使用Excel?

[AcceptVerbs(HttpVerbs.Post)] 
public JsonResult LoadAudit(int id, string sheet) 
{ 
    return Json(); // something like this 
} 
+0

Downvote and close vote,without comment。謝謝! – RvdK

+0

這確實是Excel讓它變得如此之慢,我返回了一個靜態的JSON對象。起初我使用的是Spreadsheetlight,現在我使用SmartXLS,我讀到的比電子表格光源要快得多。 – Basvo

相關問題