后台返还给我的数据格式是
var data={rows:[{ "id":"1",data:["金华中新",891,94.2,119,30,149,79.9,6,2,8,75.0,0,0,0,1114,144]},
{ "id":"2",data:["金华综合",862,105,9,81.9,143,15,158,90.5,3,0,3,1103,141,1244]},
{ "id":"3",data:["义乌车辆",1216,114,1332,135,5,140,96.4,1,0,1,100,125,1861,93.3]}
]};(标题是在其他地方设置的)
然后我是用dhtmx生成了一个grid,我想通过js把他导出成excel
网上有代码,但是我看不懂,没说明。就大神帮忙,并附带下说明,还有需要那些插件
var data={rows:[{ "id":"1",data:["金华中新",891,94.2,119,30,149,79.9,6,2,8,75.0,0,0,0,1114,144]},
{ "id":"2",data:["金华综合",862,105,9,81.9,143,15,158,90.5,3,0,3,1103,141,1244]},
{ "id":"3",data:["义乌车辆",1216,114,1332,135,5,140,96.4,1,0,1,100,125,1861,93.3]}
]};(标题是在其他地方设置的)
然后我是用dhtmx生成了一个grid,我想通过js把他导出成excel
网上有代码,但是我看不懂,没说明。就大神帮忙,并附带下说明,还有需要那些插件
using NPOI.HSSF.UserModel;
using NPOI.HPSF;
using System.IO; public void GenerateExcel(string fileName,string deptID,string contentType) {
DocumentSummaryInformation dsi = PropertySetFactory.CreateDocumentSummaryInformation();
SummaryInformation si = PropertySetFactory.CreateSummaryInformation();
si.Subject = "One NPOI example";
HSSFWorkbook WB = new HSSFWorkbook();
HSSFCellStyle lo_Style = (HSSFCellStyle)WB.CreateCellStyle();
lo_Style.DataFormat = HSSFDataFormat.GetBuiltinFormat("@");
WB.DocumentSummaryInformation = dsi;
WB.SummaryInformation = si;
dsi.Company = "NPIO Team";
HSSFSheet currentsheet = (HSSFSheet)WB.CreateSheet("sheet1");
WB.CreateSheet("Sheet2");
WB.CreateSheet("Sheet3");
DataTable dt = csm.GetDataTableByStoreprocedureStr("StoreProcedure:" + contentType + ";DeptID:" + deptID);
HSSFRow title = (HSSFRow)currentsheet.CreateRow(0);
for (int s = 0; s < dt.Columns.Count; s++)
{
HSSFCell celltitle = (HSSFCell)title.CreateCell(s);
celltitle.SetCellValue(dt.Columns[s].ColumnName);
}
//cell.SetCellValue(dt.Rows.Count.ToString());
for (int i = 0; i < dt.Rows.Count; i++)
{
HSSFRow row = (HSSFRow)currentsheet.CreateRow(i+1);
for (int j = 0; j < dt.Columns.Count; j++)
{
HSSFCell cell = (HSSFCell)row.CreateCell(j);
cell.SetCellValue(dt.Rows[i][j].ToString());
}
}
FileStream file = new FileStream("d:/TempFiles/"+fileName, FileMode.Create);
WB.Write(file);
file.Close();
}
生成完毕,客户端html注意下载方式。html页面弄一个iframe,生成完毕更新iframe的src即可,
给你一个链接学学教程。.net环境下的。npoi是很简单的易学的,别人不可能手把手教你,只能给你解决的方向。