P15GEN2\59518
2025-10-10 9f6890646993d16260d4201d613c092132856127
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
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;
    }
}