Java EXCELファイルのContent-Typeの判定方法

説明
1.application/vnd.ms-excel
EXCELファイル( .xls OFFICE 2007より過去)

2.application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
EXCELファイル( .xlsx OFFICE 2007以降)

使用例

MultipartFile regFile = this.form.getRegFile();
if (!(("application/vnd.ms-excel").equals(regFile.getContentType()) // office2007より過去
                              || ("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet") // office2007以降
                                          .equals(regFile.getContentType()))) { 
                  super.addError(xxxx);
                        処理コード
}

 

Java

Posted by arkgame