2 回答

TA貢獻1856條經驗 獲得超17個贊
如果我正確理解你的問題,你想為表格詳細信息行中的所有單元格添加突出顯示規則。不幸的是,我認為在 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 個單元格的驢子工作還要多!
我曾經做過的基本上是這樣的(在onFactoryreport項目的情況下):
// 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

TA貢獻1801條經驗 獲得超16個贊
轉到要設置格式的單元格(也適用于行或列等元素),在“屬性編輯器”上轉到“突出顯示”并單擊“添加...”。您將看到一個對話框,您可以在其中輸入突出顯示的條件以及在條件為真時要在元素上應用的樣式。
添加回答
舉報