All Downloads are FREE. Search and download functionalities are using the official Maven repository.

cn.mapway.document.helper.html.HtmlTable Maven / Gradle / Ivy

There is a newer version: 3.20.0
Show newest version
package cn.mapway.document.helper.html;

import org.nutz.lang.Strings;

import java.util.ArrayList;

public abstract class HtmlTable {

    ArrayList> table;

    public HtmlTable() {
        table = new ArrayList<>();
    }

    protected void setCellAttr(int row, int col, int rowspan, int colspan, String text, String css) {
        Cell cell = table.get(row).get(col);
        cell.colspan = colspan;
        cell.rowspan = rowspan;
        cell.text = text;
        if (!Strings.isBlank(css)) {
            cell.css = css;
        }
    }

    protected void initTable(int row, int col) {
        table = new ArrayList<>();
        for (int i = 0; i < row + 1; i++) {
            ArrayList rows = new ArrayList<>(col);
            for (int j = 0; j < col; j++) {
                rows.add(new Cell());
            }
            table.add(rows);
        }
    }

    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append("");
        for (int i = 0; i < table.size(); i++) {
            ArrayList row = table.get(i);

            sb.append("");

            for (int j = 0; j < row.size(); j++) {
                Cell cell = row.get(j);
                if (j < getLevel()) {
                    if (cell.text != null) {
                        String style = findStyle(cell.css);

                        sb.append("");
                    }
                } else {
                    if (cell.text != null) {
                        String style = findStyle(cell.css);
                        sb.append("");
                    }
                }
            }

            sb.append("");

        }
        sb.append("
").append(cell.text).append("").append(cell.text).append("
"); return sb.toString(); } /** * 获取目录的列数 * * @return */ public abstract int getLevel(); private String findStyle(String css) { if (Strings.isBlank(css)) { return ""; } else { return "class=\"" + css + "\""; } } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy