Hello,
In JAVA program, I am trying access a method from a Excel class but I am unable to instantiate the Excel class to access the method defined in Excel class.
Eclipse shows error as "The constructor Excel(String) is not visible." Please suggest how to instantiate the class to access the members of the class.
Please suggest.
import com.atlassian.jira.rest.client.api.domain.Attachment; import com.atlassian.jira.rest.client.api.domain.Issue; import com.bwc.testcase.TestcaseKeyword; import com.bwc.util.JIRA; import com.bwc.util.excel.Excel; import com.bwc.util.excel.ExcelUtil; public class TestExcel extends TestcaseKeyword { Excel test = new Excel("abc"); public void getattachments() throws EncryptedDocumentException, IOException { JIRA jira = JIRA.getInstance(); Issue message = jira.getIssue("TEST-123"); Iterator<Attachment> iter = message.getAttachments().iterator(); while (iter.hasNext()){ Attachment attachmentIter = iter.next(); String obj = attachmentIter.getFilename(); System.out.println(obj); test.loadExcel("C:\\Tools\\Automation\\JiraUpload\\jiraattachment\\data\\UploadAttachment.xlsx").getCellValue(0, 0); } } }
public class Excel { private String filePath; private Map<String,Integer> currentRow; // the current row private Workbook workbook; private String currentSheet; //the current sheet name DataFormatter objDefaultFormat; FormulaEvaluator objFormulaEvaluator; private Excel(String file) { this(file,null); } private Excel(String file,String sheetName) { this.filePath=file; this.currentSheet=sheetName; this.currentRow=new HashMap<String,Integer>(); currentRow.put(sheetName, 1); this.objDefaultFormat= new DataFormatter(); objFormulaEvaluator=null; try { FileInputStream inputStream=new FileInputStream(filePath); if(filePath.endsWith(".xlsx")) { this.workbook =new XSSFWorkbook(inputStream); this.objFormulaEvaluator= new XSSFFormulaEvaluator((XSSFWorkbook)workbook); } else { this.workbook = new HSSFWorkbook(inputStream); this.objFormulaEvaluator= new HSSFFormulaEvaluator((HSSFWorkbook)workbook); } if(StringUtil.isEmpty(sheetName)) { sheetName=workbook.getSheetName(0); } } catch (Exception e) { throw new ActionFailedException("Failed to load file:"+filePath); } } public static Excel loadExcel(String file,String sheetName) { return new Excel(file,sheetName); }