我为我的软件开发公司评估了用于ASP.NET MVC的Kendo UI,确实是非常好的小部件;特别是电子表格。 但是在电子表格中尝试导出功能时,我面临着单元格中公式的问题(我想,对于json中的scape双引号来绑定电子表格),方案如下所示:
为了测试和验证的目的,电子表格是从json文件绑定的(就像这里的演示http://demos.telerik.com/aspnet-mvc/spreadsheet/server-side-import-export),在一个单元格中我评估一个公式(AVERAGEIF)的行为,就像一个魅力,json中的公式是:
{ "value": "", "formula":"AVERAGEIF(C2:C5,\"<>39\")", "format": "", "background": "#f2f2f2", "color": "#00b050", "bold": true, "textAlign": "center", "index": 3 }
作为演示,我使用的导出方法是(asp net mvc5 C#):
[HttpPost]
public ActionResult Download(string data, string extension)
{
var workbook = Workbook.FromJson(data);
using (var stream = new MemoryStream())
{
workbook.Save(stream, extension);
var mimeType = Telerik.Web.Spreadsheet.MimeTypes.ByExtension[extension];
return File(stream.ToArray(), mimeType, "Exported" + extension);
}
}
执行后,我收到此错误:
这是堆栈跟踪:
[InvalidOperationException:由于当前操作,操作无效 对象的状态。]
Telerik.Windows.Documents.Spreadsheet.Model.CellValueFactory.CreateFormulaCellValue(字符串 value,Worksheet工作表,Int32 rowIndex,Int32 columnIndex)+123
Telerik.Windows.Documents.Spreadsheet.Model.CellValueFactory.ToFormulaCellValue(字符串 value,Worksheet工作表,Int32 rowIndex,Int32 columnIndex)+48
Telerik.Windows.Documents.Spreadsheet.Model.CellSelection.SetValueAsFormula(字符串 值)+149 Telerik.Web.Spreadsheet.Workbook.SetCells(Row srcRow, 工作表documentSheet)+558
Telerik.Web.Spreadsheet.Workbook.ToDocument()+846
Telerik.Web.Spreadsheet.Workbook.Save(流输出,字符串扩展名) +39 Kendo.Mvc.Examples.Controllers.SpreadsheetController.Download(String 数据,字符串扩展名) C:\电子表格\ Server_Side_Import_ExportController.cs:35个
lambda_method(Closure,ControllerBase,Object [])+ 245 5 System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller,Object []参数)+59
System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext,IDictionary2 parameters) +435
2 参数)+60
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary
System.Web.Mvc.Async.ActionInvocation.InvokeSynchronousActionMethod() +76 System.Web.Mvc.Async.AsyncControllerActionInvoker.b__39(IAsyncResult asyncResult,ActionInvocation innerInvokeState)+36
System.Web.Mvc.Async.WrappedAsyncResult2.CallEndDelegate(IAsyncResult asyncResult) +73
1.End()+ 136
System.Web.Mvc.Async.WrappedAsyncResultBase
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, 对象标签)+102
System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult的 asyncResult)+49
System.Web.Mvc.Async.AsyncInvocationWithFilters.b__3d() +117 System.Web.Mvc.Async。&lt;&gt; c__DisplayClass46.b__3f() +323 System.Web.Mvc.Async。&lt;&gt; c__DisplayClass33.b__32(IAsyncResult asyncResult)+44
System.Web.Mvc.Async.WrappedAsyncResult1.CallEndDelegate(IAsyncResult asyncResult) +47
1.End()+ 136
System.Web.Mvc.Async.WrappedAsyncResultBase
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, 对象标签)+102
System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethodWithFilters(IAsyncResult的 asyncResult)+50
System.Web.Mvc.Async&LT;&GT; c__DisplayClass2b.b__1c() +72 System.Web.Mvc.Async。&lt;&gt; c__DisplayClass21.b__1e(IAsyncResult) asyncResult)+185
System.Web.Mvc.Async.WrappedAsyncResult1.CallEndDelegate(IAsyncResult asyncResult) +42
1.End()+133
System.Web.Mvc.Async.WrappedAsyncResultBase
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, 对象标签)+56
System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult的 asyncResult)+40
System.Web.Mvc.Controller.b__1d(IAsyncResult的 asyncResult,ExecuteCoreState innerState)+34
System.Web.Mvc.Async.WrappedAsyncVoid1.CallEndDelegate(IAsyncResult asyncResult) +70
1.End()+133
System.Web.Mvc.Async.WrappedAsyncResultBase
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, 对象标签)+56
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, 对象标签)+37
System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult)+44 System.Web.Mvc.Controller.b__15(IAsyncResult的 asyncResult,控制器控制器)+39
System.Web.Mvc.Async.WrappedAsyncVoid1.CallEndDelegate(IAsyncResult asyncResult) +62
1.End()+133
System.Web.Mvc.Async.WrappedAsyncResultBase
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, 对象标签)+56
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, 对象标签)+37 System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult)+39
System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.EndExecute(IAsyncResult的 asyncResult)+39
System.Web.Mvc.MvcHandler.b__5(IAsyncResult的 asyncResult,ProcessRequestState innerState)+39
System.Web.Mvc.Async.WrappedAsyncVoid1.CallEndDelegate(IAsyncResult asyncResult) +70
1.End()+133
System.Web.Mvc.Async.WrappedAsyncResultBase
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, 对象标签)+56
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, 对象标签)+37
System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +40 System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult) 结果)+38
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +9721605 System.Web.HttpApplication.ExecuteStep(IExecutionStep step,Boolean&amp; completedSynchronously)+155
当我尝试使用&#34; normal&#34;导出电子表格时公式(那些不需要转义双引号的公式)导出行为按预期工作。
非常感谢您的帮助!