我迷失在这个解决方案中。 1. Excel文件保存在服务器中; 2.使用Java API将excel文件读取为二进制数据。这是功能:
@Override
public byte[] retrieveExportedFileBinaryContent(String recordId, String userId) throws IOException, NoExportRecordException, InValidDownloadPermissionException{
CaseExportRecord caseExportRecord = caseExportRecordRepository.findById(recordId);
if( caseExportRecord!=null ){
CaseExportConfig caseExportConfig = caseExportConfigRepository.findByCaseExportRecords(caseExportRecord);
if(caseExportConfig.getUserId().equalsIgnoreCase(userId)){
String fileName = generateExportedFileNameWithPath(caseExportRecord);
Path path = Paths.get(fileName);
if( path!=null ){
return Files.readAllBytes(path);
}else{
throw new NoExportRecordException("Case Export Record File Does Not Exist");
}
} else {
throw new InValidDownloadPermissionException("You do not have permission to download this file.");
}
}else{
throw new NoExportRecordException("Case Export Record Id Not Exist");
}
}
使用NodeJS获取二进制数据并创建一个excel文件:
var fs = require('fs');
var wstream = fs.createWriteStream('my.xls');
wstream.write(fileData);
wstream.end();
这里fileData是Java API返回的二进制数据。
但现在,当我使用Excel打开这个xls文件时,它不再是好的excel,只有原始二进制数据显示在excel中。
如何从二进制数据创建一个好的Excel文件?
由于