알쓸전컴(알아두면 쓸모있는 전자 컴퓨터)

handsontable copy 시 Column 까지 copy 본문

Web /Vue js tip

handsontable copy 시 Column 까지 copy

백곳 2018. 12. 19. 10:33

handsontable copy 시 Column 까지 copy 



기본 handsontable 은 Copy 시에 Column에 복사 되지 않아서 엑셀에 붙혀 넣을때 많이 불편합니다. 


그리고 구글링한 코드를 적습니다. 


기본은 node_modules\handstontable\dist 에 있는 코드를 변경 하는것입니다. 

pro 일때는 node_modules\handstontable-pro\dist 에 있는 코드를 변경 합니다. 




function getRangedData(ranges) 을 아래와 같이 변경해 줍니다.


key: 'getRangedData',
value: function getRangedData(ranges) {
var _this4 = this;
var dataSet = [];
var copyableRows = [];
var copyableColumns = [];
// Count all copyable rows and columns
(0, _array.arrayEach)(ranges, function (range) {
// XMAIS - add col headers
var colHeaders = _this4.hot.getColHeader();
colHeaders = colHeaders.slice(range.startCol, range.endCol+1);
colHeaders.unshift('');
dataSet.push(colHeaders);
// END
(0, _number.rangeEach)(range.startRow, range.endRow, function (row) {
if (copyableRows.indexOf(row) === -1) {
copyableRows.push(row);
}
});
(0, _number.rangeEach)(range.startCol, range.endCol, function (column) {
if (copyableColumns.indexOf(column) === -1) {
copyableColumns.push(column);
}
});
});
// Concat all rows and columns data defined in ranges into one copyable string
var rowHeaders = _this4.hot.getRowHeader();
(0, _array.arrayEach)(copyableRows, function (row) {
var rowSet = [];
// XMAIS - add row headers
var rowHeader = rowHeaders.slice(row,row+1);
rowSet.push(rowHeader);
// END
(0, _array.arrayEach)(copyableColumns, function (column) {
rowSet.push(_this4.hot.getCopyableData(row, column));
});
dataSet.push(rowSet);
});
return dataSet;
}


그리고 나면 colhaeder 의 배열을 복사해서 붙여 넣습니다. 

Comments