package foundation.io.file.ppt;
|
|
import java.util.List;
|
import java.util.Map;
|
|
import org.apache.poi.xslf.usermodel.*;
|
|
import foundation.io.engine.IShapeWriter;
|
|
public class TableWriter extends IShapeWriter {
|
private String[] headers;
|
private String[] fields;
|
private XSLFTable tableShape;
|
|
public TableWriter(XSLFTable shape) {
|
super(shape);
|
this.tableShape = shape;
|
|
//parse tables (header, mapping fields
|
int columnLength = shape.getNumberOfColumns();
|
|
for (int columnIndex = 0; columnIndex < columnLength; columnIndex++){
|
XSLFTableCell titleCell = shape.getCell(0, columnIndex);
|
XSLFTableCell fieldCell = shape.getCell(1, columnIndex);
|
headers[columnIndex] = titleCell.getText();
|
String fieldName = fieldCell.getText();
|
fieldName = fieldName.substring(1, fieldName.length() - 1);
|
fields[columnIndex] = fieldName;
|
}
|
}
|
|
public void writeData(XSLFSlide slide, Map<String, Object> data) throws Exception{
|
tableShape.removeRow(1);
|
// String shapeName = shape.getShapeName();
|
// Object entitySet = data.get(shapeName);
|
String[][] entitySet = {
|
{"东1区", "500", "480"},
|
{"东2区", "300", "320"},
|
{"北区", "200", "190"}
|
};
|
|
for (int i = 1; i < entitySet.length; i++) {
|
XSLFTableRow row = tableShape.addRow();
|
for (int j = 0; j < entitySet[i].length; j++) {
|
XSLFTableCell cell = row.addCell();
|
cell.setText(entitySet[i][j]);
|
}
|
}
|
}
|
|
public XSLFTable getShape() {
|
return tableShape;
|
}
|
}
|