Ask a Question

unable to resolve class Sheet getSheet(0) error

punter
Contributor

unable to resolve class Sheet getSheet(0) error

Hi,

 

I am trying to fetch  data from excel sheet but using below code but I am getting error.attaching the project and excel sheet also.

 

import jxl.*;
import java.io.File;
import java.io.IOException;
import java.util.Locale;
import jxl.write.*

 


def testData = Workbook.getWorkbook(new File("D:\\Book1.xlsx"))
Sheet s1 = testData.getSheet(0)-----it is where I am getting error
def rows = s1.getRows()
for(def i=0;i<rows;i++)
{
 def c1 = s1.getCell(0, i)
 def c2 = s1.getCell(1, i)
 testRunner.testCase.setPropertyValue("Zip1",c1.getContents())
}

 

 

error

 

org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: Script104.groovy: 11: unable to resolve class Sheet @ line 11, column 7. Sheet s1 = testData.getSheet(0) ^ org.codehaus.groovy.syntax.SyntaxException: unable to resolve class Sheet @ line 11, column 7. at org.codehaus.groovy.ast.ClassCodeVisitorSupport.addError(ClassCodeVisitorSupport.java:146) at org.codehaus.groovy.control.ResolveVisitor.resolveOrFail(ResolveVisitor.java:222) at org.codehaus.groovy.control.ResolveVisitor.resolveOrFail(ResolveVisitor.java:232) at org.codehaus.groovy.control.ResolveVisitor.transformVariableExpression(ResolveVisitor.java:866) at org.codehaus.groovy.control.ResolveVisitor.transform(ResolveVisitor.java:634) at org.codehaus.groovy.control.ResolveVisitor.transformDeclarationExpression(ResolveVisitor.java:1003) at org.codehaus.groovy.control.ResolveVisitor.transform(ResolveVisitor.java:638) at org.codehaus.groovy.ast.ClassCodeExpressionTransformer.visitExpressionStatement

1 REPLY 1
sanj
Super Contributor

Re: unable to resolve class Sheet getSheet(0) error

I have dealt with opening excels spreadsheet with java

My question was why would you not use 

import org.apache.poi.hssf.usermodel.HSSFWorkbook

I am also attaching link that explains on how to use this.

This would be much easier

https://stackoverflow.com/questions/17537230/open-existing-excel-file-in-groovy

 

You like the reply. How to give a Kudos / Accept as solution?

 

cancel
Showing results for 
Search instead for 
Did you mean: