Search in sources :

Example 6 with Table

use of com.github.liaochong.myexcel.core.parser.Table in project myexcel by liaochong.

the class HtmlToExcelFactory method buildTablesWithMultiSheet.

/**
 * MultiSheet 策略
 *
 * @param tables tables
 */
private void buildTablesWithMultiSheet(List<Table> tables) {
    for (int i = 0, size = tables.size(); i < size; i++) {
        Table table = tables.get(i);
        String sheetName = this.getRealSheetName(table.caption);
        Sheet sheet = workbook.getSheet(sheetName);
        if (sheet == null) {
            sheet = workbook.createSheet(sheetName);
        }
        boolean hasTd = table.trList.stream().map(tr -> tr.tdList).anyMatch(list -> !list.isEmpty());
        if (!hasTd) {
            continue;
        }
        // 设置单元格样式
        this.setTdOfTable(table, sheet);
        this.freezePane(i, sheet);
        // 移除table
        tables.set(i, null);
    }
}
Also used : Table(com.github.liaochong.myexcel.core.parser.Table) Sheet(org.apache.poi.ss.usermodel.Sheet) NoSuchFileException(java.nio.file.NoSuchFileException) Logger(org.slf4j.Logger) Tr(com.github.liaochong.myexcel.core.parser.Tr) IOException(java.io.IOException) File(java.io.File) XSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook) Objects(java.util.Objects) SheetStrategy(com.github.liaochong.myexcel.core.strategy.SheetStrategy) Workbook(org.apache.poi.ss.usermodel.Workbook) List(java.util.List) StringUtil(com.github.liaochong.myexcel.utils.StringUtil) Map(java.util.Map) WidthStrategy(com.github.liaochong.myexcel.core.strategy.WidthStrategy) HtmlTableParser(com.github.liaochong.myexcel.core.parser.HtmlTableParser) ParseConfig(com.github.liaochong.myexcel.core.parser.ParseConfig) Table(com.github.liaochong.myexcel.core.parser.Table) Sheet(org.apache.poi.ss.usermodel.Sheet)

Aggregations

Table (com.github.liaochong.myexcel.core.parser.Table)6 ParseConfig (com.github.liaochong.myexcel.core.parser.ParseConfig)4 Tr (com.github.liaochong.myexcel.core.parser.Tr)4 IOException (java.io.IOException)4 HtmlTableParser (com.github.liaochong.myexcel.core.parser.HtmlTableParser)3 SheetStrategy (com.github.liaochong.myexcel.core.strategy.SheetStrategy)3 WidthStrategy (com.github.liaochong.myexcel.core.strategy.WidthStrategy)3 StringUtil (com.github.liaochong.myexcel.utils.StringUtil)3 File (java.io.File)3 NoSuchFileException (java.nio.file.NoSuchFileException)3 List (java.util.List)3 Map (java.util.Map)3 Objects (java.util.Objects)3 Sheet (org.apache.poi.ss.usermodel.Sheet)3 Workbook (org.apache.poi.ss.usermodel.Workbook)3 XSSFWorkbook (org.apache.poi.xssf.usermodel.XSSFWorkbook)3 Logger (org.slf4j.Logger)3 ClassFieldContainer (com.github.liaochong.myexcel.core.reflect.ClassFieldContainer)1 Consumer (java.util.function.Consumer)1