当我进行AJAX调用以接收此c#代码中定义的JSON对象时,我需要46秒以上才能接收此对象。对象本身只有12kb大。是因为我的c#代码(执行时间不长吗?)是否是别的东西。我在我的localhost IIS服务器上测试它。
这是我的代码:
[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 :(得分: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
}