首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Excel导入器在Grails 2.2.1中不起作用

Excel导入器在Grails 2.2.1中不起作用
EN

Stack Overflow用户
提问于 2014-08-06 20:07:34
回答 1查看 249关注 0票数 0

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

代码语言:javascript
复制
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

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

代码语言:javascript
复制
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页面形式为:

代码语言:javascript
复制
<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>

并且我已经为上传文件导入了以下内容:

代码语言:javascript
复制
import org.apache.poi.ss.usermodel.WorkbookFactory
import org.apache.poi.ss.formula.WorkbookEvaluator
EN

回答 1

Stack Overflow用户

发布于 2014-08-06 23:48:06

这可能是您调用Excel导入服务的方式吗?下面是我用过的几行代码。首先,您需要创建一个CONFIG_BOOK_COLUMN_MAP。我是在一个2.1.5版本的应用程序中这样做的。

代码语言:javascript
复制
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)
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/25160000

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档