简体   繁体   English

Google Sheet API V4 Java:多行单元格值

[英]Google sheet api V4 Java: multiline cell value

I'm using java Google sheet api v4 which works pretty well. 我正在使用效果很好的Java Google Sheet API v4。 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 假设我在“ mySheet”表中有一个A2单元格,其中包含一个多义线值,例如: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. 非常感谢你的帮助。

单元格中的所有数据都是文本,因此,如果某行位于多行中,则将它们用换行符分隔: \\n

I finally figured it out. 我终于弄明白了。 As Sam said, I had already tried to split with a linebreak character. 正如Sam所说,我已经尝试过使用换行符拆分。 But I ended up with a special character "&#xD"; 但是我最后使用了特殊字符“&#xD”;

Solution is to user Scanner class 解决方案是针对用户Scanner类

    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 感谢您的帮助,山姆

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM