C# 剑道树人出口问题
演示后: 我们正在尝试在剑道树列表中实现excel导出。 问题是,下载时,excel文件没有数据,只有列的标题C# 剑道树人出口问题,c#,asp.net-mvc,kendo-ui,telerik,export-to-excel,C#,Asp.net Mvc,Kendo Ui,Telerik,Export To Excel,演示后: 我们正在尝试在剑道树列表中实现excel导出。 问题是,下载时,excel文件没有数据,只有列的标题 <%: Html.Kendo().TreeList<A.Models.ExportModel>() .Name("treelist") .Columns(columns => { columns.Add().Field(e => e.AC
<%: Html.Kendo().TreeList<A.Models.ExportModel>()
.Name("treelist")
.Columns(columns =>
{
columns.Add().Field(e => e.ACTIVITY).Title("Activity").Width(400);
})
.Toolbar(tools => tools.Excel())
.Excel(excel => excel.FileName("TreeListExport.xlsx").ProxyURL(Url.Action("Excel_Export_Save")))
.DataSource(dataSource => dataSource
.Read(read => read.Action("getActivityData", "ExportActivity"))
.ServerOperation(false)
.Model(m => {
m.Id(f => f.PK);
m.ParentId(f => f.PA);
m.Expanded(true);
m.Field(f => f.ACTIVITY);
})
)
.Height(540)
%>
[HttpPost]
public ActionResult Excel_Export_Save(string contentType, string base64, string fileName)
{
var fileContents = Convert.FromBase64String(base64);
return File(fileContents, contentType, fileName);
}
{
columns.Add().Field(e=>e.ACTIVITY).Title(“ACTIVITY”).Width(400);
})
.Toolbar(tools=>tools.Excel())
.Excel(Excel=>Excel.FileName(“TreeListExport.xlsx”).ProxyURL(Url.Action(“Excel\u Export\u Save”))
.DataSource(DataSource=>DataSource
.Read(Read=>Read.Action(“getActivityData”、“ExportActivity”))
.ServerOperation(错误)
.Model(m=>{
m、 Id(f=>f.PK);
m、 ParentId(f=>f.PA);
m、 扩展(真);
m、 字段(f=>f.ACTIVITY);
})
)
.高度(540)
%>
[HttpPost]
public ActionResult Excel\u导出\u保存(字符串contentType、字符串base64、字符串文件名)
{
var fileContents=Convert.FromBase64String(base64);
返回文件(文件内容、内容类型、文件名);
}
我们如何解决这个问题?我刚刚遇到了这个问题。您需要截获Excel导出事件,并编写JavaScript以将值转换为表中所需的值
.Toolbar(tools => tools.Excel())
.Excel(excel => excel.FileName("LocationHierarchy.xlsx").ProxyURL(Url.Action("ExcelExportSave")))
.Events(events => events.ExcelExport("onExcelExport"))
听起来您已经知道需要为ExcelExportSave()方法执行哪些操作,所以我不赘述
声明JavaScript方法,如下所示:
// groom the exported values
function onExcelExport(e) {
var workbook = e.workbook;
var i = 0;
// loop through all the worksheets
for (i = 0; i < workbook.sheets.length; ++i) {
// iterate over all the rows, skipping the first since it is just the column headings
var j = 0;
for (j = 1; j < workbook.sheets[i].rows.length; ++j) {
var thisRow = workbook.sheets[i].rows[j];
// iterate over all the cells
for (k = 0; k < thisRow.cells.length; ++k) {
var cellData = thisRow.cells[k];
var cellValue = cellData.value;
// do your special stuff so your values show up like you want
// this often just requires digging into an object and getting the correct member value
// slap the value in cellData.value to make them appear in the Excel spreadsheet
cellData.value = myCoolNewValue;
}
}
}
}
//整理导出的值
函数onExcelExport(e){
var工作簿=e.workbook;
var i=0;
//循环浏览所有的工作表
对于(i=0;i
就这样。那么您导出的Excel很漂亮。我刚刚遇到了这个问题。您需要截获Excel导出事件,并编写JavaScript以将值转换为表中所需的值
.Toolbar(tools => tools.Excel())
.Excel(excel => excel.FileName("LocationHierarchy.xlsx").ProxyURL(Url.Action("ExcelExportSave")))
.Events(events => events.ExcelExport("onExcelExport"))
听起来您已经知道需要为ExcelExportSave()方法执行哪些操作,所以我不赘述
声明JavaScript方法,如下所示:
// groom the exported values
function onExcelExport(e) {
var workbook = e.workbook;
var i = 0;
// loop through all the worksheets
for (i = 0; i < workbook.sheets.length; ++i) {
// iterate over all the rows, skipping the first since it is just the column headings
var j = 0;
for (j = 1; j < workbook.sheets[i].rows.length; ++j) {
var thisRow = workbook.sheets[i].rows[j];
// iterate over all the cells
for (k = 0; k < thisRow.cells.length; ++k) {
var cellData = thisRow.cells[k];
var cellValue = cellData.value;
// do your special stuff so your values show up like you want
// this often just requires digging into an object and getting the correct member value
// slap the value in cellData.value to make them appear in the Excel spreadsheet
cellData.value = myCoolNewValue;
}
}
}
}
//整理导出的值
函数onExcelExport(e){
var工作簿=e.workbook;
var i=0;
//循环浏览所有的工作表
对于(i=0;i
就这样。那么您导出的Excel是漂亮的。返回文件之前,
base64
的值是多少?它不会进入ActionResult@diiN\u。如果单击导出按钮时出现错误,请检查开发人员工具中的网络活动。没有错误@diiN\u但是,ActionResult不是强制性的,没有它也能用@diiN_返回文件之前,base64
的值是多少?它不会进入ActionResult@diiN_。如果单击导出按钮时出现错误,请检查开发人员工具中的网络活动。没有错误@diiN_。但是,ActionResult不是强制性的,没有它也可以工作@迪因_