文檔首頁(yè)>>FastReport中文文檔>>示例 3.打印月份名稱
示例 3.打印月份名稱
在上一個(gè)示例中,矩陣中打印了月份的數(shù)字。出現(xiàn)這種情況是因?yàn)?"Month "數(shù)據(jù)列包含月份的編號(hào),而不是名稱。要打印月份名稱,請(qǐng)執(zhí)行以下操作:
- 選擇打印月份編號(hào)的單元格。在本例中,該單元格的名稱為 "Cell8";
- 在 "BeforePrint "窗口中按下按鈕并雙擊 "BeforePrint "事件;
- FastReport 將在報(bào)表腳本中添加一個(gè)空的事件處理程序。請(qǐng)編寫(xiě)以下代碼:
private void Cell8_BeforePrint(object sender, EventArgs e) { string[] month Names = newstring[] { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" }; // Cell8 is a cell that prints the month number. // Cell8.Value is a value printed in the cell (i.e. the month number). // This value is of System.Object type, so we need to cast it to int Cell8.Text = monthNames[(int)Cell8.Value - 1]; }
運(yùn)行報(bào)告后,結(jié)果如下: