angular - 在 Angular 中使用“kendo-grid-excel”时如何设置原始文件内容类型?
问题描述
kendo-grid-excel
在 Angular 中使用时如何设置原始文件内容类型?
这是我生成excel的模板:
<kendo-grid-excel fileName="file.xlsx">
<kendo-excelexport-column
*ngFor="let i of header.properties"
[field]="i.name"
[title]="i.name">
</kendo-excelexport-column>
</kendo-grid-excel>
我导出excel,修改它。然后我将它上传到我用 C# 编写并使用NPOI的 BE 。在 BE 上,我在尝试读取 excel 时遇到错误:
NPOI.OpenXml4Net.Exceptions.InvalidFormatException: 'Package should contain a content type part [M1.13]'
.
我在这里发现解决我的问题的方法是使用
.application/application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
而不是application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
.
以下是我将文件上传回 BE 的方式:
<kendo-upload
[saveUrl]="saveUrl"
(upload)="uploadHandler($event)"
[accept]="'.xlsx'">
import
</kendo-upload>
和处理程序:
uploadHandler(e: UploadEvent) {
e.files[0].rawFile.type = "application/application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
e.data = {
file: e.files[0],
fileScructure: this.header.properties.map(x => x.name)
};
}
但我收到一个错误:Cannot assign to 'type' because it is a read-only property.
所以,我的问题是如何更改类型?
更新
看来我必须在 excel 导出上正确设置类型。所以,我需要以kendo-grid-excel
某种方式提供类型。到目前为止,我无法找到如何做到这一点。
更新 2
这看起来像是NPOI方面的一个问题。因为根据docsapplication/vnd.openxmlformats-officedocument.spreadsheetml.sheet
是正确的.xlsx类型。于是,我尝试将NPOI更新到最新的1.2.3版本,但并没有解决问题。我仍然收到错误:。NPOI.OpenXml4Net.Exceptions.InvalidFormatException: 'Package should contain a content type part [M1.13]'
更新 3
为了更好地诊断问题,我使用NPOI生成了一个.xlsx文件,并检查了我是否可以读取它。我可以用NPOI阅读它。因此,我继续尝试找出两个.xlsx文件之间的任何差异。我发现的唯一区别如下。
当我右键单击该文件时,转到属性-安全-高级我可以看到资源属性下拉列表,IMAGELOAD: 1
当单击kendo-generated.xlsx
. 而对于npoi-generated.xlsx
我看到的Integrity level: High Mandatory Level
. 也许这就是阻止NPOI能够读取的原因kendo-generated.xlsx
?
解决方案
推荐阅读
- ionic-framework - Ionic App - 构建失败,“支持的最低 Gradle 版本为 4.4”
- python-3.x - PySpark:如何从 spark 数据框创建嵌套的 JSON?
- spring-boot - 带有可选参数的 dynamodb 查询过滤器
- c# - windows 8.1 app后台任务重启后无法工作
- sql - 在 postgres 中将 jsonb 转换为常规数组
- xml - 如何在 Odoo 10 的 Qweb 标头中获取 report_name?
- powershell - 通过 PowerShell 更改文本内容时,不可见、不存在的字符阻止运行 cmd 文件
- embedded - 字节和pc单位之间的长度差异
- ios - 共享扩展“等待附加”
- java - Apache Ignite 2.7 发布日期