I'm creating an excel file with many tabs. Each tab has a table and, manually, is very easy to create a graph from it. The tables contain the cell range and headings needed for the graphs, which varies from one to another. I've been searching to do this programmatically and found nothing. Do I have to create it from scratch or is there a simpler way of creating a graph form a table?
Thanks for your help
Additional info:
I'm not saying that the graphs cannot be create using the tables but I was looking for a way where the information from the table could be used for the graph. Anyway, I've realised that the tables are the same throughout the sheets.
Code from the method that generates the tabs and adds the tables
...
XSSFSheet sheet = workbook.createSheet(kind);
addTable(sheet, years, count++);
XSSFRow row;
XSSFCell cell;
for (String var : yearMapSorted.keySet()) {
List<Double> weights = yearMap.get(var);
row = sheet.createRow(rowNum++);
cell = row.createCell(0);
cell.setCellType(CellType.NUMERIC);
cell.setCellValue(weights.get(FIRST_YEAR));
row.createCell(1).setCellValue(weights.get(SECOND_YEAR));
row.createCell(2).setCellValue(var);
}
// add formula to calculate the sum of the columns
addTotalColumns(sheet);
addCalculatedColumns(sheet);
...
Method that adds the table
private void addTable(XSSFSheet sheet, List<Integer> years, Long count) {
String tableName = "Table_" + count;
XSSFRow row = sheet.createRow(0);
row.createCell(2).setCellValue("Variety");
row.createCell(3).setCellValue(years.get(FIRST_YEAR).toString());
row.createCell(4).setCellValue(years.get(SECOND_YEAR).toString());
XSSFTable table = sheet.createTable();
CTTable cttable = table.getCTTable();
cttable.setDisplayName(tableName);
cttable.setId(count);
cttable.setName(tableName);
cttable.setRef("C1:E11");
cttable.setTotalsRowShown(false);
CTTableStyleInfo styleInfo = cttable.addNewTableStyleInfo();
styleInfo.setName("TableStyleMedium2");
styleInfo.setShowColumnStripes(false);
styleInfo.setShowRowStripes(true);
CTTableColumns columns = cttable.addNewTableColumns();
columns.setCount(3);
for (int i = 1; i <= 3; i++) {
CTTableColumn column = columns.addNewTableColumn();
column.setId(i);
column.setName("Column"+i);
}
}