I have a Grid with a detail template to show another records related to the main data set. I'm trying to export everyting to excel but when i export it excel says "Excel found unreadable content" if i make the function to return an empty list to the export function the excel file has no problem it shows nothing about details but columns names. but if i return the dataset that i need the message of unreadable content is shown.
i've followed the example http://docs.telerik.com/kendo-ui/aspnet-mvc/helpers/grid/how-to/excel/detail-grid-export and http://docs.telerik.com/kendo-ui/controls/data-management/grid/how-to/excel/detail-grid-export so the functions are practically the same
var detailExportPromises = [];
var dataSource = new kendo.data.DataSource({
type: "aspnetmvc-ajax",
transport: {
read: "@Url.Action("Fracciones_Read", "Home")",
type: "POST"
},
schema: {
data: "Data",
total: "Total",
error: "Errors"
}
});
dataSource.read();
function dataBound() {
detailExportPromises = [];
this.expandRow(this.tbody.find("tr.k-master-row").first());
}
function parameters() {
return {
fechaIni: $("#fechaIni").data("kendoDatePicker").value(),
fechaFin: $("#fechaFin").data("kendoDatePicker").value(),
operacion: "Imp"
}
}
function fracciones_excelExport(e) {
e.preventDefault();
}
function excelExport(e) {
e.preventDefault();
var workbook = e.workbook;
detailExportPromises = [];
var masterData = e.data;
for (var rowIndex = 0; rowIndex < masterData.length; rowIndex++) {
exportChildData(masterData[rowIndex].NumeroPedimento, rowIndex);
}
// wait for all detail grids to finish exporting
$.when.apply(null, detailExportPromises)
.then(function () {
// get the export results
var detailExports = $.makeArray(arguments);
// sort by masterRowIndex
detailExports.sort(function (a, b) {
return a.masterRowIndex - b.masterRowIndex;
});
// add an empty column
workbook.sheets[0].columns.unshift({ width: 30 });
// prepend an empty cell to each row
for (var i = 0; i < workbook.sheets[0].rows.length; i++) {
workbook.sheets[0].rows[i].cells.unshift({});
}
// merge the detail export sheet rows with the master sheet rows
// loop backwards so the masterRowIndex doesn't need to be updated
for (var i = detailExports.length - 1; i >= 0; i--) {
var masterRowIndex = detailExports[i].masterRowIndex + 1;
var sheet = detailExports[i].sheet;
// prepend an empty cell to each row
for (var ci = 0; ci < sheet.rows.length; ci++) {
if (sheet.rows[ci].cells[0].value) {
sheet.rows[ci].cells.unshift({});
}
}
// insert the detail sheet rows after the master row
[].splice.apply(workbook.sheets[0].rows, [masterRowIndex + 1, 0].concat(sheet.rows));
}
// save the workbook
kendo.saveAs({
dataURI: new kendo.ooxml.Workbook(workbook).toDataURL(),
fileName: "Importaciones.xlsx"
});
});
}
function exportChildData(NumeroPedimento, rowIndex) {
var deferred = $.Deferred();
detailExportPromises.push(deferred);
var rows = [{
cells: [
{ value: "DescripcionFactura" },
{ value: "DescripcionPedimento" },
{ value: "Arancel" }
]
}];
dataSource.filter({ field: "NumeroPedimento", operator: "eq", value: NumeroPedimento });
var exporter = new kendo.ExcelExporter({
columns: [
{ field: "DescripcionFactura" },
{ field: "DescripcionPedimento" },
{ field: "Arancel" }
],
dataSource: dataSource
});
exporter.workbook().then(function (book, data) {
deferred.resolve({
masterRowIndex: rowIndex,
sheet: book.sheets[0]
});
});
}
</script>