如何在 Pega 7.1.8 中使用 pzRDExportWrapper 将重复网格布局数据导出到 Excel?

How to export repeat grid layout data to Excel using pzRDExportWrapper in Pega 7.1.8?

我正在尝试将重复网格数据导出到 excel。为此,我提供了一个按钮,可通过单击运行 "MyCustomActivity" activity。该按钮位于同一布局中的网格上方。还值得指出的是,我正在使用 article 作为配置指南。根据指南,我的 "MyCustomActivity" activity 包含两个步骤:

  1. 方法:属性-设置,方法参数:Param.exportmode = "excel"
  2. 方法:调用pzRDExportWrapper。我传递了当前参数(第一步只有一个)。

但是在我得到 之后,我通过 Call Rule-Obj-Report-Definition.pzRDExportWrapper

更改了第二步

但是正如您已经了解的那样,该解决方案不起作用。我检查了日志文件并发现了有趣的错误:

2017-04-11 21:08:27,992 [ WebContainer : 4] [OpenPortal] [ ] [ MyFW:01.01.02] (ctionWrapper._baseclass.Action) ERROR as1|172.22.254.110 bar - Activity 'MyCustomActivity' failed to execute; Failed to find a 'RULE-OBJ-ACTIVITY' with the name 'PZRESOLVECOPYFILTERS' that applies to 'COM-FW-MyFW-Work'. There were 3 rules with this name in the rulebase, but none matched this request. The 3 rules named 'PZRESOLVECOPYFILTERS' defined in the rulebase are: 2017-04-11 21:08:42,807 [ WebContainer : 4] [TABTHREAD1] [ ] [ MyFW:01.01.02] (fileSetup.Code_Security.Action) ERROR as1|172.22.254.110 bar - External authentication failed:

如果有人有任何建议并分享一些,我将不胜感激。 谢谢。

我想提供将检索到的作品导出到 CSV 文件的功能。该功能应该具有选择要检索的字段的功能,所有结果都应该是乌克兰语,并且能够使用任何 SearchFilter 页面和报告定义规则。

在用户门户我有两个部分:第一个部分包含文本字段和一个搜索按钮,另一个部分带有用于显示结果的重复网格。文本字段用于过滤结果,它们使用页面 Org-Div-Work-SearchFilter。

我为 csv 创建了一个自定义解析器。我创建了两个活动并编写了一些 Java 代码。我应该提到我从 pzPDExportWrapper 中获取了一些代码。

活动是:

  • ExportToCSV - 从用户获取参数,获取数据,调用 ConvertResultsToCSV;
  • ConvertResultsToCSV - 将检索到的数据转换为 .CSV 文件。

ExportToCSV 的配置activity:
页面和 类 选项卡:

  • ReportDefinition 是某个报表定义的对象。
  • SearchFilter 是一个包含用户输入值的页面。
  • ReportDefinitionResults 是要导出的检索作品列表。
  • ReportDefinitionResults.pxResults表示某作品的一种类型。

    参数选项卡:

  • FileName是生成文件的名称

  • ColumnsNames 以逗号分隔的列名称。如果参数为空,则导出 CSVProperties。
  • CSVProperties 是显示在以逗号分隔的电子表格中的道具。
  • SearchPageName 是用于过滤结果的页面的名称。
  • ReportDefinitionName 是用于检索结果的 RD 名称。
  • ReportDefinitionClass 是一个 class 使用的报告定义。

    步骤选项卡:

让我们看一下步骤:
1. 从具有填充字段的参数中获取名称的 SearchFilte 页面:
2. 如果 SearchFilter 不为 Empty,则调用 Data Transform 将 SearchFilter 的属性转换为 Paramemer 属性:

数据转换片段:
3. 获取报表定义的对象
4. 为报表定义设置参数
5. 调用 Report Definition 并将结果保存到 ReportDefinitionResults:
6. 调用 ConvertResultsToCSV activity:
7、删除结果页:

ConvertResultsToCSV 概述 activity。

ConvertResultsToCSV 的参数选项卡 activity:

  • CSVProperties 是要检索和导出的属性。
  • ColumnsNames 是要显示的列的名称。
  • PageListProperty 属性 要在主页面中读取的名称
  • FileName 生成文件的名称。可以为空。
  • AppendTimeStampToFileName - 如果为真,则为文件生成时间。
  • CSVString 要保存到文件的生成的 CSV 字符串。
  • FileName 文件名。
  • listSeperator 始终是分隔字段的分号。

    让我们浏览一下 activity 中的所有步骤:

    1. 从用户设置中获取本地化(已评论):

      理论上可以支持多种语言的本地化。
    2. 始终设置 "uk"(乌克兰语)本地化。
    3. 根据本地化获取分隔符。在乌克兰语、英语和俄语中它始终是一个分号。需要检查其他语言。

    4. 该步骤包含Java代码,形成一个CSV字符串:

</p> <pre><code>StringBuffer csvContent = new StringBuffer(); // a content of buffer String pageListProp = tools.getParamValue("PageListProperty"); ClipboardProperty resultsProp = myStepPage.getProperty(pageListProp); // fill the properties names list java.util.List<String> propertiesNames = new java.util.LinkedList<String>(); // names of properties which values display in csv String csvProps = tools.getParamValue("CSVProperties"); propertiesNames = java.util.Arrays.asList(csvProps.split(",")); // get user's colums names java.util.List<String> columnsNames = new java.util.LinkedList<String>(); String CSVDisplayProps = tools.getParamValue("ColumnsNames"); if (!CSVDisplayProps.isEmpty()) { columnsNames = java.util.Arrays.asList(CSVDisplayProps.split(",")); } else { columnsNames.addAll(propertiesNames); } // add columns to csv file Iterator columnsIter = columnsNames.iterator(); while (columnsIter.hasNext()) { csvContent.append(columnsIter.next().toString()); if (columnsIter.hasNext()){ csvContent.append(listSeperator); // listSeperator - local variable } } csvContent.append("\r"); for (int i = 1; i <= resultsProp.size(); i++) { ClipboardPage propPage = resultsProp.getPageValue(i); Iterator iterator = propertiesNames.iterator(); int propTypeIndex = 0; while (iterator.hasNext()) { ClipboardProperty clipProp = propPage.getIfPresent((iterator.next()).toString()); String propValue = ""; if(clipProp != null && !clipProp.isEmpty()) { char propType = clipProp.getType(); propValue = clipProp.getStringValue(); if (propType == ImmutablePropertyInfo.TYPE_DATE) { DateTimeUtils dtu = ThreadContainer.get().getDateTimeUtils(); long mills = dtu.parseDateString(propValue); java.util.Date date = new Date(mills); String sdate = dtu.formatDateTimeStamp(date); propValue = dtu.formatDateTime(sdate, "dd.MM.yyyy", "", ""); } else if (propType == ImmutablePropertyInfo.TYPE_DATETIME) { DateTimeUtils dtu = ThreadContainer.get().getDateTimeUtils(); propValue = dtu.formatDateTime(propValue, "dd.MM.yyyy HH:mm", "", ""); } else if ((propType == ImmutablePropertyInfo.TYPE_DECIMAL)) { propValue = PRNumberFormat.format(localeCode,PRNumberFormat.DEFAULT_DECIMAL, false, null, new BigDecimal(propValue)); } else if (propType == ImmutablePropertyInfo.TYPE_DOUBLE) { propValue = PRNumberFormat.format(localeCode,PRNumberFormat.DEFAULT_DECIMAL, false, null, Double.parseDouble(propValue)); } else if (propType == ImmutablePropertyInfo.TYPE_TEXT) { propValue = clipProp.getLocalizedText(); } else if (propType == ImmutablePropertyInfo.TYPE_INTEGER) { Integer intPropValue = Integer.parseInt(propValue); if (intPropValue < 0) { propValue = new String(); } } } if(propValue.contains(listSeperator)){ csvContent.append("\""+propValue+"\""); } else { csvContent.append(propValue); } if(iterator.hasNext()){ csvContent.append(listSeperator); } propTypeIndex++; } csvContent.append("\r"); } CSVString = csvContent.toString();

5. 这一步在服务器的目录树中形成并保存一个文件 </p> <pre><code>char sep = PRFile.separatorChar; String exportPath= tools.getProperty("pxProcess.pxServiceExportPath").getStringValue(); DateTimeUtils dtu = ThreadContainer.get().getDateTimeUtils(); String fileNameParam = tools.getParamValue("FileName"); if(fileNameParam.equals("")){ fileNameParam = "RecordsToCSV"; } //append a time stamp Boolean appendTimeStamp = tools.getParamAsBoolean(ImmutablePropertyInfo.TYPE_TRUEFALSE,"AppendTimeStampToFileName"); FileName += fileNameParam; if(appendTimeStamp) { FileName += "_"; String currentDateTime = dtu.getCurrentTimeStamp(); currentDateTime = dtu.formatDateTime(currentDateTime, "HH-mm-ss_dd.MM.yyyy", "", ""); FileName += currentDateTime; } //append a file format FileName += ".csv"; String strSQLfullPath = exportPath + sep + FileName; PRFile f = new PRFile(strSQLfullPath); PROutputStream stream = null; PRWriter out = null; try { // Create file stream = new PROutputStream(f); out = new PRWriter(stream, "UTF-8"); // Bug with Excel reading a file starting with 'ID' as SYLK file. If CSV starts with ID, prepend an empty space. if(CSVString.startsWith("ID")){ CSVString=" "+CSVString; } out.write(CSVString); } catch (Exception e) { oLog.error("Error writing csv file: " + e.getMessage()); } finally { try { // Close the output stream out.close(); } catch (Exception e) { oLog.error("Error of closing a file stream: " + e.getMessage()); } }

  1. 最后一步调用@baseclass.DownloadFile下载文件:

最后,我们可以 post 某些部分或其他地方的按钮并设置一个操作选项卡,如下所示:

它在 "Refresh Section" 动作中也能正常工作。

一个可能的结果可能是

感谢阅读