Excel导入程序无法在Grails 2.2.1中运行

时间:2014-08-06 12:07:34

标签: excel grails file-upload

当我上传文件时,我正在使用Grails 2.2.1和excel-import:1.0.0以及joda-time:1.4,它显示以下错误:

NoSuchMethodError occurred when processing request: [POST] /pms/uploadData/uploadFiles
org.apache.poi.ss.formula.WorkbookEvaluator.<init>(Lorg/apache/poi/ss/formula/EvaluationWorkbook;Lorg/apache/poi/ss/formula/IStabilityClassifier;Lorg/apache/poi/hssf/record/formula/udf/UDFFinder;)V. Stacktrace follows:
Message: Executing action [uploadFiles] of controller [uploadData.UploadDataController] in plugin [pms] caused exception: Runtime error executing action
    Line | Method
->>  195 | doFilter  in grails.plugin.cache.web.filter.PageFragmentCachingFilter
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|     63 | doFilter  in grails.plugin.cache.web.filter.AbstractFilter
|   1110 | runWorker in java.util.concurrent.ThreadPoolExecutor
|    603 | run       in java.util.concurrent.ThreadPoolExecutor$Worker
^    722 | run . . . in java.lang.Thread

上传文件的控制器代码为:

static int counted
def excelImportService
def uploadFiles(){          
        def uploadedFile = request.getFile('myFile')           
        if (uploadedFile.empty) {              
            return
        }
        def webRoot = servletContext.getRealPath("/")
        File filecheck = new File(webRoot, counted + ".xls")
        if (!filecheck.exists()) {
            filecheck.createNewFile()
        }
        counted++
        if (counted == 11) { 
            counted = 1
        }
        int threadTime = 2000
        while (!filecheck.canWrite()) {
            Thread.sleep(threadTime)
            threadTime += 5000
            if (threadTime > 10000) {  
                threadTime = 2000
            }
        }
        uploadedFile.transferTo(filecheck)
        String fileName = filecheck.toString()
        Workbook wb = WorkbookFactory.create(new FileInputStream(fileName))            

        ExcelImporter importer = new ExcelImporter(fileName);
}

并且GSP页面形式为:

<g:uploadForm controller="uploadData" action="uploadFiles">
    <input class="form-control  btn btn-primary btn-xs" type="file" name="myFile" id="chooseFile"  />
    <input class="btn btn-primary " id="subButn" value="Add" type="submit"/>
</g:uploadForm>

我为上传文件导入了以下内容:

import org.apache.poi.ss.usermodel.WorkbookFactory
import org.apache.poi.ss.formula.WorkbookEvaluator

1 个答案:

答案 0 :(得分:0)

您是如何调用Excel导入服务的?以下是我使用过的几行代码。首先,您需要创建CONFIG_BOOK_COLUMN_MAP。我在2.1.5版本的应用程序中这样做。

Map CONFIG_BOOK_COLUMN_MAP = [
        sheet:'Sheet1',
        startRow: 1,
        columnMap:  [
                //Col, Map-Key
                'A':'recordID',
                'B':'recordVersion',
                'C':'stateUnitNumber',
                'D':'stateUnitType',
                'E':'stateSiteNumber',
        ]


Workbook workbook = WorkbookFactory.create(is)
def columnList = excelImportService.columns(workbook, CONFIG_BOOK_COLUMN_MAP)