1

I am working with a large xlsm file, the file has many tabs and i want to parse a specific tab information.I am able to load the file using apache EventUsrerModel documentaion.But i am not able to get the specific tab information using XSSFReader and also i have used another APIs like XSSFWorkBook with OCPPackage, but it is failing me with heap space.Only XSSFReader is able to load the document into the system but i don't know how to get a specific tab information using it. Here i am giving the code i have upto now,

I am using a java class where i am setting the large file like ,

public class LargeExcelManager {

private OPCPackage pkg ;



public OPCPackage getPkg() {
    return pkg;
}

public void setPkg(OPCPackage pkg) {
    this.pkg = pkg;
}

public LargeExcelManager(String fileName)throws Exception {

    openWorkbook(fileName);
}

private void openWorkbook(String fileName)throws Exception {
    try {
        System.out.println("Can be added now");
        //File myFile = new File(fileName);
        this.setPkg(OPCPackage.open(fileName));
    } catch (Exception e) {
        e.printStackTrace();
    }
     }


  }

And here i am loading the document using XSSFReader,

public void startElement(String uri, String localName, String name,
            Attributes attributes) throws SAXException {
        try {

        // c => cell
        if(name.equals("c")) {
            // Print the cell reference
            System.out.print(attributes.getValue("r") + " - ");
            String  rowIndex = (attributes.getValue("r")); 
            //  I have to ignore some rows here and get the data how can i do that ?
            // Figure out if the value is an index in the SST
            String cellType = attributes.getValue("t");
            if(cellType != null && cellType.equals("s")) {
                nextIsString = true;
            } else {
                nextIsString = false;
            }
        }
        // Clear contents cache
        lastContents = "";
        }catch(Exception e) {
            e.printStackTrace();
        }
    }

Is this is the wright way i am passing the sheet "Loan information" that i am getting to the process ?? If so can anyone tell me how i can get the the desired row information from it ???

Mandrek
  • 1,159
  • 6
  • 25
  • 55
  • Can anyone help ?? I am struggling from yesterday – Mandrek Feb 14 '18 at 10:43
  • By "specific tab", do you mean one particular Sheet in the Workbook? Or something else? – Gagravarr Feb 14 '18 at 10:44
  • @Gagravarr yes the workbook contains with several sheets , one of them is loan information which i have to process.Is there any way out ? – Mandrek Feb 14 '18 at 10:49
  • @Gagravarr you can see my last code i have mentioned how i was trying to parse the specific sheet – Mandrek Feb 14 '18 at 10:51
  • @Gagravarr is it possible anyways ?? – Mandrek Feb 14 '18 at 11:22
  • Process the (small) Workbook Data section with a DOM parser, grab the relationship ID, then [fetch and process just that sheet's data](https://poi.apache.org/apidocs/org/apache/poi/xssf/eventusermodel/XSSFReader.html#getSheet-java.lang.String-) ? – Gagravarr Feb 14 '18 at 11:48
  • @Gagravarr i have found how i will get the specific tab information by event module.Now can you tell how to process the information row wise ?? – Mandrek Feb 14 '18 at 11:49
  • @Gagravarr can you give me an example or edit my code ? – Mandrek Feb 14 '18 at 12:41
  • @Gagravarr can you new please check the approach i am trying ? – Mandrek Feb 14 '18 at 13:45
  • Did you try reading the SAX example on the Apache POI website? What happens if you now follow that? – Gagravarr Feb 14 '18 at 14:24
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/165158/discussion-between-mandrek-and-gagravarr). – Mandrek Feb 14 '18 at 14:28
  • @Gagravarr i am trying to override the startElement method but , the problem is i have process some row and have to reject some row .Now what i am getting is each cell name when i am trying to use String rowIndex = (attributes.getValue("r")); so can i have a method which will return a rowIndex ??? – Mandrek Feb 14 '18 at 14:31
  • @Gagravarr can you atleast tell how to get the rowIndex from here? I have tried a lot u can see ? – Mandrek Feb 14 '18 at 14:38
  • Anyone have the answers here ? – Mandrek Feb 14 '18 at 14:57

0 Answers0