PDA

View Full Version : generate report from grid to excel



Dagev
24 Nov 2009, 2:02 PM
how can I generate a report to excel from my grid, I mean can export the rows of my grid to excel, some suggestion??

dlbjr
24 Nov 2009, 7:34 PM
This code takes a grid's store and preps it for Excel and places it in the clipboard.
You should be able to throw it into a new window and set it to an Excel file





function copyGridDataToClipboard(grid) {
var s = new StringBuilderEx();
var col;
var visibleCols = grid.getColumnModel().getColumnsBy(
function(columnConfig, index) {
if (columnConfig.hidden) {
return false
}
else {
return true;
}
}
);
var rec = 0;
grid.getSelectionModel().selectAll();
var selRecords = grid.getSelectionModel().getSelections();
for (rec = 0; rec < selRecords.length; rec++) {
for (col = 0; col < visibleCols.length; col++) {
var colIdxName = "";
colIdxName += visibleCols[col].dataIndex;
/* Excel needs a tab in between columns */
s.append(selRecords[rec].get(visibleCols[col].dataIndex) + '\t');
}
s.append('\n');
}
grid.getSelectionModel().clearSelections();
window.clipboardData.setData('text', s.toString());
}