How to get the contents of a cell in a google spreadsheet using java and Google Spreadsheet API

StackOverflow https://stackoverflow.com/questions/19952232

  •  30-07-2022
  •  | 
  •  

Question

After connect to spreadsheet properly, attempt to obtain the contents of a particular cell: the 'C6' cell. The content of this cell is a number: '49', but the result I get is: 'com.google.gdata.data.TextContent@528ca407'

Here is the code I'm using:

for (CellEntry cell : cellFeed.getEntries()) {
      if (cell.getTitle().getPlainText().equals("C6")) {
          System.out.println (cell.getContent());
      } 
    }

I've also tested with: cell.getCell().getInputValue()
obtaining the same result

Thanks in advance!

Was it helpful?

Solution

CellDemo.java shows how. See https://code.google.com/p/gdata-java-client/source/browse/trunk/java/sample/spreadsheet/cell/CellDemo.java?r=51

From CellDemo.java:

/**
 * Prints out the specified cell.
 * 
 * @param cell the cell to print
 */
public void printCell(CellEntry cell) {
  String shortId = cell.getId().substring(cell.getId().lastIndexOf('/') + 1);
  out.println(" -- Cell(" + shortId + "/" + cell.getTitle().getPlainText()
      + ") formula(" + cell.getCell().getInputValue() + ") numeric("
      + cell.getCell().getNumericValue() + ") value("
      + cell.getCell().getValue() + ")");
}

OTHER TIPS

You can define the row and column number as param
It will be good for fetching single cell and multiple cell
for column "C6", Cell R1C1 address is min-row=6&max-row=6&min-col=3&max-col=3

URL cellFeedUrl1 = new URI(worksheets.get(wSID).getCellFeedUrl()+ "?min-row=6&max-row=6&min-col=3&max-col=3").toURL();
CellFeed cellFeed1 = googleservice.getFeed(cellFeedUrl1, CellFeed.class);

        for (CellEntry cell : cellFeed1.getEntries()) {
            System.out.println(cell.getPlainTextContent());
            }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top