use of com.google.api.services.sheets.v4.model.Spreadsheet in project repairnator by Spirals-Team.
the class GoogleSpreadSheetFactory method insertData.
public static void insertData(List<List<Object>> dataRows, Sheets sheets, String range, Logger logger) {
ValueRange valueRange = new ValueRange();
valueRange.setValues(dataRows);
try {
AppendValuesResponse response = sheets.spreadsheets().values().append(GoogleSpreadSheetFactory.getSpreadsheetID(), range, valueRange).setInsertDataOption("INSERT_ROWS").setValueInputOption("USER_ENTERED").execute();
if (response != null && response.getUpdates().getUpdatedCells() > 0) {
logger.debug("Data have been inserted in Google Spreadsheet.");
}
} catch (IOException e) {
logger.error("An error occurred while inserting data in Google Spreadsheet.", e);
}
}
use of com.google.api.services.sheets.v4.model.Spreadsheet in project teiid by teiid.
the class SheetsAPI method insert.
/**
* Insert row into spreadsheet
* @param spreadsheetKey key that identifies spreadsheet
* @param pairs key that identifies worksheet
* @param worksheet name - value pair that should be inserted into spreadsheet
* @return 1 if the row is successfully inserted
*/
public UpdateResult insert(String spreadsheetId, Map<String, Object> pairs, Worksheet worksheet) {
ValueRange content = new ValueRange();
List<Object> row = new ArrayList<>();
for (String label : worksheet.getColumns().keySet()) {
Object value = pairs.get(label);
if (value != null) {
if (value instanceof String) {
// $NON-NLS-1$
value = "'" + value;
} else if (!(value instanceof Boolean || value instanceof Double)) {
value = value.toString();
}
// else directly supported
}
row.add(value);
}
content.setValues(Arrays.asList(row));
try {
service.spreadsheets().values().append(spreadsheetId, worksheet.getName(), content).setValueInputOption(// $NON-NLS-1$ -- TODO: this could be configurable
"USER_ENTERED").execute();
} catch (IOException e) {
throw new SpreadsheetOperationException("Error inserting spreadsheet row", e);
}
return new UpdateResult(1, 1);
}
use of com.google.api.services.sheets.v4.model.Spreadsheet in project teiid by teiid.
the class SpreadsheetMetadataExtractor method extractMetadata.
public SpreadsheetInfo extractMetadata(String spreadsheetId) {
try {
Spreadsheet spreadsheet = sheetsAPI.getSpreadsheet(spreadsheetId);
SpreadsheetInfo metadata = new SpreadsheetInfo(spreadsheet.getProperties().getTitle());
metadata.setSpreadsheetKey(spreadsheet.getSpreadsheetId());
for (Sheet sheet : spreadsheet.getSheets()) {
String title = sheet.getProperties().getTitle();
Worksheet worksheet = metadata.createWorksheet(title);
worksheet.setId(sheet.getProperties().getSheetId().toString());
List<Column> cols = dataProtocolAPI.getMetadata(spreadsheet.getSpreadsheetId(), title);
if (!cols.isEmpty()) {
if (cols.get(0).getLabel() != null) {
worksheet.setHeaderEnabled(true);
}
}
for (Column c : cols) {
worksheet.addColumn(c.getLabel() != null ? c.getLabel() : c.getAlphaName(), c);
}
}
return metadata;
} catch (IOException ex) {
throw new SpreadsheetOperationException(SpreadsheetManagedConnectionFactory.UTIL.gs("metadata_error"), // $NON-NLS-1$
ex);
}
}
use of com.google.api.services.sheets.v4.model.Spreadsheet in project selenium_java by sergueik.
the class Quickstart method main.
public static void main(String[] args) throws IOException {
// Build a new authorized API client service.
Sheets service = getSheetsService();
// Prints the names and majors of students in a sample spreadsheet:
// https://docs.google.com/spreadsheets/d/1BxiMVs0XRA5nFMdKvBdBZjgmUUqptlbs74OgvE2upms/edit
String spreadsheetId = "1BxiMVs0XRA5nFMdKvBdBZjgmUUqptlbs74OgvE2upms";
String range = "Class Data!A2:E";
ValueRange response = service.spreadsheets().values().get(spreadsheetId, range).execute();
List<List<Object>> values = response.getValues();
if (values == null || values.size() == 0) {
System.out.println("No data found.");
} else {
System.out.println("Name, Major");
for (List row : values) {
// Print columns A and E, which correspond to indices 0 and 4.
System.out.printf("%s, %s\n", row.get(0), row.get(4));
}
}
}
Aggregations