private static void mergeCells(Element table,Sheet sheet) {
if(table==null||sheet==null){
return;
}
Elements trs = table.select("tr");
int mergedRegions = sheet.getNumMergedRegions();
for(int i=0;i<mergedRegions;i++){
CellRangeAddress rangeAddress = sheet.getMergedRegion(i);
if(rangeAddress!=null){
int startRow = rangeAddress.getFirstRow();
int startColumn = rangeAddress.getFirstColumn();
int rowspan = rangeAddress.getLastRow()-startRow+1;
int colspan = rangeAddress.getLastColumn()-startColumn+1;
if(startRow<trs.size()){
Element tr = trs.get(startRow);
Elements tds = tr.children();
if(startColumn<tds.size()){
Element td = tds.get(startColumn);
if(rowspan>1){
td.attr("rowspan",String.valueOf(rowspan));
}
if(colspan>1){
for(int j=0;j<rowspan;j++){
if(startRow+j<trs.size()){
Element spanTr = trs.get(startRow+j);
Elements spanTds = spanTr.children();
if(startColumn<spanTds.size()){
Element spanTd = spanTds.get(startColumn);
spanTd.attr("colspan",String.valueOf(colspan));
}
}
}
}