英文:
How to combine fixed n rows into columns in Crystal Reports
问题
我有一个报告(Crystal Reports),记录以以下方式输入:
字段名 | 数值 | 位置 |
---|---|---|
'姓名' | '安东' | 01 |
'年龄' | 15 | 02 |
'性别' | 'X' | 03 |
'姓名' | '安东' | 04 |
'年龄' | 15 | 05 |
'性别' | '男' | 06 |
'姓名' | '安东' | 07 |
'年龄' | 15 | 08 |
'性别' | '男' | 09 |
等等,等等, |
因此,我的记录集只有3列,字段名、数值和位置。
我创建了一个公式,将所有行放入一个变量中,如下所示:
如果记录.Position = 1,则stringVar name_1 = 记录.Value
如果记录.Position = 2,则StringVar age_1 = 记录.Value
如果记录.Position = 3,则StringVar gender_1 = 记录.Value
依此类推,对于第二、第三、...条记录
如果我将此公式放在详细部分,那么所有变量都将被创建。
然后,我为每个创建的单独变量创建一个新的公式,并将例如name_1、age_1和gender_1放在页脚部分,name_2、age_2和gender_2放在第二页脚部分,以此类推。
我的问题是:
是否可以将这些记录放入某种数组中,以便将此数组作为具有3列的常规记录集进行迭代?因此,在伪代码中,创建具有前3条记录的3列数组,依此类推?
目的是在详细部分中使用此数组,创建对应的3条记录的3列布局,因此第一行是记录1..3,第二行= 4..6,第三行= 记录7..9等等。
英文:
I have a Report (Crystal Reports) which is feeded records in the following way;
FieldName | Value | Position |
---|---|---|
'Name' | 'Anton' | 01 |
'Age' | 15 | 02 |
'Gender' | 'X' | 03 |
'Name' | 'Anton' | 04 |
'Age' | 15 | 05 |
'Gender' | 'M' | 06 |
'Name' | 'Anton' | 07 |
'Age' | 15 | 08 |
'Gender' | 'M' | 09 |
etc, etc, |
So my recordset has only 3 columns, FieldName, Value and Position.
I've created an formula which put all the rows in a variable like:
if record.Position = 1 then stringVar name_1 = record.Value
if record.Position = 2 then StringVar age_1 = record.Value
if record.Position = 3 then StringVar gender_1 = record.Value
and so on for the second, third, ... record
If I put this formula in the detail section, then all the variable are created.
Then I create a new formula for each individual variable created and put for example name_1, age_1 and gender_1 in a footer section, name_2, age_2, gender 2 in a second footer section and so on.
My question is;
Is it possible to put these records in some kind of an array to itterate this array as a normal recordset with 3 column? So in pseude; create array with 3 columns of first 3 records and so on?
Purpuse is to use this array in the detail section to create an layout with 3 columns for the corresponding 3 records, so first row is record 1..3, second row = 4..6, third row = record 7..9 and so on.
答案1
得分: 1
以下是代码的中文翻译部分:
如下图所示,此Crystal公式可以将您的数据转换为所需的显示形式,以单个文本对象的形式显示。但如果您需要将数据处理为常规的多行结果集,您需要进行2步处理。
local stringvar Data_In_Rows := {@Data} ;
Data_In_Rows := Replace(Data_In_Rows, "|FieldName|Value|Position| |-------|------|-------| |'Name'|","");
Data_In_Rows := LEFT(Data_In_Rows, Len(Data_In_Rows) - 1) ;
Data_In_Rows := Replace(Data_In_Rows, "| |'Name'|", Chr(10) + Chr(13));
Data_In_Rows := Replace(Data_In_Rows, "'Age'|", "");
Data_In_Rows := Replace(Data_In_Rows, "'Gender'|", "");
local stringvar array myArray := Split(Data_In_Rows, Chr(10) + Chr(13));
local stringvar result ;
local numbervar NumberOfRows := UBound(myArray) ;
local numbervar rowNumber;
local stringvar row ;
local stringvar array rowArray;
For rowNumber := 1 to NumberOfRows step 1 do
(
row := myArray[rowNumber];
rowArray := Split(row, "| |");
IF UBound(rowArray) = 3 Then
result := result + LEFT(rowArray[1], Len(rowArray[1]) -3 ) + "," + LEFT(rowArray[2], Len(rowArray[2]) -3 ) + "," +LEFT(rowArray[3], Len(rowArray[3]) -3) + Chr(10) + Chr(13);
);
result := "Name,Age,Gender" + Chr(10) + Chr(13) + result;
注意:上述代码为Crystal编程语言的一部分,已经保留原始代码中的特殊字符和注释。
英文:
As the image below shows, this Crystal formula can convert your data to the desired display as a single text object. But if you need to handle the data as a regular multi-row result set, you would need a 2-step process.
local stringvar Data_In_Rows := {@Data} ;
Data_In_Rows := Replace(Data_In_Rows, "|FieldName|Value|Position| |-------|------|-------| |'Name'|","");
Data_In_Rows := LEFT(Data_In_Rows, Len(Data_In_Rows) - 1) ;
Data_In_Rows := Replace(Data_In_Rows, "| |'Name'|", Chr(10) + Chr(13));
Data_In_Rows := Replace(Data_In_Rows, "'Age'|", "");
Data_In_Rows := Replace(Data_In_Rows, "'Gender'|", "");
local stringvar array myArray := Split(Data_In_Rows, Chr(10) + Chr(13));
local stringvar result ;
local numbervar NumberOfRows := UBound(myArray) ;
local numbervar rowNumber;
local stringvar row ;
local stringvar array rowArray;
For rowNumber := 1 to NumberOfRows step 1 do
(
row := myArray[rowNumber];
rowArray := Split(row, "| |");
IF UBound(rowArray) = 3 Then
result := result + LEFT(rowArray[1], Len(rowArray[1]) -3 ) + "," + LEFT(rowArray[2], Len(rowArray[2]) -3 ) + "," +LEFT(rowArray[3], Len(rowArray[3]) -3) + Chr(10) + Chr(13);
);
result := "Name,Age,Gender" + Chr(10) + Chr(13) + result;
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论