网站设计论文,仿牌外贸网站,wordpress禁用修正版,公司免费注册java开发#xff0c;增删改查#xff0c;涉及到导入excel时#xff0c;有的excel导入失败提示Cant open workbook - unsupported file type: XML。着急赶工期#xff0c;告诉客户先把excel另存为xls格式#xff0c;再重新导入。现在有点空余时间#xff0c;好…java开发增删改查涉及到导入excel时有的excel导入失败提示Cant open workbook - unsupported file type: XML。着急赶工期告诉客户先把excel另存为xls格式再重新导入。现在有点空余时间好好研究了下解决了这个问题。直接上操作啊.
import com.spire.xls.FileFormat;
import org.apache.poi.EmptyFileException;
import org.apache.poi.poifs.filesystem.FileMagic;
//获取文件输入流
InputStream checkis FileMagic.prepareToCheckMagic(file.getInputStream());
byte[] emptyFileCheck new byte[1];
checkis.mark(emptyFileCheck.length);
if (checkis.read(emptyFileCheck) emptyFileCheck.length) {throw new EmptyFileException();
} else {checkis.reset();FileMagic fm FileMagic.valueOf(checkis);//开始判断文件是不是xml格式if (FileMagic.XML fm) {com.spire.xls.Workbook workbooknew com.spire.xls.Workbook();workbook.loadFromXml(file.getInputStream());workbook.saveToFile(fileName, FileFormat.Version2013);//接下来开始处理导入excel文件****}
}
参考了 poi读取excel报错Your InputStream was neither an OLE2 stream, nor an OOXML stream-CSDN博客