帆软帮助文档代码合集。
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

46 lines
1.6 KiB

package com.fr.io;
import com.fr.io.importer.ExcelReportImporter;
import com.fr.main.TemplateWorkBook;
import com.fr.main.impl.WorkBook;
import com.fr.report.cell.CellElement;
import com.fr.report.cell.cellattr.CellPageAttr;
import com.fr.report.elementcase.AbstractElementCase;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.util.Iterator;
public class ExcelToCptpage {
public static void main(String[] args) throws Exception {
File excelFile = new File("D:\\API.xls"); // 获取EXCEL文件
FileInputStream a = new FileInputStream(excelFile);
TemplateWorkBook tpl = new ExcelReportImporter().generateWorkBookByStream(a);
Iterator it = tpl.getReport(0).iteratorOfElementCase();
while (it.hasNext()) {
AbstractElementCase ec = (AbstractElementCase) it.next();
Iterator cellIt = ec.cellIterator();
while (cellIt.hasNext()) {
CellElement obj = (CellElement) cellIt.next();
if (matchCell(obj, Integer.parseInt("1"), Integer.parseInt("0"))) {
CellPageAttr cpa = new CellPageAttr();
cpa.setPageAfterRow(true);
obj.setCellPageAttr(cpa);
}
}
}
OutputStream outputStream = new FileOutputStream(new File("D:\\abc.cpt")); // 转换成cpt模板
((WorkBook) tpl).export(outputStream);
}
private static boolean matchCell(CellElement cell, int row, int col) {
if (cell.getRow() == row && cell.getColumn() == col)
return true;
return false;
}
}