October 22, 2024
Chicago 12, Melborne City, USA
java

Getting the Content of a Cell from a workbook


In previos versions of graph i was able to get the value of a cell in excel pretty easy

in v5.8 i did this

List<WorkbookWorksheet> worksheets = workbookreq.worksheets().buildRequest().get().getCurrentPage();
for (WorkbookWorksheet worksheet : worksheets) {
    WorkbookWorksheetRequestBuilder worksheetReq = workbookreq.worksheets(worksheet.id);
    WorkbookWorksheetRangeRequest rangeReq = worksheetReq.range().buildRequest();
    WorkbookWorksheetUsedRangeRequest usedRangeReq = worksheetReq.usedRange().buildRequest();

    WorkbookWorksheetCellParameterSet cellParam = new WorkbookWorksheetCellParameterSet();

    cellParam.column = 3;
    cellParam.row = 4;
    String cellValue = worksheetReq.cell(cellParam).buildRequest().get().values.getAsString();

}

now i have to migrate this code to v6.0

and i cannot seem to get the cell value in a simple way,

this is how i was able to get it

List<WorkbookWorksheet> worksheets = workbookreq.worksheets().get().getValue();
for (WorkbookWorksheet worksheet : worksheets) {
    WorkbookWorksheetItemRequestBuilder worksheetReq = workbookreq.worksheets().byWorkbookWorksheetId(worksheet.getId());

    String cellValue = "";

    WorkbookRange cell = worksheetReq.cellWithRowWithColumn(3, 4).get();
    
    UntypedArray values = (UntypedArray) ((ArrayList)cell.getValues().getValue()).get(0);
    for (UntypedNode untypedNode : values.getValue()) {
        cellValue = untypedNode.getValue().toString();
    }
}

i dont think this is the correct way, because of the way i have to do multiple cast and do multuple getValues and getValue.

i have been looking at microsfot documentation and online but i cannot seem to find another way of doing this



You need to sign in to view this answers

Leave feedback about this

  • Quality
  • Price
  • Service

PROS

+
Add Field

CONS

+
Add Field
Choose Image
Choose Video