Free Support Forum - aspose.com

Aspose Cells getCellsAPI


#1

Hi,
how do you load data to memory while using Light cells, are you load entire spreadsheet cells into InMemory? can you explain briefly? what light cells actually do? are they reduce memory by keeping the only necessary parameters?


#2

Sample Code I used
public class Listener implements LightCellsDataHandler {

@Override
public boolean startSheet(Worksheet worksheet) {
    System.out.println("START WORKSHEET");
    return true;
}

@Override
public boolean startRow(int i) {
    System.out.println("START ROW"+i);
    return true;
}

@Override
public boolean processRow(Row row) {
    System.out.println("PROCESS ROW");
    return false;
}

@Override
public boolean startCell(int i) {
    System.out.println("START CELL"+i);
    return true;
}

@Override
public boolean processCell(Cell cell) {
    System.out.println("PROCESS CELL");
    System.out.println(cell.getStringValue());
    return false;
}

}

 public static void main(String[] args) {
    Scanner in = new Scanner(System.in);

    String fileName = null
    fileName = "/../csv/1.19lac lines.csv";
    LoadOptions options= new LoadOptions();
    Listener l = new Listener();
    options.setLightCellsDataHandler(l);
    long start = System.currentTimeMillis();
    try {
        Workbook b = new Workbook(fileName,options);
        WorksheetCollection sheets = b.getWorksheets();
        int length = sheets.getCount();
        for(int i=0;i<length;i++){
            Worksheet sheet = sheets.get(i);
            _printCells(sheet);
        }

    } catch (Exception e) {
        e.printStackTrace();
    }
    System.out.println("Exit");
    long end = System.currentTimeMillis();
    System.out.println("Performance "+(end-start)+"ms");
}



public static void _printCells(Worksheet sheet){
    Cells cells = sheet.getCells();
    Iterator iterator = cells.iterator();
    while(iterator.hasNext()){
        Cell cell = (Cell)iterator.next();
        System.out.println(cell.getStringValue());
    }

}

#3

@Sundarcj,

Thanks for the query.

Well, when you load the template file with LightCells API, data of those cell objects should be processed in your implementation of LightCellsDataHandler you specify, e.g mainly in the method processCell(). And, if you return false for this method, then the cell’s data will not be kept in memory any more, so it will be absent from the corresponding cells collection of the Worksheet. Because of that, your code of looping sheets and cells after the constructor of the Workbook will output nothing.

On the other hand, if you return true for all cells for your implementation of processCell(), then all cells will be kept in the memory (in the Cells model) and the memory cost will be same with loading template file without LightCells. You can determine whether one cell’s data should be kept in memory or not, and by this way, you can control the memory cost for loading large template files.

For complete reference on using LightCells APIs with examples, see the document:
https://docs.aspose.com/display/cellsjava/Using+LightCells+API


#4

can you provide an example other than the docs example. am confused why my LightCellsDataHandler doesnt print anything !!


#5

@Sundarcj,

We will look into it and provide the sample code soon.

By the way, as a side note, I see you return false in the processCell method. Could you specify to return it to true as we explained in previous reply if it works