Fede MG 的回答是正确的。
如果我正确理解了您的问题,您希望向表格详细信息行中的所有 单元格添加突出显示规则。不幸的是,我认为在 BIRT 中实现这一点有点麻烦。
我假设你的桌子有例如像 COL_VALUE_1, ..., COL_VALUE_9 这样的绑定用于单元格值和 COL_TITLE_1, ..., COL_TITLE_9 用于列标题。
此外,我假设有一些在 BIRT 中使用 Javascript 的经验。
我这样做的方式是这样的:
为每个细节单元格创建一个onCreate 事件脚本,代码如下:
highlightDetailCell(this, row, 1);
... 其中 1 是列号。例如。这是第一列的代码,对于第二列,我将 1 替换为 2,依此类推。您可以通过复制和粘贴快速完成此操作。
接下来我在报告的onInitialize 脚本内的函数中实现逻辑,如下所示:
function highlightDetailCell(item, row, colnum) {
var colTitle = row["COL_TITLE_" + colnum];
var colValue = row["COL_VALUE_" + colnum];
var highlight = use_your_logic_to_decide(colTitle, colValue);
if (highlight) {
item.get_Style().backgroundColor = "yellow";
}
}
这是基本思想。如果您想将脚本添加到许多单元格中,手动执行此操作可能需要做很多工作。事实上,可以使用脚本将调用附加到 highlightDetailCell 函数(当然,这是 BIRT :-)。您应该阅读文档并修改 Design Engine API(简称 DE API)。
但请注意,编写和调试这样的脚本可能比在 1200 个单元格中添加和编辑单行代码的工作量更大!
我曾经做的基本上是这样的(在报告项的onFactory事件中):
// This code is a simplified version that modifies just the first cell,
// However it should point you into the right direction.
// Some preparation
importPackage(Packages.org.eclipse.birt.report.model.api);
var myconfig = reportContext.getReportRunnable().getReportEngine().getConfig();
var de = DataEngine.newDataEngine( myconfig, null );
var elementFactory = reportContext.getDesignHandle().getElementFactory();
// Find the item you want to modify (in my case, a "Grid Item").
// Note that for tables, the structure is probably a bit different.
// E.G. tables have header, detail and footer rows,
// while grids just have rows.
var containerGrid = reportContext.getDesignHandle().findElement("Layout MATRIX");
// Get the first row
var row0 = containerGrid.getRows().get(0);
// Do something with the first cell (:
var cell = row0.getCells().get(0).getContent();
cell.setStringProperty("paddingTop", "1pt");
cell.setStringProperty("paddingLeft", "1pt");
cell.setStringProperty("paddingRight", "1pt");
cell.setStringProperty("paddingBottom", "1pt");
cell.setStringProperty("borderBottomColor", "#000000");
cell.setStringProperty("borderBottomStyle", "solid");
cell.setStringProperty("borderBottomWidth", "thin");
cell.setStringProperty("borderTopColor", "#000000");
cell.setStringProperty("borderTopStyle", "solid");
cell.setStringProperty("borderTopWidth", "thin");
cell.setStringProperty("borderLeftColor", "#000000");
cell.setStringProperty("borderLeftStyle", "solid");
cell.setStringProperty("borderLeftWidth", "thin");
cell.setStringProperty("borderRightColor", "#000000");
cell.setStringProperty("borderRightStyle", "solid");
cell.setStringProperty("borderRightWidth", "thin");
// When you're finished:
de.shutdown( );
如果您必须处理合并的单元格,事情会更加复杂。
您甚至可以向单元格添加内容(我以这种方式动态创建了一个完整的矩阵)。
脚本并不完全符合您的要求(将脚本添加到每个单元格),但我将其留作练习...
保存动态修改的报表设计以在设计器中打开以查看结果也很有帮助:
reportContext.getDesignHandle().saveAs("c:/temp/modified_report.rptdesign");
HTH