[]
        
(Showing Draft Content)

FlexGrid를 CSV로 내보내기

FlexGrid를 CSV로 내보내려면 FlexGrid.getClipString 메서드를 호출하여 전체 그리드 또는 지정된 범위를 나타내는 문자열을 가져온 다음 문자열을 파일로 가져옵니다.

다음과 같이 전체 그리드를 CSV로 내보낼 수 있습니다:

import * as wjGrid from '@grapecity/wijmo.grid';

//function for converting CSV string into a downloadable file
function exportFile(csv, fileName) {
    var fileType = 'txt/csv;charset=utf-8';
    if (navigator.msSaveBlob) { // IE 
        navigator.msSaveBlob(new Blob([csv], {
        type: fileType
        }), fileName);
    } 
    else {
        var e = document.createElement('a');
        e.setAttribute('href', 'data:' + fileType + ',' + encodeURIComponent(csv));
        e.setAttribute('download', fileName);
        e.style.display = 'none';
        document.body.appendChild(e);
        e.click();
        document.body.removeChild(e);
    }
}

//export grid to CSV
var rng = new wjGrid.CellRange(0, 0, theGrid.rows.length - 1, theGrid.columns.length - 1),
    csv = theGrid.getClipString(rng, true, true);
exportFile(csv, 'FlexGrid.csv');

또는 선택된 셀을 내보낼 범위로 사용하는 것처럼 그리드의 일부를 내보낼 수 있습니다:

//export selected cell range to CSV
var rng = theGrid.selection,
    csv = theGrid.getClipString(rng, true, true);
exportFile(csv, 'Selection.csv');