try{
htmlBuffer = "<html>" + htmlBuffer + "</html>";
Parser parser = new Parser();
parser.setInputHTML(htmlBuffer);
NodeList nodelist = parser.parse(null);
NodeList tableList = nodelist.extractAllNodesThatMatch(new TagNameFilter("TABLE"), true);
NodeList headList = tableList.extractAllNodesThatMatch(new TagNameFilter("THEAD"), true);
NodeList footList = tableList.extractAllNodesThatMatch(new TagNameFilter("TFOOT"), true);
NodeList rowList = tableList.extractAllNodesThatMatch(new TagNameFilter("TR"), true);
//Create a ParserUtils var
ParserUtils pu = new ParserUtils();
//Set rowCount to size of rowList
rowCount = rowList.size();
HSSFFont boldFont = wb.createFont();
boldFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
HSSFCellStyle boldStyle = wb.createCellStyle();
boldStyle.setFont(boldFont);
boldStyle.setWrapText(true);
//Loop through excel 'Rows'
for ( int i = 0; i < rowList.size(); i++ ) {
HSSFRow row;
String htmlRow = rowList.elementAt(i).toHtml().trim();
String[] splitHtmlRow;
List<String> elements = new ArrayList<String>();
if(i == 0 && headList.size() == 1){
row = sheet.createRow((short) i);
htmlRow = htmlRow.replace("<th></th>","<th> </th>");
htmlRow = htmlRow.replace("<TH></TH>","<th> </th>");
htmlRow = htmlRow.replace("</span>", " </span>");
elements.add("tr");
elements.add("th");
if (htmlRow.indexOf("<a href=") > -1) {
elements.add("a");
}
if (htmlRow.indexOf("<span ") > -1) {
elements.add("span");
}
} else if(i == 1 && footList.size() == 1){
row = sheet.createRow((short) rowList.size() - 1);
htmlRow = pu.trimTags(htmlRow, new String[]{"span"},false,false);
htmlRow = htmlRow.replace("<td></td>","<td> </td>");
htmlRow = htmlRow.replace("<TD></TD>","<td> </td>");
elements.add("tr");
elements.add("td");