在web中js实现类似excel的表格控件
Execl功能⾮常强⼤,内置的很多函数或公式可以⼤⼤提⾼对数据的加⼯处理能⼒。那么在web中有没有类似的控件呢?经过⼀番搜寻,发现handsontable具备了基本的excel功能⽀持公式,同时能对数据进⾏实时编辑。另外⽀持拖动复制、Ctrl+C 、Ctrl+V 等等。在浏览器⽀持⽅⾯,它⽀持以下的浏览器: IE7+, FF, Chrome, Safari, Opera。⾸先引⼊相关库⽂件,公式⽀持不包含在handsontable.full.js中,需要单独引⼊:
在HTML中放置⼀个Div容器来存放handsontable控件:
在javascript代码中,⾸先获取div容器,然后创建表格控件:
其中 =SUM(B5,E3)的公式是RuleJs提供的,return 1+2是⾃⼰实现的C#代码脚本,需要单击解析:
public class CSEngine : IHttpHandler { private static int count = 0;
public void ProcessRequest (HttpContext context) { context.Response.ContentType = \"text/plain\";
try {
count++;
string ret = \"\";
string code = context.Request[\"code\"].ToString(); if (string.IsNullOrEmpty(code)) {
ret = \"参数错误\"; } else {
ScriptOptions options = ScriptOptions.Default .AddReferences(
Assembly.GetAssembly(typeof(DBServices.DataAccess)) )
//.AddImports(\"System.Data\")
//.AddImports(\"System.Data.SqlClient\") .AddImports(\"DBServices\");
var state = CSharpScript.RunAsync(code, options).Result.ReturnValue; ret = state.ToString(); state = null; options = null; }
Console.WriteLine(count); context.Response.Write(ret); }
catch(Exception ex) {
//error
Console.WriteLine(count); } }
public bool IsReusable { get {
return false; } }}
运⾏代码,如下:
以上就是本⽂的全部内容,希望对⼤家的学习有所帮助,也希望⼤家多多⽀持。