I tried to export PDF/Excel using demo link mentioned below here.
Blazor DataGrid Advanced Exporting Example - Syncfusion Demos
Code as per attached link works successfully for windows application and web browser but it does not work for mobile application for android and iOS.
Please do the needful.
Thank you.
Hi Amish
Based on the reported issue, we recommend using the Excel and PDF export solutions below to solve this problem. Please see the code snippet and example code below for reference.
|
public async Task ToolbarClickHandler(Syncfusion.Blazor.Navigations.ClickEventArgs args) { if (args.Item.Id == "Grid_excelexport") //Id is combination of Grid's ID and itemname { using (ExcelEngine excelEngine = new ExcelEngine()) { IApplication application = excelEngine.Excel; application.DefaultVersion = ExcelVersion.Excel2013; IWorkbook workbook = application.Workbooks.Create(1); IWorksheet worksheet = workbook.Worksheets[0]; IList<Order> reports = Orders; // pass the datasoruce worksheet.ImportData(reports, 1, 1, true); MemoryStream stream = new MemoryStream(); workbook.SaveAs(stream);
await Runtime.InvokeVoidAsync("saveAsFile", new object[] { "export.xlsx", Convert.ToBase64String(stream.ToArray()) });
} } if (args.Item.Id == "Grid_pdfexport") { PdfDocument pdfDocument = new PdfDocument(); PdfPage pdfPage = pdfDocument.Pages.Add(); //Create a new PdfGrid. PdfGrid pdfGrid = new PdfGrid(); pdfGrid.Columns.Add(DefaultGrid.Columns.Count);
PdfGridRow[] headerRow = pdfGrid.Headers.Add(1); var GridColHeader = DefaultGrid.Columns.Select(x => x.HeaderText).ToList(); for (var i = 0; i < DefaultGrid.Columns.Count; i++) { headerRow[0].Cells[i].Value = GridColHeader[i]; } // Add Rows to the grid based/using on Grid's DataSource for (int i = 0; i < Orders.Count; i++) { PdfGridRow row = pdfGrid.Rows.Add(); //assign cells based on grid's columns row.Cells[0].Value = Orders[i].OrderID.ToString(); row.Cells[1].Value = Orders[i].CustomerID; row.Cells[2].Value = Orders[i].OrderDate.ToString(); row.Cells[3].Value = Orders[i].Freight.ToString(); } //enable repeating grid column header in each page pdfGrid.RepeatHeader = true; //Draw the PdfGrid. pdfGrid.Draw(pdfPage, new PointF(0, 0)); MemoryStream stream = new MemoryStream(); pdfDocument.Save(stream); //Close the document pdfDocument.Close(true);
await Runtime.InvokeVoidAsync("saveAsFile", new object[] { "output.pdf", Convert.ToBase64String(stream.ToArray()) });
} }
if (navigator.msSaveBlob) {
//Download document in Edge browser
var data = window.atob(bytesBase64);
var bytes = new Uint8Array(data.length);
for (var i = 0; i < data.length; i++) {
bytes[i] = data.charCodeAt(i);
}
var blob = null;
if (filename.endsWith(".pdf"))
blob = new Blob([bytes.buffer], { type: "application/pdf" });
else if (filename.endsWith(".xlsx"))
blob = new Blob([bytes.buffer], { type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" });
navigator.msSaveBlob(blob, filename);
}
else {
var link = document.createElement('a');
link.download = filename;
if (filename.endsWith(".pdf"))
link.rel='nofollow' href = "data:application/pdf;base64," + bytesBase64;
else if (filename.endsWith(".xlsx"))
link.rel='nofollow' href = "data:application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;base64," + bytesBase64;
document.body.appendChild(link); // Needed for Firefox
link.click();
document.body.removeChild(link);
}
}
|
Regards,
Prathap S
Hi team,
Facing same issue in EJ2 angular too.
any possible solution, we are using latest angular package.
Thanks.
Hi Kumaresan Subramani,
Greetings from Syncfusion support.
Before we proceed with providing a solution, we need some information to better understand the issue you are facing. Please provide us with the following details:
https://stackblitz.com/edit/angular-a23rpz?file=src%2Fapp.component.ts,src%2Fapp.component.html
We appreciate your cooperation in providing us with the requested information, as it will help us provide a more effective solution to your query.
Regards,
Hemanth Kumar S