[英]Why ExcelJs plugin is not working in IE11?
我正在使用 Angular 9 和 excelJs 4.1.1,這在 chrome 中工作正常,但僅在 IE11 中出現錯誤:polyfills-es5.js 中字符集的范圍無效
當我從 package.json 中刪除此依賴項時,一切正常。
我已經添加了https://www.npmjs.com/package/exceljs 中建議的所有 polyfill
Polyfills.ts
import 'core-js/modules/es.promise';
import 'core-js/modules/es.string.includes';
import 'core-js/modules/es.object.assign';
import 'core-js/modules/es.object.keys';
import 'core-js/modules/es.symbol';
import 'core-js/modules/es.symbol.async-iterator';
import 'regenerator-runtime/runtime';
import './unicode-regex-polyfill';
import 'zone.js/dist/zone';
unicode-regex-polyfill.ts
import rewritePattern from 'regexpu-core';
import { generateRegexpuOptions } from '@babel/helper-create-regexp-features-plugin/lib/util';
const { RegExp } = global;
try {
new RegExp('a', 'u');
} catch (err) {
// @ts-ignore
global.RegExp = function(pattern, flags) {
if (flags && flags.includes('u')) {
return new RegExp(
rewritePattern(
pattern,
flags,
generateRegexpuOptions({ flags, pattern })
)
);
}
return new RegExp(pattern, flags);
};
// @ts-ignore
global.RegExp.prototype = RegExp;
}
配置文件
{
"compileOnSave": false,
"compilerOptions": {
"baseUrl": "./",
"outDir": "./dist/out-tsc",
"sourceMap": true,
"declaration": false,
"downlevelIteration": true,
"experimentalDecorators": true,
"module": "esnext",
"moduleResolution": "node",
"importHelpers": true,
"target": "es5",
"typeRoots": ["node_modules/@types"],
"lib": ["es2017", "dom"],
"paths": {
"@app/*": ["src/app/*"],
"@environments/*": ["src/environments/*"],
"exceljs": [
"node_modules/exceljs/dist/exceljs.min"
],
// "@assets/images/*": ["src/assets/images*"]
}
},
"angularCompilerOptions": {
"fullTemplateTypeCheck": true,
"strictInjectionParameters": true
}
}
包.json
"dependencies": {
"@angular-redux/store": "^10.0.0",
"@angular/animations": "~9.0.3",
"@angular/cdk": "^9.2.4",
"@angular/common": "~9.0.3",
"@angular/compiler": "~9.0.3",
"@angular/core": "~9.0.3",
"@angular/forms": "~9.0.3",
"@angular/material": "^9.2.4",
"@angular/platform-browser": "~9.0.3",
"@angular/platform-browser-dynamic": "~9.0.3",
"@angular/router": "~9.0.3",
"install": "^0.13.0",
"jspdf": "1.4.1",
"jspdf-autotable": "^3.5.6",
"ngx-mat-select-search": "^3.0.0",
"npm": "^6.14.7",
"redux": "^4.0.1",
"redux-devtools": "^3.5.0",
"redux-devtools-extension": "^2.13.8",
"rxjs": "~6.5.4",
"tslib": "^1.10.0",
"zone.js": "~0.10.2"
"exceljs": "^4.1.1",
},
請幫我解決這個問題
一切正常,如果我從 package.json 中刪除 exceljs 依賴項
我終於讓它在 IE11 中通過在 stpes 下工作
從 package.json 中刪除 excelJS 和文件保護程序
將 CDN 路徑添加到 index.html 中的腳本標記
在 ts 文件中聲明以下變量
declare var ExcelJS: any ; declare var saveAs: any;
下面的代碼在相同的 ts
var workbook = new ExcelJS.Workbook(); var worksheet = workbook.addWorksheet('SheetName'); workbook.xlsx.writeBuffer().then(function(buffer) { saveAs(new Blob([buffer], { type: 'application/octet-stream' }), 'FileName.xlsx'); });
參考: https : //supportcenter.devexpress.com/ticket/details/t900163/datagrid-the-latest-version-of-exceljs-doesn-t-work-in-ie11
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.