2012-04-11 116 views
2

早上好!在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编程经验,但我在水晶noob和它有限的工具,所以我觉得受到了限制,并且在查找我在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" 

回答

3

你会想要做的第一件事就是通过拆分()分手了你的行,像这样:

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
+0

感谢瑞恩的快速反响。这是一个真正的字体,我喜欢你的方法,但我仍然遇到间距错误。我不得不对你的代码做一些小的修改,这样它就不会在没有多个空格的行上执行这些操作。 '(对于i:= 1 to ubound(墙)) if (行): (elem:= trim(row [j]); output:= output + space(20-len(elem))+ elem); output:= output + chr(10)); ) 其他 输出:= {PBP_DPM_DETAIL_VW。文本}; 输出” – 2012-04-11 19:11:03

+0

我的意思是,代码看起来像它应该工作,但是当我没有改变运行代码,它确实有些怪异间距。 idk最新情况。 – 2012-04-11 19:20:21

+0

@EdwardLane在构建输出之前,我添加了如果不是(elem =“”)然后''的行。这将处理他们使用一堆空格来划分列的情况,就像在你的例子中一样。至于跳过包含“字幕”的行,您可以检查在该行中是否出现带有两个空格的字符串。 – Ryan 2012-04-11 19:20:36

相关问题