Marco
Marco

Reputation: 11

Google sheet api V4 Java: multiline cell value

I'm using java Google sheet api v4 which works pretty well. On thing I cannot figure out is the separator character for multiline cell value

Let say I have A2 cell in "mySheet" sheet which contains a multline value such as: Value1 Value2 Value3

    String range = "mySheet!A2";
    ValueRange valueRange = sheetService.spreadsheets().values().get(spreadsheet.getSpreadsheetId(), range).execute();
    List<List<Object>> rowsValues = valueRange.getValues();
    for (List<Object> rowValues : rowsValues) {
        String rowValue = (String) rowValues.get(0);
        List<String> splittedValue = Arrays.asList(objectType.split(?????));
    }

I hope my question is clear enough.
Thanks a lot for your help.

Upvotes: 0

Views: 613

Answers (2)

Marco
Marco

Reputation: 11

I finally figured it out. As Sam said, I had already tried to split with a linebreak character. But I ended up with a special character "&#xD";

Solution is to user Scanner class

    String range = "mySheet!A2";
    ValueRange valueRange = sheetService.spreadsheets().values().get(spreadsheet.getSpreadsheetId(), range).execute();
    List<List<Object>> rowsValues = valueRange.getValues();
    for (List<Object> rowValues : rowsValues) {
        String rowValue = (String) rowValues.get(0);
        List<String> splittedValue = new ArraysList<String>();
        Scanner scanner = new Scanner(objectType);
        while (scanner.hasNextLine()) {
            splittedValue .add(scanner.nextLine());
        }
        scanner.close();
    }

Finally the list is clean and doesn't contain special charater.

Thanks for your help Sam

Upvotes: 0

Sam Berlin
Sam Berlin

Reputation: 3773

All data within a cell is just text, so if something is on multiple lines then it's separated with a linebreak character: \n.

Upvotes: 2

Related Questions