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 55 56 57 58 59 60 61 62
| package test;
import org.eclipse.birt.report.engine.api.script.IReportContext;
import org.eclipse.birt.report.engine.api.script.element.ITable;
import org.eclipse.birt.report.engine.api.script.eventadapter.TableEventAdapter;
import org.eclipse.birt.report.engine.api.script.instance.ICellInstance;
import org.eclipse.birt.report.engine.api.script.instance.IRowInstance;
import org.eclipse.birt.report.engine.api.script.instance.ITableInstance;
import org.eclipse.birt.report.model.api.CellHandle;
import org.eclipse.birt.report.model.api.DesignElementHandle;
import org.eclipse.birt.report.model.api.ModuleHandle;
import org.eclipse.birt.report.model.api.RowHandle;
import org.eclipse.birt.report.model.api.TableHandle;
public class TableEA extends TableEventAdapter {
int table_size;
/* Table onPrepare event */
public void onPrepare(ITable table, IReportContext reportContext) {
try {
//table.getStyle().setBackgroundColor("green");
table_size = table.getColumnCount();
if( reportContext.getOutputFormat().equalsIgnoreCase("pdf") ){
DesignElementHandle designHandle = reportContext.getReportRunnable().getDesignHandle();
ModuleHandle moduleHandle = designHandle.getModuleHandle();
table.setName("myTable");
TableHandle tableHandle = (TableHandle) moduleHandle.findElement(table.getName());
// table header
RowHandle tableheader = (RowHandle) tableHandle.getHeader( ).get(0);
for( int i=0; i < table.getColumnCount()-1; i++){
CellHandle cell = (CellHandle) tableheader.getCells( ).get(i);
cell.getContent().get(0).getPrivateStyle().getFontSize().setStringValue("6px");
}
// table detail
RowHandle tabledetail = (RowHandle) tableHandle.getDetail( ).get(0);
for( int i=0; i < table.getColumnCount()-1; i++){
CellHandle cell = (CellHandle) tabledetail.getCells( ).get(i);
cell.getContent().get(0).getPrivateStyle().getFontSize().setStringValue("6px");
}
}
}
catch ( Exception e ) {
e.printStackTrace( );
}
}
/* Table onRender event */
public void onRender(ITableInstance table, IReportContext reportContext) { }
} |
Partager