Skip to content

Instantly share code, notes, and snippets.

@ngocongcan
Created November 13, 2017 16:28
Show Gist options
  • Save ngocongcan/6dc8e8e5bcd5e62d19e21efdbf54fe70 to your computer and use it in GitHub Desktop.
Save ngocongcan/6dc8e8e5bcd5e62d19e21efdbf54fe70 to your computer and use it in GitHub Desktop.
Get table content in Email
/**
* Get table content in Email
*/
public String[][] getTableContentInEmail(String subjectEmail, int tableNumOrder) throws Exception {
String emailContent = "";
// get table content
// try {
// get table content
emailContent = getMessages(subjectEmail);
Document doc = Jsoup.parse(emailContent);
Element table = doc.select("table").get(tableNumOrder);
Elements rows = table.select("tr");
int numberOfRow = rows.size();
String[][] tableContent = new String[numberOfRow][];
for (int i = 0; i < rows.size(); i++) {
Element row = rows.get(i);
Elements cols = row.select("td");
if (cols.size() == 0) {
cols = row.select("th");
}
int numberOfColumn = rows.size();
tableContent[i] = new String[numberOfColumn];
for (int j = 0; j < cols.size(); j++) {
System.out.print("["+i+"]["+j+"]= ");
System.out.println(cols.get(j).text());
tableContent[i][j] = cols.get(j).text();
}
}
// }
// catch (Exception e) {
// System.out.println("Unable to get Email Content");
// }
return tableContent;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment