Angular6 如何将角度6栅格数据导出到excel?
要将angular 6网格数据导出到客户端的ms excel文件中吗Angular6 如何将角度6栅格数据导出到excel?,angular6,Angular6,要将angular 6网格数据导出到客户端的ms excel文件中吗 Finally Got Solution on my Question export at client side Using Angular 6 const worksheet: XLSX.WorkSheet = XLSX.utils.json_to_sheet(this.callRecordingModels); /* generate workbook and add the worksheet *
Finally Got Solution on my Question export at client side Using Angular 6
const worksheet: XLSX.WorkSheet =
XLSX.utils.json_to_sheet(this.callRecordingModels);
/* generate workbook and add the worksheet */
const wb: XLSX.WorkBook = XLSX.utils.book_new();
XLSX.utils.book_append_sheet(wb, worksheet, 'Sheet1');
/* save to file */
XLSX.writeFile(wb, this.fileName);
我曾尝试使用MVC5使用WebAPI,但问题是无法将数据从datatable(即服务器端)发送到客户端进行导出
用于将数据导出到excel的C#代码,但无法在客户端发送datatable数据以将其导出到excel文件中
if (callrec != null)
{
DataTable dt = new DataTable();
dt.Columns.AddRange(new DataColumn[7] {
new DataColumn("RECORDING FILE NAME",typeof(string)),
new DataColumn("ACCOUNT NUMBER",typeof(string)),
new DataColumn("CALL START TIME",typeof(string)),
new DataColumn("AGENT NAME",typeof(string)),
new DataColumn("AGENT RESULT",typeof(string)),
new DataColumn("DURATION SECONDS",typeof(string)),
new DataColumn("PHONE DIALED",typeof(string))
});
foreach (var item in callrec)
{
dt.Rows.Add(item.RecFileName,
item.AccountNo == "NULL" ? "" : item.AccountNo,
item.CallStartTime == null ? null :
item.CallStartTime,
item.agentName == "NULL" ? "" : item.agentName,
item.agentResults == "NULL" ? "" :
item.agentResults,
item.DurationSecs,
item.phoneDialed == "NULL" ? "" : item.phoneDialed);
};
using (ClosedXML.Excel.XLWorkbook wb = new
ClosedXML.Excel.XLWorkbook())
{
var ws = wb.Worksheets.Add(dt, "CallRecording");
ws.Tables.FirstOrDefault().ShowAutoFilter = false;
MemoryStream stream = GetStream(wb);
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.ClearContent();
HttpContext.Current.Response.Buffer = true;
HttpContext.Current.Response.AddHeader("Access-Control-
Allow-Origin", "*");
HttpContext.Current.Response.AddHeader("Access-Control-
Allow-Headers", "Origin, X-Requested-With, Content-
Type, Accept");
HttpContext.Current.Response.AddHeader("content-
disposition", "attachment; filename=
CallRecording.xlsx");
HttpContext.Current.Response.ContentType =
"application/vnd.ms-excel";
HttpContext.Current.Response.BinaryWrite(stream.ToArray());
HttpContext.Current.Response.End();
}
}
else if(callrec==null || callrec.Count==0)
{
throw new Exception("Null or empty input table to
export!");
}
}
将数据导出到客户端
Finally Got Solution on my Question export at client side Using Angular 6
const worksheet: XLSX.WorkSheet =
XLSX.utils.json_to_sheet(this.callRecordingModels);
/* generate workbook and add the worksheet */
const wb: XLSX.WorkBook = XLSX.utils.book_new();
XLSX.utils.book_append_sheet(wb, worksheet, 'Sheet1');
/* save to file */
XLSX.writeFile(wb, this.fileName);