ZengTao
2025-05-13 3c32000216972a73cef885933ddb3e5ccc888749
UI-Project/src/views/largescreendisplay/statistics.vue
@@ -7,6 +7,7 @@
      </el-date-picker>
      <el-button type="primary" style="margin-left: 10px;margin-bottom: 10px;" @click="sethistorical()">{{
        $t('reportmanage.inquire') }}</el-button>
        <el-button type="primary" @click="exportToExcel">{{$t('large.ExporttoExcel')}}</el-button>
    </div>
    <el-table ref="table" style="margin-top: 20px;height: 580px;width: 1770px;" :data="tableDatax"
      :header-cell-style="{ background: '#F2F3F5 ', color: '#1D2129' }">
@@ -223,5 +224,50 @@
  parseAndSetTime();
  historical();
});
import * as XLSX from 'xlsx';
import { saveAs } from 'file-saver';
const exportToExcel = () => {
  // 表格数据(深拷贝防止污染)
  const data = JSON.parse(JSON.stringify(tableDatax.value));
  // 表头转换为中文或国际化文本
  const headerMap = {
    date: t('large.date'),
    countOutOne: t('large.countOutOne'),
    totalAreaOutOne: t('large.totalAreaOutOne'),
    countOutTwo: t('large.countOutTwo'),
    totalAreaOutTwo: t('large.totalAreaOutTwo'),
    countIn: t('large.countIn'),
    totalAreaIn: t('large.totalAreaIn'),
    countOut: t('large.countOut'),
    totalAreaOut: t('large.totalAreaOut'),
    hollowCountOutOne: t('large.hollowCountOutOne'),
    hollowTotalAreaOutOne: t('large.hollowTotalAreaOutOne'),
    hollowCountOutTwo: t('large.hollowCountOutTwo'),
    hollowTotalAreaOutTwo: t('large.hollowTotalAreaOutTwo')
  };
  // 将数据中的 key 替换为中文表头
  const exportData = data.map(row => {
    const newRow = {};
    for (const key in headerMap) {
      newRow[headerMap[key]] = row[key];
    }
    return newRow;
  });
  // 转换为工作表
  const worksheet = XLSX.utils.json_to_sheet(exportData);
  const workbook = XLSX.utils.book_new();
  XLSX.utils.book_append_sheet(workbook, worksheet, 'Sheet1');
  // 导出为文件
  const excelBuffer = XLSX.write(workbook, { bookType: 'xlsx', type: 'array' });
  const blob = new Blob([excelBuffer], { type: 'application/octet-stream' });
  saveAs(blob, '生产情况导出.xlsx');
};
</script>
<style scoped></style>