我将C#与.NET 3.5一起使用angular 7来创建xlsx
文件,而我正在使用openXML SDK。 由于企业规则,我无法粘贴所有代码,但是当我将文件保存在服务器上时我知道文件创建正确,但是我没有损坏
后端,当我将文件保存在服务器上时,我会创建运行良好的文件
MemoryStream ms = new MemoryStream();
using (SpreadsheetDocument document = SpreadsheetDocument.Create(ms, SpreadsheetDocumentType.Workbook))
byte[] xlsxInBytes;
string xslxBase64;
我的代码来填充文件
保存并将其放在base 64上的代码
workbookPart.Workbook.Save();
xlsxInBytes = ms.ToArray();
xslxBase64 = Convert.ToBase64String(xlsxInBytes);
return Ok(xslxBase64);
前端
downloadFile(data: string, contentType: string) {
// const contentType = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet';
const blob = new Blob([data], { type: contentType });
// const url = window.URL.createObjectURL(blob);
// const test = atob(data);
console.log(blob);
const downloadLink = document.createElement('a');
document.body.appendChild(downloadLink);
downloadLink.href = 'data:application/' + contentType + ';base64, ' + encodeURI(blob.);
downloadLink.download = 'title.xlsx';
downloadLink.click();
document.body.removeChild(downloadLink);
// window.open(url);
}
当我打开文件时说它已损坏