Apache POI测试用例失败,因为它找不到CTExtensionList类

时间:2016-07-26 04:26:32

标签: java maven groovy apache-poi

我编写了简单的groovy spock测试用例来验证excel表。这是我在我的部分,我有以下内容。

for teEmp in json {

                    if teEmp.valueForKey("department") !== null {
                        if teEmp.valueForKey("department")  as! String == "Technology"{

                            // start core data

                            let entityDescription = NSEntityDescription.entityForName("Tech", inManagedObjectContext: self.managedObjectcontext!)
                            let tech = Employees(entity: entityDescription!,insertIntoManagedObjectContext: self.managedObjectcontext)

                            tech.id = teEmp.valueForKey("id")! as? String
                            tech.first_name = teEmp.valueForKey("firstname")! as? String
                            tech.card_id = (teEmp.valueForKey("cardId")!) as? String
                            tech.image = (teEmp.valueForKey("image")!) as? String
                            tech.last_name = (teEmp.valueForKey("lastname")!) as? String
                            tech.designation = (teEmp.valueForKey("designation")!) as? String
                            tech.department = (teEmp.valueForKey("department")!) as? String
                            if teEmp.valueForKey("startedDate") as! String != "null" {
                                let dateAsString = teEmp.valueForKey("startedDate")
                                dateFormatter.dateFormat = "MM/dd/YYYY"
                                let teStartDate = dateFormatter.dateFromString((dateAsString as? String)!)
                                dateFormatter.dateStyle = NSDateFormatterStyle.LongStyle
                                //dateFormatter.dateFormat = "MMM dd YYYY"
                                let techStartDay = dateFormatter.stringFromDate(teStartDate!)
                                tech.started_date = techStartDay as String
                            }
                            tech.departure_date = (teEmp.valueForKey("departureDate")!) as? String
                            tech.responsibilities = (teEmp.valueForKey("responsibilities")!) as? String
                            tech.address = (teEmp.valueForKey("address")!) as? String
                            tech.email = (teEmp.valueForKey("email")!) as? String
                            tech.shift = (teEmp.valueForKey("shift")!) as? String
                            tech.linkedIn_profile = (teEmp.valueForKey("linkedInProfile")!) as? String
                            tech.new_employee = (teEmp.valueForKey("newEmployee")!) as? String
                            tech.departed = (teEmp.valueForKey("departed")!) as? String
                            tech.supervisor = (teEmp.valueForKey("supervisor")!) as? String

                            if teEmp.valueForKey("birthDate") as! String != "null" {
                                let dateAsString = teEmp.valueForKey("birthDate")
                                dateFormatter.dateFormat = "MM/dd"
                                let teBirthDate = dateFormatter.dateFromString(dateAsString as! String)
                                dateFormatter.dateFormat = "MMM dd"
                                let techBirthMonth = dateFormatter.stringFromDate(teBirthDate!)
                                tech.birth_date = techBirthMonth
                            }

                            tech.privacy = (teEmp.valueForKey("privacy")!) as? String
                            if (teEmp.valueForKey("privacy")!) as? String == "PUBLIC"{
                                tech.contact = (teEmp.valueForKey("contact")!) as? String
                            } else {
                                tech.contact = "98********"
                            }



                            do {
                                try self.managedObjectcontext!.save()
                                print("Tech data saved in core data")

                            } catch let error as NSError
                            {
                                print(error.localizedDescription)


                            }
                            // end core data

                        }

                    }

                }

            }

        }catch  let error as NSError {
            print(error)
        }

        if(err != nil) {
            print(err!.localizedDescription)
            let jsonStr = NSString(data: data!, encoding: NSUTF8StringEncoding)
            print("Error could not parse JSON: '\(jsonStr)'")

        }
        else {


        }

我在访问then:"Should return the excel work book" workbook != null workbook.getNumberOfSheets() == 3 def sheet = workbook.getSheetAt(1); def row = sheet.getRow(4).getCell(0) def cell = row.getCell(0); cell.cellValue println cell 等单元格值时收到java.lang.ClassNotFoundException: org.openxmlformats.schemas.spreadsheetml.x2006.main.CTExtensionList

请告诉我这里的问题是什么?

查看jar poi-ooxml-schemas-3.14.jar,此类不可用。该类在poi-ooxml-schemas-3.14.jar中不可用,或者我们必须引用其他jar?

另外,通过查看此链接APACHE POI,我知道我们需要一个大小为15 MB的完整jar。我怎么能用maven得到它?

1 个答案:

答案 0 :(得分:2)

this Apache POI FAQ Entry中所述,poi-ooxml-schemas jar仅包含OOXML模式的最常见部分。如果你需要在公共集合之外使用任何东西,你必须抓住完整的OOXML Schemas jar,目前ooxml-schemas-1.3.jar

正如in that FAQPOI Components page所解释的那样,作为maven用户,您可以使用以下依赖项执行此操作:

<dependency>
  <groupId>org.apache.poi</groupId>
  <artifactId>ooxml-schemas</artifactId>
  <version>1.3</version>
</dependency>