d-band / better-xlsx

A better xlsx library.
https://d-band.github.io/better-xlsx/
420 stars 36 forks source link

使用 webpack minimize 后,导出的 excel 损坏 #78

Closed shiny closed 5 years ago

shiny commented 5 years ago

关掉 minimize 功能后正常,开启 minimize 后 excel 就提示损坏了,但代码能正常运行。 下面是两个 excel 的对比 报表2018年11月28日(3).xlsx 报表2018年11月28日(4).xlsx

helloyou2012 commented 5 years ago

谢谢,Bug 已修复,请更新至版本 0.7.2

shiny commented 5 years ago

升级到了 0.7.3,还是存在问题,附上升级后的文件对比 Webpack压缩前.xlsx Webpack压缩后.xlsx

helloyou2012 commented 5 years ago

你好,麻烦你提供下 webpack 版本、babel 版本吧。最好给个简单的 Demo 和 webpack 配置文件。比如:

index.js

import xlsx from 'better-xlsx';
import saveFile from 'jszip/vendor/FileSaver';

document.getElementById('download').onclick = function download() {
  const xlsx = require('better-xlsx');
  const file = new xlsx.File();
  const sheet = file.addSheet('Sheet1');
  const row = sheet.addRow();

  const cell = row.addCell();
  cell.value = 'I am a cell!';
  cell.hMerge = 2;
  cell.vMerge = 1;

  const style = new xlsx.Style();
  style.fill.patternType = 'solid';
  style.fill.fgColor = '00FF0000';
  style.fill.bgColor = 'FF000000';
  style.align.h = 'center';
  style.align.v = 'center';

  cell.style = style;

  file
    .saveAs('blob')
    .then(function(content) {
      saveFile(content, "example.xlsx");
    });
}

index.html

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Simple download</title>
</head>
<body>
  <button id="download">Download</button>
  <script type="text/javascript" src="./dist/index.js"></script>
</body>
</html>