public List<WorksheetEntry> copyDocument(
      DocumentListEntry documentListEntry,
      String newDocumentTitle,
      DocumentListEntry destinationFolderEntry)
      throws IOException, ServiceException {

    documentListEntry.setTitle(new PlainTextConstruct(newDocumentTitle));

    URL url = new URL("https://docs.google.com/feeds/default/private/full/");

    DocumentListEntry newDoc = docsService.insert(url, documentListEntry);

    String destFolder = ((MediaContent) destinationFolderEntry.getContent()).getUri();
    URL newUrl = new URL(destFolder);

    // Convert DocumentListEntry to SpreadsheetEntry
    DocumentListEntry newDocumentListEntry = docsService.insert(newUrl, newDoc);
    String spreadsheetURL =
        "https://spreadsheets.google.com/feeds/spreadsheets/" + newDocumentListEntry.getDocId();

    SpreadsheetEntry spreadsheetEntry =
        spreadsheetService.getEntry(new URL(spreadsheetURL), SpreadsheetEntry.class);

    return spreadsheetEntry.getWorksheets();
  }
  public SpreadsheetEntry getSpreadsheetEntryFromDocumentListEntry(DocumentListEntry docListEntry)
      throws IOException, ServiceException {

    String spreadsheetURL =
        "https://spreadsheets.google.com/feeds/spreadsheets/" + docListEntry.getDocId();

    return spreadsheetService.getEntry(new URL(spreadsheetURL), SpreadsheetEntry.class);
  }
  public static void parseOneWorkSheet(
      SpreadsheetService service,
      Project project,
      ProjectMetadata metadata,
      final ImportingJob job,
      URL docURL,
      URL worksheetURL,
      int limit,
      JSONObject options,
      List<Exception> exceptions) {

    try {
      WorksheetEntry worksheetEntry = service.getEntry(worksheetURL, WorksheetEntry.class);
      String spreadsheetName = docURL.toExternalForm();
      try {
        SpreadsheetEntry spreadsheetEntry = service.getEntry(docURL, SpreadsheetEntry.class);
        spreadsheetName = spreadsheetEntry.getTitle().getPlainText();
      } catch (ServiceException e) { // RedirectRequiredException among others
        // fall back to just using the URL (better for traceability anyway?)
      }

      String fileSource = spreadsheetName + " # " + worksheetEntry.getTitle().getPlainText();

      setProgress(job, fileSource, 0);
      TabularImportingParserBase.readTable(
          project,
          metadata,
          job,
          new WorksheetBatchRowReader(job, fileSource, service, worksheetEntry, 20),
          fileSource,
          limit,
          options,
          exceptions);
      setProgress(job, fileSource, 100);
    } catch (IOException e) {
      e.printStackTrace();
      exceptions.add(e);
    } catch (ServiceException e) {
      e.printStackTrace();
      exceptions.add(e);
    }
  }
Exemple #4
0
  /**
   * Returns a CellEntry with batch id and operation type that will tell the server to update the
   * specified cell with the given value. The entry is fetched from the server in order to get the
   * current edit link (for optimistic concurrency).
   *
   * @param row the row number of the cell to operate on
   * @param col the column number of the cell to operate on
   * @param value the value to set in case of an update the cell to operate on
   * @throws ServiceException when the request causes an error in the Google Spreadsheets service.
   * @throws IOException when an error occurs in communication with the Google Spreadsheets service.
   */
  private CellEntry createUpdateOperation(int row, int col, String value)
      throws ServiceException, IOException {
    String batchId = "R" + row + "C" + col;
    URL entryUrl = new URL(cellFeedUrl.toString() + "/" + batchId);
    CellEntry entry = service.getEntry(entryUrl, CellEntry.class);
    entry.changeInputValueLocal(value);
    BatchUtils.setBatchId(entry, batchId);
    BatchUtils.setBatchOperationType(entry, BatchOperationType.UPDATE);

    return entry;
  }