private void writeData(HSSFSheet sheet) {
for (int i = 0; i < boltData.size(); i++) {
HSSFRow row = sheet.createRow(rowCount);
rowCount++;
BoltDto boltDto = boltData.get(i);
for (int j = 0; j < **${noOfattributesInMyEntity}**; j++) {
HSSFCell cell = row.createCell(j);
cell.setCellValue(new HSSFRichTextString(
(**boltDto.getXyz()**).trim()));
}
}
}
I want something like above.
I am creating an excel sheet where in the number of rows corresponds to the number of objects in the List. and the number of columns corresponds to the number of attributes/properties in the DTO.
As my DTO has over 40 attributes, I don’t want to write explicitly. Is there any work around?
You can use reflection or (better) the commons-beanutils API (or anything providing similar functionality). The simplest usage would look like this: