在Crystal Reports XI中的文本字段中格式化字符串

时间:2012-04-11 17:11:18

标签: string vba crystal-reports crystal-reports-xi

早上好!

我希望有人可以帮我解决一个简单的问题,但我不能按照我想要的方式开展工作。我目前正在处理一个包含“全能”文本字段的报告。在该字段中,用户可以输入他们想要的任何内容,有时,将以列格式输入信息(例如1.1)。此字段允许回车,用于在此字段中创建“行”。问题是用户希望此字段中的“列”在报表上排队,而不必在输入信息时计算列之间的空格(例如1.2)。问题是,即使输入此类信息,也没有设置协议或格式指南。可能有多个“字幕”,行,由字幕分隔的行等。每行末尾(或每行的开头)的回车(Chr(10))是唯一可以依赖的东西。 consistantly。

我目前正在尝试将每一行分开,根据需要对每个行进行格式化,并将其重新组合在一起:

    Dim output As String
    Dim sections as String
    Dim returnCount as Int 
    Dim leftText as String
    Dim rightText as String
    Dim sectionTogether as String
    Dim totalText as String
    Dim textLength as Int

    output = {table.textfield}

    sections = ExtractString(output, Chr(10), Chr(10))

    If Instr(sections,"  ") > 0 Then
      leftText = Left(sections, Instr(sections, "  "))
      textLength = Length(Left(sections, Instr(sections, "  "))
      rightText = Right(sections, Instr(sections, "  "))
      Replace(sections,"  "," ")
      sectionTogether = rightText + (Space(20) - (textLength - 3)) + leftText
      totalText = totalText + sectionTogether
      formula = totalText
    else
      formula = output

这是我要做的事情的要点。几个笔记: 1)我知道我错过了某种形式的循环来格式化每个部分,但我不知道如何在水晶中设置它 2)我有VB编程经验,但我是水晶和它有限的工具的菜鸟,所以我觉得hamstringed我找不到我将在Visual Studio中使用的方法和工具 3)我的语法也可能在几个地方关闭,因为我还在学习如何设置它,我真的错过了一个调试器。

我希望有人可以帮助我,我已经研究了一个多星期,感觉就像我只是把头靠在墙上。

提前谢谢。

The output examples
ex. 1.1
"Your current charges are:
Jan          12.89
Feb         117.44
Mar          15.02
Apr        4.17"

ex. 1.2
"Your current charges are:
Jan                       12.89
Feb                      117.44
Mar                       15.02
Apr                        4.17"

1 个答案:

答案 0 :(得分:3)

您要做的第一件事是通过split()拆分行,如下所示:

local stringvar array wallOText := split({table.textfield},chr(10));

这将为您提供一个字符串数组,其中每个数组条目都是“行”。现在,您可以使用以下内容遍历行:

for i := 1 to ubound(wallOText) step 1 do <some stuff to wallOText[i]>

现在,让列右对齐是有点棘手的,但这里有一些代码可以让你开始。您可以将列宽调整为您可能需要的任何值(在本例中为20个空格)。另请注意,您必须使用固定宽度的字体。

local stringvar output;
local stringvar array row;
local numbervar i;
local numbervar j;
local stringvar array wallOText := split({@some text},chr(10));
local stringvar elem;

for i := 1 to ubound(wallOText) do  //loop over lines
    (row := split(wallOText[i]," ");
     for j := 1 to ubound(row) do //loop over words
        (elem := trim(row[j]); //get current element and cut white space
         if not(elem="") then 
         output := output + space(20-len(elem)) + elem); //build output string
     output := output + chr(10));

output