Posted 26 May 2021, 2:03 am EST
When we try to use the getClipString it seems to truncates the data. The underlying data in the grid goes to 8 decimal places but when pasting into Excel using getClipString we only get 2 (and I checked - the data is not there if I expand precision in Excel).
Before we manually collected the data and exported, and had hoped to move to getClipString to reduce complexity.
Here is the old code (which we need to enhance as it does not capture multi-row headers):
const { gridData, columnDefinitions } = this.props;
var headerRow = '';
var columns = [];
for (var columnIndex = 0; columnIndex < grid.columns.length; columnIndex++){
var column = grid.columns[columnIndex];
var actionColumns = columnDefinitions.filter(columnDef => columnDef.action).map(columnDef => columnDef.binding);
if (!actionColumns || !actionColumns.includes(column.binding)) {
columns.push(column);
//Replace all new lines in the header with white space
headerRow += grid.columns[columnIndex].header.replace(/\n/g, ' ');
if (columnIndex !== grid.columns.length - 1) {
headerRow += '\t';
}
}
}
//Handling for case where last column in grid is an action column
if (headerRow.endsWith('\t')) {
headerRow = headerRow.slice(0, -1);
}
var rows = [headerRow];
if (gridData) {
for (var rowIndex = 0; rowIndex < gridData.length; rowIndex++) {
var rowData = '';
var row = gridData[rowIndex];
for (var colIndex = 0; colIndex < columns.length; colIndex++) {
var value = row[columns[colIndex].binding];
if (value !== undefined && value !== null) {
rowData += value;
}
if (colIndex !== columns.length - 1){
rowData += '\t';
}
}
rows.push(rowData);
}
}
Clipboard.copy(rows.join('\n'));
This is the new implementation
// Create a range including everything in the grid
let rng = new wjcGrid.CellRange(0, 0, grid.rows.length - 1, grid.columns.length - 1);
// See https://www.grapecity.com/wijmo/api/classes/wijmo_grid.flexgrid.html#getclipstring
// for parameters the range is passed, then false as we do not want CSV, then true as we
// do want headers
// Get the clipboard string (tab delimited)
let copyText = grid.getClipString(rng, false, true);
Clipboard.copy(copyText);
Is this expected behavior?