use of com.google.api.services.sheets.v4.model.ExtendedValue in project OpenRefine by OpenRefine.
the class SpreadsheetSerializer method cellData2sheetCellData.
private com.google.api.services.sheets.v4.model.CellData cellData2sheetCellData(CellData cellData) {
com.google.api.services.sheets.v4.model.CellData sheetCellData = new com.google.api.services.sheets.v4.model.CellData();
ExtendedValue ev = new ExtendedValue();
if (cellData != null) {
if (cellData.value instanceof String) {
ev.setStringValue((String) cellData.value);
} else if (cellData.value instanceof Integer) {
ev.setNumberValue(new Double((Integer) cellData.value));
} else if (cellData.value instanceof Double) {
ev.setNumberValue((Double) cellData.value);
} else if (cellData.value instanceof OffsetDateTime) {
// supposedly started internally as a double, but not sure how to transform correctly
// ev.setNumberValue((Double) cellData.value);
ev.setStringValue(cellData.value.toString());
} else if (cellData.value instanceof Boolean) {
ev.setBoolValue((Boolean) cellData.value);
} else if (cellData.value == null) {
ev.setStringValue("");
} else {
ev.setStringValue(cellData.value.toString());
}
} else {
ev.setStringValue("");
}
sheetCellData.setUserEnteredValue(ev);
return sheetCellData;
}
use of com.google.api.services.sheets.v4.model.ExtendedValue in project OpenRefine by OpenRefine.
the class SpreadsheetSerializerTests method testDataTypes.
@Test
public void testDataTypes() {
// options is null, but unused
SUT.startFile(options);
List<CellData> row = new ArrayList<>();
row.add(new CellData("null value", null, "null value", null));
row.add(new CellData("string value", "a string", "a string as string", null));
row.add(new CellData("integer value", 42, "42", null));
row.add(new CellData("double value", new Double(42), "42.0", null));
row.add(new CellData("boolean value", true, "true", null));
OffsetDateTime now = OffsetDateTime.now(ZoneId.of("Z"));
row.add(new CellData("datetime value", now, now.toString(), null));
SUT.addRow(row, false);
List<Request> requests = SUT.prepareBatch(SUT.getRows());
assertEquals(requests.size(), 1);
List<RowData> rows = requests.get(0).getAppendCells().getRows();
assertEquals(rows.size(), 1);
List<com.google.api.services.sheets.v4.model.CellData> values = rows.get(0).getValues();
assertEquals(values.size(), 6);
ExtendedValue value = values.get(0).getUserEnteredValue();
assertEquals(value.getStringValue(), "");
value = values.get(1).getUserEnteredValue();
assertEquals(value.getStringValue(), "a string");
value = values.get(2).getUserEnteredValue();
assertEquals(value.getNumberValue(), new Double(42));
value = values.get(3).getUserEnteredValue();
assertEquals(value.getNumberValue(), new Double(42));
value = values.get(4).getUserEnteredValue();
assertEquals(value.getBoolValue(), Boolean.TRUE);
value = values.get(5).getUserEnteredValue();
assertEquals(value.getStringValue(), now.toString());
}
Aggregations