final String msg = String.format( "column [%d] is null. Will be ignored ", col );
log.warn( msg);
continue;
}
final CTXmlColumnPr colPr = tableCol.getXmlColumnPr();
assert colPr!=null;
if( colPr==null ) {
final String msg = String.format( "column pr for column [%d] is null. Will be ignored", col );
log.warn( msg);
continue;
}
final String xpath = colPr.getXpath();
assert xpath!=null;
if( xpath==null ) {
final String msg = String.format( "xpath attribute for column [%d] is null. Will be ignored", col );
log.warn( msg);
continue;
}
// PERFORM AN XPATH QUERY
final String xpathQuery = String.format( "$this%s", xpath );
XmlObject[] bindValues = xmlSourceObject.selectPath(xpathQuery);
assert bindValues!=null;
assert bindValues.length > 0;
if( bindValues==null ) {
final String msg = String.format( "no values match for xpath query [%s] for column [%d]. Column will be ignored", xpathQuery, col );
log.warn( msg);
continue;
}
// FILL SHEET
int rowNum = endCell.getRow();
int cellType = -1;
XSSFCellStyle cellStyle = null;
for( XmlObject value : bindValues ) {
XSSFRow row = sheet.getRow(rowNum);
if( row == null ) {
row = sheet.createRow(rowNum);
}
assert row!=null;
if( row==null ) {
final String msg = String.format( "detected problem to get/create row [%d]. Will be ignored!", rowNum );
log.warn( msg);
continue;
}
final int cellNum = startCell.getCol() + col;
XSSFCell cell = row.getCell( cellNum, Row.CREATE_NULL_AS_BLANK );
assert cell!=null;
if( cell==null ) {
final String msg = String.format( "detected problem to get cell [%d,%d]. Will be ignored!", rowNum, cellNum );
log.warn( msg);
continue;
}
if( cellType!=-1 && cellStyle!=null ) {
cell.setCellStyle(cellStyle);
cell.setCellType(cellType);
}
else {
cellStyle = cell.getCellStyle();
cellType = cell.getCellType();
}
setCellValue( cell, value, colPr.getXmlDataType() );
//cell.setCellValue( ((SimpleValue)value).getStringValue() );
++rowNum;
}
}