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

时间:2017-04-11 19:17:52

标签: java pega

我正在尝试将重复网格数据导出为ex​​cel。为此,我提供了一个按钮,通过单击运行“MyCustomActivity”活动。按钮以相同的布局放置在网格上方。值得指出的是,我正在推荐article作为配置指南。根据指南,我的“MyCustomActivity”活动包含两个步骤:

  1. 方法:属性集,方法参数:Param.exportmode =“excel”
  2. 方法:调用pzRDExportWrapper。我传递当前参数(第一步只有一个)。
  3. 但在我获得issue之后,我通过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 - 活动'MyCustomActivity'失败执行;无法找到名为'PZRESOLVECOPYFILTERS'的'RULE-OBJ-ACTIVITY',适用于'COM-FW-MyFW-Work'。规则库中有3个具有此名称的规则,但没有一个符合此请求。规则库中定义的名为“PZRESOLVECOPYFILTERS”的3条规则是:   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 - 外部身份验证失败:

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

1 个答案:

答案 0 :(得分:1)

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

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

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

活动如下:

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

ExportToCSV活动的配置:
页面和类选项卡:
enter image description here

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

    参数选项卡:
    enter image description here

  • FileName是生成文件的名称

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

    “步骤”标签:
    enter image description here

让我们看看以下步骤:
 1.从带有填充字段的参数中获取一个带有名称的SearchFilte页面:
enter image description here  2.如果SearchFilter不为空,请调用数据转换以将SearchFilter的属性转换为Paramemer属性:
enter image description here
数据片段转换:
enter image description here  3.获取报表定义的对象
enter image description here  4.设置报告定义的参数
enter image description here  5.调用报告定义并将结果保存到ReportDefinitionResults:
enter image description here  6.调用ConvertResultsToCSV活动:
enter image description here  7.删除结果页面:
enter image description here

ConvertResultsToCSV活动的概述。
enter image description here
如果ConvertResultsToCSV活动的参数选项卡:
enter image description here

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

    让我们浏览活动中的所有步骤:

    1. 从用户设置获取本地化(已评论):
      enter image description here
      从理论上讲,它能够支持多种语言的本地化。
    2. 始终设置" uk" (乌克兰语)本地化。
      enter image description here
    3. 根据本地化获取分隔符。它始终是乌克兰语,英语和俄语的分号。需要检查其他语言。
      enter image description here

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

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();

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.此步骤在服务器的目录树中形成并保存文件

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来下载文件:
    enter image description here
  2. 最后,我们可以在某个部分或其他地方发布一个按钮,并设置如下所示的“操作”选项卡:
    enter image description here
    它内部工作正常&#34;刷新部分&#34;行动。

    可能的结果是
    enter image description here

    感谢阅读。