This is a migrated thread and some comments may be shown as answers.

ui grid export to excel with format

7 Answers 1826 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Bertha
Top achievements
Rank 1
Bertha asked on 15 Dec 2014, 10:27 PM
I have use the latest version to export the kendo grid to excel.  Superb functionality.

(1) I used dataBound event to change some color of the cell in the grid.  How can I put that color to the excel as well? 
(2) I have changed the title name of a column with "<br />" to show 2 lines and it is successful in grid.  But in excel, it just show "<br />".  How can I do the same during export to excel?

Thanks.

$("#gdCombinedReport").kendoGrid({
dataSource: reportDataSource,
sortable: false,
pageable: false,
scrobllable: true,
toolbar: ["excel"],
dataBound: onDataBound3,
excel: {
fileName: "Report.xlsx",
allPages: true
},
columns: [
{ field: "itemName", title: "Item Name", locked: true, attributes: { style: "text-align:left" }, width: "200px" },
{ field: "forecast[0]", title: $scope.titleName[0] + "<br /> January", attributes: { style: "text-align:right" }, width: "90px", format: "{0:c0}" },

7 Answers, 1 is accepted

Sort by
0
Dimiter Madjarov
Telerik team
answered on 16 Dec 2014, 11:50 AM
Hello,


I will go straight to the questions:

1. You could use an approach similar to the following one in the excelExport event in order to set custom background color to the Grid cells.

2. The reason for this behavior is that Excel does not support HTML, so <br/> cannot be translated to new row. Nevertheless allowing this in the upcoming versions is in our development plans.

I wish you a great day!

Regards,

Dimiter Madjarov
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Bertha
Top achievements
Rank 1
answered on 16 Dec 2014, 05:12 PM
Great product!

(1) Besides changing background color, I want to bold some cells and do number format as $1,000 as well.  I tried but failed.  How can I do that?

(2) Also, I tried to export to pdf but my kendo grid has horizontal scrollbar. Is it possible to have pdf for the whole grid.   Thanks.

row.cells[cellIndex].Font.Bold = true;
row.cells[cellIndex].format(c0);
row.cells[cellIndex].NumberFormat = "#,##0";
row.cells[cellIndex].value = (row.cells[cellIndex].value).replace(/\d(?=(\d{3})+\.)/g, '$&,');
0
Dimiter Madjarov
Telerik team
answered on 17 Dec 2014, 12:33 PM
Hello Bertha,


You could find all the possible configuration options for the Workbook at the following documentation page. For example:

sheets.rows.cells.boldsheets.rows.cells.format

Regarding the second question, indeed at the moment only the visible rows are exported to PDF. As a workaround, you could use the following approach. In the example I am temporary increasing the height of the Grid, so that all of the rows are exported and then returning the old one. Currently we are in the process of developing a more convenient way to achieve this.

I wish you a great day!

Regards,
Dimiter Madjarov
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Bertha
Top achievements
Rank 1
answered on 17 Dec 2014, 04:01 PM
Superb workaround.  Thanks.
0
Bertha
Top achievements
Rank 1
answered on 06 Jan 2015, 03:45 PM
I used the pdf example you gave me and it worked perfectly.  But now one of my kendo grid has both horizontal and vertical scrollbar and it extended to next pdf page. Also, the first column is frozen. 
1) With existing code, content did not show after horizontal scroll bar. 
2) first frozen column only show rows on the screen, missing rows underneath
3) vertical rows only show for the first pdf page, it did not go to next page. 

I tried the following but it didn't work.  Is there any workaround?  Thanks.

var wrapperWidth = grid.wrapper.css("width");
var contentWidth = $(".k-grid-content", grid.wrapper).css("width");

...

grid.wrapper.css("width", wrapperWidth);
$(".k-grid-content", grid.wrapper).css("width", contentWidth);
0
Dimiter Madjarov
Telerik team
answered on 07 Jan 2015, 12:07 PM

Hello Bertha,

The reason that the rows from the frozen columns are not shown with the current custom implementation is that they are part of a different table element and we are not modifying it's height before exporting, The example could be modified like this, in order to update the locked content height accordingly too.

Nevertheless at the moment I cannot provide a suitable workaround for the other issues. It is in our development plans to provide better PDF export options in complex scenarios like the current one.

I wish you a great day!

Regards,
Dimiter Madjarov
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Bertha
Top achievements
Rank 1
answered on 07 Jan 2015, 02:50 PM
Thanks for the example of locked column and looking forward to the new updates.
Tags
Grid
Asked by
Bertha
Top achievements
Rank 1
Answers by
Dimiter Madjarov
Telerik team
Bertha
Top achievements
Rank 1
Share this question
or