poi-general mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ɓukasz Jarych <jarys...@gmail.com>
Subject Problem with reading workbook
Date Sat, 19 May 2018 15:40:25 GMT
Hi Guys,

i have very big problem with reading named ranges using poi.

My code is :

import java.io.File;
>
> import java.io.IOException;
>
>
>> import org.apache.poi.EncryptedDocumentException;
>
> import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
>
> import org.apache.poi.ss.SpreadsheetVersion;
>
> import org.apache.poi.ss.usermodel.Cell;
>
> import org.apache.poi.ss.usermodel.Row;
>
> import org.apache.poi.ss.usermodel.Sheet;
>
> import org.apache.poi.ss.usermodel.WorkbookFactory;
>
> import org.apache.poi.ss.util.AreaReference;
>
> import org.apache.poi.ss.util.CellReference;
>
> import org.apache.poi.xssf.usermodel.XSSFName;
>
>
>> public class WorkbookCreate {
>
>
>> public static void main(String[] args) throws IOException {
>
>
>>     // setup code
>
>     String cname = "TestName";
>
>
>
>     org.apache.poi.ss.usermodel.Workbook wb = null;
>
> try {
>
> wb = WorkbookFactory.create(new File("C:\\Users\\admin\\Desktop\\Example
>> Variable3.xlsm"));
>
> } catch (EncryptedDocumentException | InvalidFormatException | IOException
>> e) {
>
> // TODO Auto-generated catch block
>
> e.printStackTrace();
>
> }
>
> int namedCellIdx = wb.getNameIndex("Test");
>
> System.out.println(namedCellIdx);
>
>     org.apache.poi.ss.usermodel.Name aNamedCell =
>> wb.getNameAt(namedCellIdx);
>
>
>
>     System.out.println(aNamedCell);
>
>
>
>     AreaReference[] arefs =
>> AreaReference.generateContiguous(aNamedCell.getRefersToFormula());
>
>
>
>     for (int i=0; i<arefs.length; i++) {
>
>         // Only get the corners of the Area
>
>         // (use arefs[i].getAllReferencedCells() to get all cells)
>
>         CellReference[] crefs = arefs[i].getCells();
>
>         for (int j=0; j<crefs.length; j++) {
>
>             // Check it turns into real stuff
>
>             Sheet s = wb.getSheet(crefs[j].getSheetName());
>
>             Row r = s.getRow(crefs[j].getRow());
>
>             Cell c = r.getCell(crefs[j].getCol());
>
>             // Do something with this corner cell
>
>         }
>
>     }
>
>
>
>     }
>
>
>> }
>
>
I do not see getCells() method
"The method getCells() is undefined for the type AreaReference"

and generateContinous is crossed out.

Why?

My workbook is in Attachment.

I want to read named range "Test" and "TestVariable"

Please help,
Jacek

Mime
View raw message