gpt4 book ai didi

java - 如何解决无法解析类XSSFWorkbook的问题?

转载 作者:行者123 更新时间:2023-12-01 12:41:05 25 4
gpt4 key购买 nike

我正在尝试使用下面的代码读取 xlsx 文件,但无法得到结果类。任何帮助将不胜感激...

org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: Script7.groovy: 8: unable to resolve class XSSFWorkbook @ line 8, column 11. srcBook = new XSSFWorkbook(new FileInputStream(new File("C:\\PerTableData\\TestData-Mix.xlsx"))) ^ org.codehaus.groovy.syntax.SyntaxException: unable


import org.apache.poi.ss.usermodel.*;
//import org.apache.poi.ss.usermodel.DataFormatter

//Create data formatter
//dFormatter = new DataFormatter()

//Create a new workbook using POI API
srcBook = new XSSFWorkbook(new FileInputStream(new File("C:\\PerTableData\\TestData-Mix.xlsx")))

//Create formula evaluator to handle formula cells
fEval = new XSSFFormulaEvaluator(srcBook)

//Get first sheet of the workbook (assumes data is on first sheet)
sourceSheet = srcBook.getSheetAt(0)

//Sets row counter to 0 (first row)-- if your sheet has headers, you can set this to 1
context.rowCounter = 0

//Read in the contents of the first row
sourceRow = sourceSheet.getRow(0)

//Step through cells in the row and populate property values-- note the extra work for numbers
elNameCell = sourceRow.getCell(0)
testCase.setPropertyValue("ElName",dFormatter.formatCellValue(elNameCell,fEval))

atNumCell = sourceRow.getCell(1)
testCase.setPropertyValue("AtNum",dFormatter.formatCellValue(atNumCell,fEval))

symbolCell = sourceRow.getCell(2)
testCase.setPropertyValue("Symbol",dFormatter.formatCellValue(symbolCell,fEval))

atWtCell = sourceRow.getCell(3)
testCase.setPropertyValue("AtWeight",dFormatter.formatCellValue(atWtCell,fEval))

boilCell = sourceRow.getCell(4)
testCase.setPropertyValue("BoilPoint",dFormatter.formatCellValue(boilCell,fEval))

//Rename request test steps for readability in the log; append the element name to the test step names
testCase.getTestStepAt(0).setName("GetAtomicNumber-" + testCase.getPropertyValue("AtNum"))
testCase.getTestStepAt(1).setName("GetAtomicWeight-" + testCase.getPropertyValue("AtWeight"))
testCase.getTestStepAt(2).setName("GetElementySymbol-" + testCase.getPropertyValue("Symbol"))

//Add references to sheet to re-use it in ReadNextLine step
context.srcWkSheet = sourceSheet

最佳答案

添加导入:

import org.apache.poi.xssf.usermodel.XSSFWorkbook;
^^^^

您只添加了:

import org.apache.poi.ss.usermodel.*;

关于java - 如何解决无法解析类XSSFWorkbook的问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25092771/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com