
import FileSaver from "file-saver";
import XLSX from "xlsx";


/**
 * 字符权限校验
 * @param {Array} value 校验值
 * @returns {Boolean}
 * id:表ID
 * name:导出表名字
 *xlsxParam：true/false:如果表格里有数字、日期这些、需要加上raw: true 
 */
export function handleExport(id,name,xlsxParam) {      
  var wb = XLSX.utils.table_to_book(
    document.querySelector('#'+id),
   {raw: xlsxParam}
  );

  var wbout = XLSX.write(wb, {
    bookType: "xlsx",
    bookSST: true,
    type: "array",
  });
  try {
    FileSaver.saveAs(
      new Blob([wbout], { type: "application/octet-stream" }),
      name+".xlsx"
    );
  } catch (e) {
    if (typeof console !== "undefined") {
      console.log(e, wbout);
    }
  }
  return wbout;
}