public void LoadDonationWorksheets() throws Exception {
    if (MyService == null) ConnectToSpreadsheets();

    String sheetName = Settings.FinancialsGoogleSpreadsheetName;
    URL metafeedUrl = new URL("https://spreadsheets.google.com/feeds/spreadsheets/private/full");
    System.out.println("Opening \"" + sheetName + "\" Google spreadsheet...");
    SpreadsheetQuery query2 = new SpreadsheetQuery(metafeedUrl);
    query2.setTitleQuery(sheetName);
    query2.setTitleExact(true);
    SpreadsheetFeed feed2 = MyService.query(query2, SpreadsheetFeed.class);
    List<SpreadsheetEntry> entries2 = feed2.getEntries();
    if (entries2.size() < 1)
      throw new Exception("Cannot access spreadsheet:" + Settings.FinancialsGoogleSpreadsheetName);
    MyFinancialsSheet = entries2.get(0);

    MyDonationSheetMap = new HashMap<String, DonationSheet>();
    MyDonationSheets = new Vector<DonationSheet>();
    MyCellFeedURLs = new Vector<URL>();
    List<WorksheetEntry> worksheets = MyFinancialsSheet.getWorksheets();

    for (int i = 0; i < worksheets.size(); i++) {
      String title = worksheets.get(i).getTitle().getPlainText();
      if (title.contains("Donations")) {
        DonationSheet sheet = new DonationSheet();
        sheet.worksheetEntry = worksheets.get(i);
        sheet.title = title;
        MyDonationSheetMap.put(title, sheet);
        MyDonationSheets.add(sheet);
      } else {
        MyDonationSheets.add(null);
      }
      MyCellFeedURLs.add(worksheets.get(i).getCellFeedUrl());
    }
  }
Esempio n. 2
0
  /**
   * Gets the SpreadsheetEntry for the first spreadsheet with that name retrieved in the feed.
   *
   * @param spreadsheet the name of the spreadsheet
   * @return the first SpreadsheetEntry in the returned feed, so latest spreadsheet with the
   *     specified name
   * @throws Exception if error is encountered, such as no spreadsheets with the name
   */
  public SpreadsheetEntry getSpreadsheet(String spreadsheet) throws Exception {

    SpreadsheetQuery spreadsheetQuery = new SpreadsheetQuery(factory.getSpreadsheetsFeedUrl());
    spreadsheetQuery.setTitleQuery(spreadsheet);
    SpreadsheetFeed spreadsheetFeed = service.query(spreadsheetQuery, SpreadsheetFeed.class);
    List<SpreadsheetEntry> spreadsheets = spreadsheetFeed.getEntries();
    if (spreadsheets.isEmpty()) {
      throw new Exception("No spreadsheets with that name");
    }

    return spreadsheets.get(0);
  }
  public void LoadDonorWorksheet() throws Exception {
    if (MyService == null) ConnectToSpreadsheets();

    String sheetName = Settings.DonorsGoogleSpreadsheetName;
    URL metafeedUrl = new URL("https://spreadsheets.google.com/feeds/spreadsheets/private/full");
    System.out.println("Opening \"" + sheetName + "\" Google spreadsheet...");
    SpreadsheetQuery query1 = new SpreadsheetQuery(metafeedUrl);
    query1.setTitleQuery("Huruma House Donors");
    query1.setTitleExact(true);
    SpreadsheetFeed feed1 = MyService.query(query1, SpreadsheetFeed.class);
    List<SpreadsheetEntry> entries1 = feed1.getEntries();
    if (entries1.size() < 1)
      throw new Exception("Cannot access spreadsheet:" + Settings.DonorsGoogleSpreadsheetName);
    MyDonorsSheet = entries1.get(0);
  }