package com.zd.laboratory.utils.word;

import com.deepoove.poi.data.RowRenderData;
import com.deepoove.poi.policy.DynamicTableRenderPolicy;
import com.deepoove.poi.policy.TableRenderPolicy;
import org.apache.poi.xwpf.usermodel.XWPFTable;
import org.apache.poi.xwpf.usermodel.XWPFTableRow;

import java.util.List;

public class Word2DetailTablePolicy extends DynamicTableRenderPolicy {
    int startRow = 1;
    int column = 3;

    @Override
    public void render(XWPFTable table, Object o) throws Exception {
        if (null == o) {
            return;
        }
        WordPolicy wordPolicy = (WordPolicy) o;

        List<RowRenderData> details = wordPolicy.getLabors();
        if (null != details) {
            table.removeRow(startRow);
            // 循环插入行
            for (int i = 0; i < details.size(); i++) {
                XWPFTableRow insertNewTableRow = table.insertNewTableRow(startRow);
                for (int j = 0; j < 4; j++) {
                    insertNewTableRow.createCell();
                }

                // 合并单元格
//                TableTools.mergeCellsHorizonal(table, goodsStartRow, 0, 3);
                // 单行渲染
                TableRenderPolicy.Helper.renderRow(table.getRow(startRow), details.get(i));
            }
        }
    }

}
