我能';不要用Angular2阅读Excel
我想将带有Angular的Excel发送到我的服务器(SpringBoot)。我不能这样做 所以,我想我的问题可能是“Angular不读Excel”。我试图用Angular阅读Excel,但我得到了错误-> 我的意图是“如果Angular可以阅读Excel,那么我将尝试发送Excel。” 因为我正在尝试发送Excel,但无法发送 然后: 在此代码中:我能';不要用Angular2阅读Excel,excel,angular,Excel,Angular,我想将带有Angular的Excel发送到我的服务器(SpringBoot)。我不能这样做 所以,我想我的问题可能是“Angular不读Excel”。我试图用Angular阅读Excel,但我得到了错误-> 我的意图是“如果Angular可以阅读Excel,那么我将尝试发送Excel。” 因为我正在尝试发送Excel,但无法发送 然后: 在此代码中: fileChange(event) { let file: File = event.files[0]; let myRe
fileChange(event) {
let file: File = event.files[0];
let myReader: FileReader = new FileReader();
let fileType = event.parentElement.id;
myReader.onloadend = function (e) {
console.log(myReader.result);
}
console.log('fileType' , fileType);
myReader.readAsText(file);
}
fileChange(event) {
let fileList: FileList = event.target.files;
if (fileList.length > 0) {
let file: File = fileList[0];
this.formData.append('uploadFile', file, file.name);
console.log('al cambiar file' , file);
}
console.log(' formdata' , this.formData );
console.log(' fileList' , fileList);
console.log('stack' , event.files[0]);
}
错误
这个代码我得到了->
在尝试使用此代码之前:
fileChange(event) {
let file: File = event.files[0];
let myReader: FileReader = new FileReader();
let fileType = event.parentElement.id;
myReader.onloadend = function (e) {
console.log(myReader.result);
}
console.log('fileType' , fileType);
myReader.readAsText(file);
}
fileChange(event) {
let fileList: FileList = event.target.files;
if (fileList.length > 0) {
let file: File = fileList[0];
this.formData.append('uploadFile', file, file.name);
console.log('al cambiar file' , file);
}
console.log(' formdata' , this.formData );
console.log(' fileList' , fileList);
console.log('stack' , event.files[0]);
}
结果
使用这段代码,我得到了文件名和最后一次修改,但我无法得到Excel的单元格。使用'xlsx'包
npm install xlsx
您可以显示您使用post方法发送的响应类型吗?您好,您可以在我的第一个链接“我的问题”中看到答案服务器。而不是标题。append('Content-Type','multipart/form data')更改标题。append('Content-Type','ResponseContentType.Blob')并尝试发布415(),状态:415,“error”:“Unsupported Media Type”异常“:“org.springframework.web.HttpMediaTypeNotSupportedException”,“message:“无效mime类型\”ResponseContentType.Blob \“:不包含“/”,“路径”:“/ml/insert”}”您当前使用的是哪个版本的angular?