This is a migrated thread and some comments may be shown as answers.
Export RadGridview to Excel with variable image sizes (adjusting cell sizes)
3 Answers 45 Views
This is a migrated thread and some comments may be shown as answers.
Pin
Top achievements
Rank 1
Pin asked on 10 Sep 2020, 06:21 PM

Hi

I have a RadGridview that contains some data columns and some image columns and images are in different sizes (refer to attached image). I want to export it to excel. what is the best way to adjust row height and column width (based on image sizes)?

Note1: I think that i should put some conditions on "ExcelexportRenderer_WorkbookCreated" event but can't find the way.

Note2: My images are in binary format ("System.Byte[]").

3 Answers, 1 is accepted

Sort by
0
Pin
Top achievements
Rank 1
answered on 11 Sep 2020, 09:08 AM

UPDATE:  It seems that using "ExportVisualSettings = true" is a good solution in ordinary tables (without image column) but unfortunately NOT works correctly on tables with grouped data (and image columns). The location of images (relative to their cells) are not calculated correctly in excel when there is some grouping...

What should i do?

 

Thanks

0
Todor Vyagov
Telerik team
answered on 15 Sep 2020, 12:48 PM

Hello Pin,

As you noticed the ExportVisualSettings property of GridViewSpreadExport controls whether the visual settings and sizes are exported to the excel workbook.

Thanks for the detailed description, which helped me reproduce the problem you are facing. When the image column is exported in a non-grouped grid - the alignment of images in excel cells is correct, but when the grid is grouped the image positioning is not correct. I have logged the issue on our feedback portal, here: RadGridView: Export to excel does not position images correctly when grid is grouped. I have also updated your Telerik points for the report.

As a workaround, if you need to handle the event, you can subscribe to the WorkbookCreated event of SpreadExportRenderer and adjust the position of the image, which is illustrated in the code below:

private void Renderer_WorkbookCreated(object sender, WorkbookCreatedEventArgs e)
{
    if (this.gridView.GroupDescriptors.Count == 0)
    {
        return;
    }

    foreach (var imageShape in e.Workbook.ActiveWorksheet.Shapes)
    {
        double cellWidth = e.Workbook.ActiveWorksheet.Columns[imageShape.CellIndex.ColumnIndex].GetWidth().Value.Value;
        double imageWidth = imageShape.Width;
        
        imageShape.OffsetX = (cellWidth - imageWidth) / 2;
    }
}

Here is the result on my end after the applied workaround:


I hope this helps. Let me know if you need further assistance.

Regards,
Todor Vyagov
Progress Telerik

Five days of Blazor, Angular, React, and Xamarin experts live-coding on twitch.tv/CodeItLive , special prizes and more, for FREE?! Register now for DevReach 2.0(20).

0
Pin
Top achievements
Rank 1
answered on 18 Sep 2020, 05:13 PM
Thanks so much
Asked by
Pin
Top achievements
Rank 1
Answers by
Pin
Top achievements
Rank 1
Todor Vyagov
Telerik team
Share this question
or