Search in sources :

Example 1 with AppendDimensionRequest

use of com.google.api.services.sheets.v4.model.AppendDimensionRequest in project OpenRefine by OpenRefine.

the class SpreadsheetSerializerTests method test30columns.

@Test
public void test30columns() {
    // options is null, but unused
    SUT.startFile(options);
    List<CellData> cells = new ArrayList<>();
    for (int i = 0; i < 30; i++) {
        String colnum = Integer.toString(i);
        CellData cell = new CellData("col" + colnum, "text" + colnum, "text" + colnum, null);
        cells.add(cell);
    }
    SUT.addRow(cells, true);
    SUT.addRow(cells, false);
    List<Request> requests = SUT.prepareBatch(SUT.getRows());
    assertEquals(requests.size(), 2);
    for (Request request : requests) {
        if (request.getAppendDimension() instanceof AppendDimensionRequest) {
            return;
        }
    }
    fail("Failed to find AppendDimensionRequest for columns > 26");
}
Also used : AppendDimensionRequest(com.google.api.services.sheets.v4.model.AppendDimensionRequest) ArrayList(java.util.ArrayList) Request(com.google.api.services.sheets.v4.model.Request) AppendDimensionRequest(com.google.api.services.sheets.v4.model.AppendDimensionRequest) CellData(com.google.refine.exporters.TabularSerializer.CellData) Test(org.testng.annotations.Test)

Example 2 with AppendDimensionRequest

use of com.google.api.services.sheets.v4.model.AppendDimensionRequest in project OpenRefine by OpenRefine.

the class SpreadsheetSerializer method prepareBatch.

protected List<Request> prepareBatch(List<RowData> rows) {
    List<Request> requests = new ArrayList<>();
    // If this row is wider than our sheet, add columns to the sheet
    int columns = rows.get(0).getValues().size();
    if (columns > maxColumns) {
        AppendDimensionRequest adr = new AppendDimensionRequest();
        adr.setDimension("COLUMNS");
        adr.setLength(columns - maxColumns);
        maxColumns = columns;
        Request req = new Request();
        req.setAppendDimension(adr);
        requests.add(req);
    }
    AppendCellsRequest acr = new AppendCellsRequest();
    acr.setFields("*");
    acr.setSheetId(0);
    acr.setRows(rows);
    Request request = new Request();
    request.setAppendCells(acr);
    requests.add(request);
    return requests;
}
Also used : AppendDimensionRequest(com.google.api.services.sheets.v4.model.AppendDimensionRequest) AppendCellsRequest(com.google.api.services.sheets.v4.model.AppendCellsRequest) BatchUpdateSpreadsheetRequest(com.google.api.services.sheets.v4.model.BatchUpdateSpreadsheetRequest) Request(com.google.api.services.sheets.v4.model.Request) AppendDimensionRequest(com.google.api.services.sheets.v4.model.AppendDimensionRequest) AppendCellsRequest(com.google.api.services.sheets.v4.model.AppendCellsRequest) ArrayList(java.util.ArrayList)

Aggregations

AppendDimensionRequest (com.google.api.services.sheets.v4.model.AppendDimensionRequest)2 Request (com.google.api.services.sheets.v4.model.Request)2 ArrayList (java.util.ArrayList)2 AppendCellsRequest (com.google.api.services.sheets.v4.model.AppendCellsRequest)1 BatchUpdateSpreadsheetRequest (com.google.api.services.sheets.v4.model.BatchUpdateSpreadsheetRequest)1 CellData (com.google.refine.exporters.TabularSerializer.CellData)1 Test (org.testng.annotations.Test)1