java 上传excel 表格

package com.zuma.website.elasticsearch.controller;
import com.zuma.common.utils.rpc.ResultMessage;
import org.apache.poi.hslf.model.Sheet;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Workbook;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.FileInputStream;

/**
 * Created by futianwei on 2019/4/3.
 */
@Controller
@RequestMapping("/search-api")
@ResponseBody
public class NewsInfoSearchControllerTest {





    @RequestMapping("/doTestFile")
    public ResultMessage doTestFile(MultipartFile file) {
        ResultMessage res=new ResultMessage();
        res.setMessage("success");
        try{
            //判断文件类型
            String fileName="";
            if(file==null){
                fileName="文件为空";
            }else{
                fileName=file.getOriginalFilename();
                if(fileName.endsWith(".xls")){
                    HSSFWorkbook wb = new HSSFWorkbook(new POIFSFileSystem(file.getInputStream()));
                    HSSFSheet sheet = wb.getSheetAt(0);
                    for(int j=0;j 
 

你可能感兴趣的:(java 上传excel 表格)