2013-03-13 161 views
0

我的客户端需要将文本文件导入系统,但其文本文件是管道分隔的“|”。他们还需要导出一些数据到相同的格式(管道分隔)。我被要求使用Powerbuilder 12.是否可以直接使用PipeDelimited文本文件导入文件?我想跳过“FOR LOOP MID GET”方法,直接进入importfile然后update()。 dw.saveas()也一样。Powerbuilder ImportFile/SaveAs

回答

0

,据我所知,我们是不是幸运的进口,因为我们无法定义的分隔符,但这里是一个小的解决方法:

  1. 文件读入到一个字符串变量
  2. 更换管道|以逗号,
  3. 导入字符串作为CSV到DW

我做了一个小测试程序对你和它的工作。我的文本文件是这样的:

Col1中| col2的| COL3

AAA | BBB | CCC

这里是导入代码:

string ls_import, ls_export 
long ll_filehandle, ll_readbytes 
// IMPORT 
ll_filehandle = FileOpen("d:\Work\StackExchange\pipes.txt", TextMode!) 
ll_readbytes = FileReadEx(ll_filehandle, ls_import) 

if ll_filehandle = -1 or IsNull(ll_filehandle) then 
else 
    ls_import = f_glo_replace_all(ls_import, "|", ",") 
    dw_1.ImportString(CSV!, ls_import) 
end if 

随着我们有更多的运气出口。有在其中您可以自定义分隔的出口数据窗口方法:

SaveAsFormattedText

所以进口是这样的:

dw_1.SaveAsFormattedText(“d:\工作\ StackExchange \ export_pipes .TXT”,EncodingANSI!‘|’)

当然,你将需要全局替换函数的代码:

这里是源:

global type f_glo_replace_all from function_object 
end type 

forward prototypes 
global function string f_glo_replace_all (string source, string look_for, string replace_with) 
end prototypes 

global function string f_glo_replace_all (string source, string look_for, string replace_with);/*A String Occurrence Search and Replace RoutineThe following code demonstrates a string occurrence search and replaceroutine.This routine works generically for any string. For example,if old_str = "red" and new_str ="green", all occurrences of "red" inside of mystring will be replaced with "green". 
Parameters 
Name = source Type = String 
Name = look_for Type = String 
Name = replace_with Type = String 
*/ 
int start_pos=1,len_look_for 

len_look_for = len(lower(look_for)) 
//find the first occurrence of look_for ... 
start_pos = Pos(lower(source),lower(look_for), start_pos) 
//only enter the loop if you find whats in look_for 
DO WHILE start_pos > 0 
    //replace look_for with replace_with ... 
    source = Replace(source,start_pos,Len_look_for,replace_with) 
    //find the next occurrence of 
    start_pos = Pos(lower(source), lower(look_for), start_pos+Len(replace_with)) 
LOOP 
return source 
end function 

我希望这有助于!

Br。 Gábor

+0

我认为这与“FOR LOOP MID GET”是一样的,因为它需要一行一行地读取,对于小于10的细节项目,这将是实际的,但是我面对每个文件每天约1000行。可悲的是我觉得我没有任何选择。 – Sid 2013-03-14 07:40:03

+0

对于导入yes是这样的,除了一次读取文件,只更改管道类似于“每行读取”方法,但对于导出有一个很好的解决方案! – DARKinVADER 2013-03-14 09:08:59

0

不,你想要的方式是不可能的。您需要编写自己的ImportFile版本,抱歉,这不是您想要的答案。