PeopleSoft-报表示例(WriteExcelEx_2010类和ReportDefinition类)

两个jar包的位置

jar包1:ibm_excel_handle.jar

调用路径:com.cust.common.poi.ReportDefinition

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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
/**********************************************
描述:证书信息报表
作者:SIE_GEK
日期:2021-11-18
操作:新增
*************************************************/

Declare Function GetDirSeparator PeopleCode PSXPFUNCLIB.FUNCLIB FieldFormula;

Local JavaObject &reportDefn, &reportRow;
Local string &sDirSep, &strQryName, &strRptLabel, &strTreeNode, &strLevel, &strRptWidthLen, &strLabel;
Local number &i, &j, &n, &rownumber, &strProcessInstance, &sheets;
Local array of string &rp_title_array;
Local SQL &sqlGetBenLedgerInfoDetail, &sqlGetSubDept;
Local string &strSetid, &strEmplidQr, &strDeptid, &strCompany, &strHrStatus, &strEffdt, &strSubDept, &strLanguagecd, &strOprid, &strDirectlyFlag;
Local string &strLister, &strRptPersonNm, &strTabulationdate, &strCompanys, &strCompanyName, &strDirectlyFlag1, &strDepartment;
Local string &strDepartmentName, &strIncludesubdept, &strEmplname, &strName1, &strHrStatus11, &strHrstatus1, &strEffdt1;


REM 获取页面参数;
&strSetid = C_CERT_AET.SETID.Value;
&strEmplidQr = C_CERT_AET.EMPLID.Value;
&strDeptid = C_CERT_AET.DEPTID.Value;
&strCompany = C_CERT_AET.COMPANY.Value;
&strHrStatus = C_CERT_AET.HR_STATUS.Value;
&strEffdt = C_CERT_AET.C_EFFDT.Value;
&strSubDept = C_CERT_AET.C_INCLUDE_SUBDEPT.Value;
&strLanguagecd = C_CERT_AET.C_LANGUAGE_DESCR.Value;
&strOprid = C_CERT_AET.OPRID.Value;
&strProcessInstance = C_CERT_AET.PROCESS_INSTANCE.Value;

rem 拼接多语言报表表头;
Local array of string &arrRptLabel;

&arrRptLabel = CreateArray("EMPLID", "NAME", "DESCR2", "DESCR1", "C_CERT_NAME", "C_CERT_UNIT", "C_CERT_GRADE", "C_BGN_DT", "C_END_DT", "DESCRLONG");
For &n = 1 To &arrRptLabel.Len
SQLExec("SELECT DESCRLONG FROM PS_C_REP_AE_TBL WHERE LANGUAGE_CD = :1 AND C_REP_AE_ID=:2", &strLanguagecd, &arrRptLabel [&n], &strLabel);
&strRptLabel = &strRptLabel | "," | &strLabel;
End-For;

&strRptLabel = Substring(&strRptLabel, 2, Len(&strRptLabel));

rem 报表名称;
SQLExec("SELECT DESCRLONG FROM PS_C_REP_AE_TBL WHERE LANGUAGE_CD = :1 AND C_REP_AE_ID=:2", &strLanguagecd, "C_CERT_AE", &strQryName);
rem 字段长度;
&strRptWidthLen = "4000,4000,4000,4000,4000,4000,4000,4000,4000,4000,4000,4000,4000,4000,4000,4000,4000,4000";
REM 报表数据表头;
Local string &repSql = "SELECT DESCRLONG FROM PS_C_REP_AE_TBL WHERE LANGUAGE_CD = :1 AND C_REP_AE_ID=:2";

try
&reportDefn = CreateJavaObject("com.cust.common.poi.ReportDefinition");
&sDirSep = GetDirSeparator();
&reportDefn.AddSheet(&strQryName);

&reportDefn.addHeader(&strQryName);
&reportDefn.mergeCells(0, 0, 0, 1);

rem 设置表头信息;
rem 制表人;
&reportRow = CreateJavaObject("com.cust.common.poi.ReportRow");
SQLExec(&repSql, &strLanguagecd, "LISTER", &strLister);
&reportRow.addString(&strLister | ":");
SQLExec("SELECT NAME FROM PS_PERSONAL_DATA WHERE EMPLID = :1", %EmployeeId, &strRptPersonNm);
&strRptPersonNm = %OperatorId | " " | &strRptPersonNm;
&reportRow.addString(&strRptPersonNm);
&reportDefn.addRow(&reportRow);

rem 制表日期;
&reportRow = CreateJavaObject("com.cust.common.poi.ReportRow");
SQLExec(&repSql, &strLanguagecd, "TABULATION_DATE", &strTabulationdate);
&reportRow.addString(&strTabulationdate | ":");
&reportRow.addString(String(%Date));
&reportDefn.addRow(&reportRow);

rem 公司;
If All(&strCompany) Then
&reportRow = CreateJavaObject("com.cust.common.poi.ReportRow");
SQLExec(&repSql, &strLanguagecd, "COMPANY", &strCompanys);
&reportRow.addString(&strCompanys | ":");
SQLExec("SELECT (C_UTIL_PKG.GET_DESCR_COMPANY(:1, SYSDATE,'" | &strLanguagecd | "')) COMPANY FROM DUAL;", &strCompany, &strCompanyName);
&reportRow.addString(&strCompany | " " | &strCompanyName);
&reportDefn.addRow(&reportRow);
End-If;

REM 如果部门参数为空,部门id默认根节点 10000000,默认包含子部门;
If None(&strDeptid) Then
&strDeptid = "10000000";
&strSubDept = "Y";
End-If;

rem 部门;
If All(&strDeptid) Then
&reportRow = CreateJavaObject("com.cust.common.poi.ReportRow");
SQLExec(&repSql, &strLanguagecd, "DEPARTMENT", &strDepartment);
&reportRow.addString(&strDepartment | ":");
SQLExec("SELECT (C_UTIL_PKG.GET_DESCR_DEPT_BY_SETID('" | &strSetid | "', :1, SYSDATE, '" | &strLanguagecd | "')) DEPT FROM DUAL;", &strDeptid, &strDepartmentName);
&reportRow.addString(&strDeptid | " " | &strDepartmentName);
&reportDefn.addRow(&reportRow);
End-If;

rem 是否包含子部门;
If All(&strSubDept) Then
&reportRow = CreateJavaObject("com.cust.common.poi.ReportRow");
SQLExec(&repSql, &strLanguagecd, "INCLUDE_SUBDEPT", &strIncludesubdept);
&reportRow.addString(&strIncludesubdept | ":");
&reportRow.addString(&strSubDept);
&reportDefn.addRow(&reportRow);
End-If;

rem 员工;
If All(&strEmplidQr) Then
&reportRow = CreateJavaObject("com.cust.common.poi.ReportRow");
SQLExec(&repSql, &strLanguagecd, "EMPLNAME", &strEmplname);
&reportRow.addString(&strEmplname | ":");
SQLExec("SELECT (C_UTIL_PKG.GET_NAME_PERSONAL_DATA(:1, '" | &strLanguagecd | "')) NAME FROM DUAL;", &strEmplidQr, &strName1);
&reportRow.addString(&strEmplidQr | " " | &strName1);
&reportDefn.addRow(&reportRow);
End-If;

rem HR状态;
If All(&strHrStatus) Then
&reportRow = CreateJavaObject("com.cust.common.poi.ReportRow");
SQLExec(&repSql, &strLanguagecd, "HR_STATUS", &strHrStatus11);
&reportRow.addString(&strHrStatus11 | ":");
SQLExec("SELECT (C_UTIL_PKG.GET_DESCR_TRANSLATE('HR_STATUS',:1, SYSDATE, '" | &strLanguagecd | "')) HR_STATUS_DESCR FROM DUAL", &strHrStatus, &strHrstatus1);
&reportRow.addString(&strHrstatus1);
&reportDefn.addRow(&reportRow);
End-If;

&reportRow = CreateJavaObject("com.cust.common.poi.ReportRow");

rem 表头;
&rp_title_array = CreateArrayRept("", 0);
&rp_title_array = Split(&strRptLabel, ",");

For &i = 1 To &rp_title_array.Len
&reportRow.addHeaderCell(&rp_title_array [&i]);
End-For;
&reportDefn.addRow(&reportRow);

rem 获取部门ID;
If &strSubDept = "Y" Then
Local string &strGetSubDept = "";
&strGetSubDept = &strGetSubDept | "SELECT B.TREE_NODE, LEVEL AS LV ";
&strGetSubDept = &strGetSubDept | " FROM (SELECT A.SETID, A.TREE_NODE, A.PARENT_NODE_NAME ";
&strGetSubDept = &strGetSubDept | " FROM PSTREENODE A ";
&strGetSubDept = &strGetSubDept | " WHERE A.TREE_NAME = 'DEPT_SECURITY' ";
&strGetSubDept = &strGetSubDept | " AND A.SETCNTRLVALUE = ' ' ";
&strGetSubDept = &strGetSubDept | " AND A.EFFDT = (SELECT MAX(A_ED.EFFDT) ";
&strGetSubDept = &strGetSubDept | " FROM PSTREENODE A_ED ";
&strGetSubDept = &strGetSubDept | " WHERE A_ED.SETID = A.SETID ";
&strGetSubDept = &strGetSubDept | " AND A_ED.SETCNTRLVALUE = A.SETCNTRLVALUE";
&strGetSubDept = &strGetSubDept | " AND A_ED.TREE_NAME = A.TREE_NAME ";
&strGetSubDept = &strGetSubDept | " AND A_ED.EFFDT <= SYSDATE) ";
&strGetSubDept = &strGetSubDept | " AND A.SETID = '" | &strSetid | "') B ";
&strGetSubDept = &strGetSubDept | " START WITH B.TREE_NODE = :1 ";
&strGetSubDept = &strGetSubDept | " CONNECT BY PRIOR B.TREE_NODE = B.PARENT_NODE_NAME ";
&strGetSubDept = &strGetSubDept | " ORDER BY LV ";
Else
&strGetSubDept = &strGetSubDept | " SELECT :1,1 FROM DUAL ";
End-If;


rem 拼接sql;
Local string &sql = "";
&sql = &sql | "SELECT J.EMPLID, ";
&sql = &sql | " (C_UTIL_PKG.GET_NAME_PERSONAL_DATA(J.EMPLID,'" | &strLanguagecd | "')) NAME, ";
&sql = &sql | " (C_UTIL_PKG.GET_DESCR_POSN(J.POSITION_NBR,SYSDATE,'" | &strLanguagecd | "')) POST, ";
&sql = &sql | " (C_UTIL_PKG.GET_DESCR_DEPT_BY_SETID('" | &strSetid | "',J.DEPTID, SYSDATE,'" | &strLanguagecd | "')) DEPT, ";
&sql = &sql | " (C_UTIL_PKG.GET_DESCR_CERT_NAME(J.EMPLID,CE.C_SEQUENCE_NUM,'" | &strLanguagecd | "')) C_CERT_NAME, ";
&sql = &sql | " (C_UTIL_PKG.GET_DESCR_CERT_UNIT(J.EMPLID,CE.C_SEQUENCE_NUM,'" | &strLanguagecd | "')) C_CERT_UNIT, ";
&sql = &sql | " (C_UTIL_PKG.GET_DESCR_CERT_GRADE(J.EMPLID,CE.C_SEQUENCE_NUM,'" | &strLanguagecd | "')) C_CERT_GRADE, ";
&sql = &sql | " CE.C_BGN_DT, ";
&sql = &sql | " CE.C_END_DT, ";
&sql = &sql | " (C_UTIL_PKG.GET_DESCR_DESCRLONG(J.EMPLID,CE.C_SEQUENCE_NUM,'" | &strLanguagecd | "')) DESCRLONG ";
&sql = &sql | " FROM PS_JOB J ,PS_C_CERT_TBL CE ";
&sql = &sql | " WHERE CE.EMPLID = J.EMPLID AND J.EMPL_RCD = '0' ";
&sql = &sql | " AND J.EFFDT = (SELECT MAX(JOB_ED.EFFDT) ";
&sql = &sql | " FROM PS_JOB JOB_ED ";
&sql = &sql | " WHERE JOB_ED.EMPLID = J.EMPLID ";
&sql = &sql | " AND JOB_ED.EMPL_RCD = J.EMPL_RCD ";
&sql = &sql | " AND JOB_ED.EFFDT <= SYSDATE) ";
&sql = &sql | " AND J.EFFSEQ = (SELECT MAX(JOB_ES.EFFSEQ) ";
&sql = &sql | " FROM PS_JOB JOB_ES ";
&sql = &sql | " WHERE JOB_ES.EMPLID = J.EMPLID ";
&sql = &sql | " AND JOB_ES.EMPL_RCD = J.EMPL_RCD ";
&sql = &sql | " AND JOB_ES.EFFDT = J.EFFDT) ";
&sql = &sql | " AND J.DEPTID = :1 ";

If All(&strEmplidQr) Then
&sql = &sql | " AND J.EMPLID = '" | &strEmplidQr | "' ";
End-If;

If All(&strCompany) Then
&sql = &sql | " AND J.COMPANY = '" | &strCompany | "' ";
End-If;

If All(&strHrStatus) Then
&sql = &sql | " AND J.HR_STATUS = '" | &strHrStatus | "' ";
End-If;

If All(&strSetid) Then
&sql = &sql | " AND J.SETID_DEPT = '" | &strSetid | "' ";
End-If;

REM 安全性限制;
&sql = &sql | " AND EXISTS(SELECT 'X' FROM PS_C_DEPT_SEC_VW DS WHERE DS.OPRID = '" | &strOprid | "' AND DS.DEPTID = J.DEPTID)";

&sqlGetSubDept = CreateSQL(&strGetSubDept, &strDeptid);
While &sqlGetSubDept.Fetch(&strTreeNode, &strLevel);
Local array of any &result = CreateArrayAny();
&sqlGetBenLedgerInfoDetail = CreateSQL(&sql, &strTreeNode);
MessageBox(0, "", 0, 0, "&strTreeNode=" | &strTreeNode);
REM 循环查出的结果输出的exec表;
While &sqlGetBenLedgerInfoDetail.Fetch(&result);
MessageBox(0, "", 0, 0, "&result[1]=" | &result [1]);
If &result.Len <> 0 Then
&reportRow = CreateJavaObject("com.cust.common.poi.ReportRow");

For &i = 1 To &result.Len
&reportRow.addString(String(&result [&i]));
End-For;

&reportDefn.addRow(&reportRow);
End-If;
End-While;
End-While;
&sqlGetSubDept.Close();

&reportDefn.prepareExcel();

rem 列宽;
Local array of string &arrRptWidthlen = CreateArrayRept("", 0);
&arrRptWidthlen = Split(&strRptWidthLen, ",");
For &j = 1 To &arrRptWidthlen.Len
Local number &wt = Value(&arrRptWidthlen [&j]);
&reportDefn.setColumnWidth(&j - 1, &wt);
End-For;

/*报表下载*/
Local string &FilePath;
&FilePath = %FilePath | "/" | &strQryName | "_" | &strProcessInstance | ".xlsx";
REM 先生成一个空的文件;
Local File &tempfile = GetFile(&FilePath, "W", %FilePath_Absolute);
&tempfile.Close();

&reportDefn.ChangeHeaderBackgroundColor(0, 0, 163, 132);
&reportDefn.ChangeHeaderFontColor(0, 255, 255, 255);

&reportDefn.buildExcel(&FilePath);
catch Exception &e;
WriteToLog(%ApplicationLogFence_Error, &e.ToString());
end-try;

jar包2:SieExcelPoi.jar

调用路径:generateExcelPOI.WriteExcelEx_2010

注意:该jar包无法处理超大数据量报表,慎用!!!(不建议使用)

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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
Local string &strCAL_PRD_ID;
Local number &iRow, &iCol, &i;
Local JavaObject &jExcel;

REM 获取参数;
&strCAL_PRD_ID = C_CEN_SUM_AET.CAL_PRD_ID.Value;
rem MessageBox(0, "", 0, 0, "&strCAL_PRD_ID==" | &strCAL_PRD_ID);
//引入Java类;
&jExcel = CreateJavaObject("generateExcelPOI.WriteExcelEx_2010");
//Excel 新建工作页;
&jExcel.newWorkBook();

&iRow = 0;
&iCol = 0;
&arrData = CreateArrayAny();

rem 报表制表表头;
&jExcel.addTitlePropertiesCell(&iRow, 0, "报表名称", "string", "");
&jExcel.addTitlePropertiesCell(&iRow, 1, "中心预算", "string", "");
&iRow = &iRow + 1;

&jExcel.addTitlePropertiesCell(&iRow, 0, "期间", "string", "");
&jExcel.addTitlePropertiesCell(&iRow, 1, &strCAL_PRD_ID, "string", "");
&iRow = &iRow + 1;

&jExcel.addTitlePropertiesCell(&iRow, 0, "制表人", "string", "");
SQLExec("SELECT NAME FROM PS_PERSONAL_DATA WHERE EMPLID = :1", %EmployeeId, &strRptPersonNm);
&strRptPersonNm = %OperatorId | " " | &strRptPersonNm;
&jExcel.addTitlePropertiesCell(&iRow, 1, &strRptPersonNm, "string", "");
&iRow = &iRow + 1;

&jExcel.addTitlePropertiesCell(&iRow, 0, "制表日期", "string", "");
&jExcel.addTitlePropertiesCell(&iRow, 1, String(%Date), "string", "");
&iRow = &iRow + 1;



REM 报表数据表头;
&iRow = &iRow + 1;
&iCol = 0;
&jExcel.addTitleCell(&iRow, &iCol, "一级部门", "string", "");
&iCol = &iCol + 1;
&jExcel.addTitleCell(&iRow, &iCol, "职级", "string", "");
&iCol = &iCol + 1;
&jExcel.addTitleCell(&iRow, &iCol, "实际人数", "string", "");
&iCol = &iCol + 1;
&jExcel.addTitleCell(&iRow, &iCol, "HC人数", "string", "");
&iCol = &iCol + 1;
&jExcel.addTitleCell(&iRow, &iCol, "实际工资", "string", "");
&iCol = &iCol + 1;
&jExcel.addTitleCell(&iRow, &iCol, "支出", "string", "");
&iCol = &iCol + 1;
&jExcel.addTitleCell(&iRow, &iCol, "差异金额", "string", "");


Local string &C_END_DT;
SQLExec("SELECT add_months(TO_DATE(:1, 'YYYY-MM'), 1) - 1 FROM DUAL", &strCAL_PRD_ID, &C_END_DT);
/*查部门路径表和职级表,拼基表*/
Local SQL &C_PSN_DEP_SQL = CreateSQL(SQL.C_PSN_DEP_SQL, &C_END_DT);
Local array &arr = CreateArrayAny();
rem Local Rowset &RS = GetLevel0().GetRow(1).GetRowset(Scroll.C_HC_COUNT_VW);
rem &RS.Flush();

While &C_PSN_DEP_SQL.Fetch(&arr)
Local string &strCOUNT1, &strC_COUNT1, &strC_AMT001, &strC_AMT003, &strC_AMT004;
rem &RS(&i).C_HC_COUNT_VW.C_POSN_GRDE_ID.Value = &arr [1];
rem &RS(&i).C_HC_COUNT_VW.C_POSN_GRDE_DESCR.Value = &arr [2];
rem &RS(&i).C_HC_COUNT_VW.DEPTID.Value = &arr [3];
rem &RS(&i).C_HC_COUNT_VW.DEPT_DESCR.Value = &arr [4];

/*根据基表+参数,搜索对应的实际人数+人力成本*/
SQLExec(SQL.C_CONT_SAL_SQL, &C_END_DT, &arr [3], &arr [1], &strCOUNT1, &strC_AMT001);
rem &RS(&i).C_HC_COUNT_VW.COUNT1.Value = &strCOUNT1;
rem &RS(&i).C_HC_COUNT_VW.C_AMT001.Value = &strC_AMT001;

/*根据基表+参数,搜索对应的HC人数*/
SQLExec(SQL.C_HC_COUNT_SQL, Substring(&C_END_DT, 1, 4), &arr [3], &arr [1], &C_END_DT, &strC_COUNT1);
rem &RS(&i).C_HC_COUNT_VW.C_COUNT1.Value = &strC_COUNT1;

/*计算HC成本+成本差异*/
If All(&strCOUNT1) And
Value(&strCOUNT1) > 0 Then
&strC_AMT003 = String(Round(Value(&strC_AMT001) / Value(&strCOUNT1) * Value(&strC_COUNT1), 2));
&strC_AMT004 = String(Round(Value(&strC_AMT001) - (Value(&strC_AMT001) / Value(&strCOUNT1) * Value(&strC_COUNT1)), 2));
Else
&strC_AMT003 = "0";
&strC_AMT004 = "0";
End-If;

&iRow = &iRow + 1;
&iCol = 0;
REM 一级部门;
&jExcel.addRowCell(&iRow, &iCol, &arr [4], "string", "");
&iCol = &iCol + 1;
REM 职级;
&jExcel.addRowCell(&iRow, &iCol, &arr [2], "string", "");
&iCol = &iCol + 1;
REM 实际人数;
&jExcel.addRowCell(&iRow, &iCol, &strCOUNT1, "string", "");
&iCol = &iCol + 1;
REM HC人数;
&jExcel.addRowCell(&iRow, &iCol, &strC_COUNT1, "string", "");
&iCol = &iCol + 1;
REM 实际工资;
&jExcel.addRowCell(&iRow, &iCol, &strC_AMT001, "string", "");
&iCol = &iCol + 1;
REM 支出;
&jExcel.addRowCell(&iRow, &iCol, &strC_AMT003, "string", "");
&iCol = &iCol + 1;
REM 差异金额;
&jExcel.addRowCell(&iRow, &iCol, &strC_AMT004, "string", "");
&iCol = &iCol + 1;
End-While;

&strRptName = "中心预算_" | C_CEN_SUM_AET.PROCESS_INSTANCE.Value;
&strRptName = &strRptName | ".xlsx";
// 获取实际路径PS_HOME并拼接文件名;
&strRptFullName = GetEnv("PSPRCSLOGDIR") | "/" | &strRptName;
&strRptName = &jExcel.outputFile(&strRptFullName);