How to export image or hyperlink column to Excel and PDF

Hi,


I need to export image or hyperlink column to excel or pdf.

I can't find the sample code for blazor grid.


Regards,
Krailit

2 Replies 1 reply marked as answer

RS Renjith Singh Rajendran Syncfusion Team February 22, 2022 03:51 PM UTC

Hi Krailit, 
 
Greetings from Syncfusion support. 
 
We suggest you to enable the IncludeTemplateColumn property of PdfExportProperties and ExcelExportProperties to export Template columns in Grid. And also we suggest you to ensure to set values for args.Cell.Value inside the corresponding event handlers(PdfQueryCellInfoEvent, ExcelQueryCellInfoEvent) to export the contents of template column in Grid. 
References :  
 
Please refer the codes below, 
 
 
<GridEvents OnToolbarClick="ToolbarClickHandler" PdfQueryCellInfoEvent="PdfQueryCellInfoEvent" ExcelQueryCellInfoEvent="ExcelQueryCellInfoEvent" TValue="Order"></GridEvents> 
 
    public async Task ToolbarClickHandler(Syncfusion.Blazor.Navigations.ClickEventArgs args) 
    { 
        if (args.Item.Id == "Grid_pdfexport"//Id is combination of Grid's ID and itemname 
        { 
            PdfExportProperties pdfExportProperties = new PdfExportProperties(); 
            pdfExportProperties.IncludeTemplateColumn = true; 
            await this.DefaultGrid.PdfExport(pdfExportProperties); 
        } 
       if (args.Item.Id == "Grid_excelexport"//Id is combination of Grid's ID and itemname 
        { 
            ExcelExportProperties excelExportProperties = new ExcelExportProperties(); 
            excelExportProperties.IncludeTemplateColumn = true; 
            await this.DefaultGrid.ExcelExport(excelExportProperties); 
        } 
    } 
 
 
Query 1 : export image or hyperlink column to excel. 
We suggest you to customize the args.Cell.Value inside ExcelQueryCellInfoEvent handler to achieve this requirement. You can use the below code to export hyperlink in Grid Template column to excel file. Please refer and use as like the code below, 
 
 
    public void ExcelQueryCellInfoEvent(ExcelQueryCellInfoEventArgs<Order> args) 
    { 
        ... 
       if (args.Column.HeaderText == "Customer Name") 
        { 
            args.Cell.Value = "<a rel='nofollow' href=\'https:\\www.google.com'>" + @args.Data.CustomerID + "</a>"; 
        } 
    } 
 
 
And we would like to inform you that, Excel export don’t have support for exporting images in corresponding excel cells. 
 
Query 2 : export image or hyperlink column to pdf. 
We suggest you to customize the codes inside PdfQueryCellInfoEvent as like the below code to export images in template column to pdf file. Please refer and use as like the code below, 
 
 
    public void PdfQueryCellInfoEvent(PdfQueryCellInfoEventArgs<Order> args) 
    { 
        if (args.Column.HeaderText == "Order ID") 
        { 
            Image img = Image.FromFile(@"wwwroot/Images/Uploads/" + args.Data.OrderID.ToString() + ".png"); 
            byte[] bytes = (byte[])(new ImageConverter()).ConvertTo(img, typeof(byte[])); 
 
            //use the byte to generate a base64String and assign to image to get displayed in Grid 
            string base64String = Convert.ToBase64String(bytes, 0, bytes.Length); 
 
            byte[] dataString = Convert.FromBase64String(base64String);  
            System.IO.MemoryStream imageStream = new System.IO.MemoryStream(dataString);  
            args.Cell.Style.BackgroundImage = Syncfusion.PdfExport.PdfImage.FromStream(imageStream);  
            args.Cell.ImagePosition = Syncfusion.PdfExport.PdfGridImagePosition.Center;  
        } 
        ... 
   } 
 
 
We are currently checking the possibility in exporting hyperlink to pdf from our side. We will update you further details within two business days. Until then we appreciate your patience. 
 
We are also attaching the sample based on this requirement for your convenience, please download and refer the sample from the link below, 
 
Please get back to us if you need further assistance. 
 
Regards, 
Renjith R 


Marked as answer

RS Renjith Singh Rajendran Syncfusion Team February 24, 2022 11:33 AM UTC

Hi Krailit, 
 
Query : exporting hyperlink to pdf 
Currently we don’t have support for this requirement. But, we have logged a feature improvement task for this requirement. At the planning stage for every release cycle, we review all open features and identify features for implementation based on specific parameters including product vision, technological feasibility, and customer vote count. This will be implemented in any of our upcoming releases.   
 
You can now track the current status of this feature request from the below feedback page.   
 
Regards, 
Renjith R 


Loader.
Up arrow icon