Js前端导出csv

var myMemory = myObjectStore.objectStore;
var myDataArray = myMemory.data;

var myCsvString = "\ufeff"
var myPropertyNameArray = [];
var myDataGridLayout = myThis._DataGrid.structure;
var myPropertyCount = myDataGridLayout[0].cells.length;
for (var i = 0; i < myPropertyCount; i++) {
    myCsvString += myDataGridLayout[0].cells[i].name + ",";
    myPropertyNameArray.push(myDataGridLayout[0].cells[i].field);
}
myCsvString += '\r\n';
for (var i = 0; i < myDataArray.length; i++) {
    for (var j = 0; j < myPropertyNameArray.length; j++) {
        myCsvString += myDataArray[i][myPropertyNameArray[j]] + ",";
    }
    myCsvString += '\r\n';
}
var myCsvData = new Blob([myCsvString], { type: "text/csv,charset=UTF-8" });
var myCsvUrl = URL.createObjectURL(myCsvData);
var myUIA = document.createElement("a");
myUIA.setAttribute("href", myCsvUrl);
myUIA.setAttribute("download", "data.csv");
myUIA.click();

 

posted @ 2020-12-24 16:51  mytudousi  阅读(178)  评论(0编辑  收藏  举报