从 Txt 文件格式化数字数据的问题亲爱的社区,
我正在尝试构建一个 jsl 脚本来正确导入 ecnlosed 示例文件中格式化的数据。 我面临的挑战:
- 十进制符号是“,”而不是“.”。 通过使用我的区域首选项的默认设置,JMP 将“,”解释为千位分隔符。 如何强制 JMP 在 jsl 脚本中正确解释这些数字?
- 负数的格式如下:64,000-。 JMP 可以处理这种格式吗?
一种解决方案可能是重新格式化 txt 文件,但它是从 ERP 中提取的,IT 团队不明白我无法像 Excel 那样处理此类文件。
感谢致敬,
热罗姆
脚本编写回复:从 Txt 文件格式化数字数据的问题你好,
您可以尝试以下操作;当您提到 IT 不了解您的问题时,您可以使用 JSL 自己重新格式化文件。 虽然可能有一个导入设置来处理逗号作为十进制,但我无法立即想到它,也无法在文档中找到它。 也许其他人会用该设置回复。 在那之前,看看这是否有效。 我附上了一个示例文件;如果你把它放在你的下载文件夹中,脚本有望在不修改的情况下运行。
</CODE></P>
<PRE><CODE class=" language-jsl">Names Default To Here( 1 );
//set these to reflect your path and file name
path = "$DOWNLOADS/";
origFile = "example.txt";
holdFile = "example_modified.txt";
//get text of original file and replace commas with decimals
txt = Substitute( Load Text File( path || origFile ), ",", "." );
//save resulting text to a file, open this file as a table, then delete the file
Save Text File( path || holdFile, txt );
dt = Open( path || holdFile );
Delete File( path || holdFile );
//create a new column. if the last character is not "-", the string is immediately converted to a number. If the last
//character IS a "-", the string is converted to a number after the "-" is moved to the first character of the string
dt << New Column( "xx", formula( Num( If( Right( :INFO, 1 ) != "-", :INFO, "-" || Left( :INFO, Length( :INFO ) - 1 ) ) ) ) );
//remove the formula, so we can delete the original INFO column and rename our new column to INFO
dt:xx << Delete Formula;
dt << Delete Columns( "INFO" );
dt:xx << set name( "INFO" );
干杯,
布雷迪
回复:从 Txt 文件格式化数字数据的问题我喜欢这个聪明的解决方案,我不知道这种直接修改txt文件的方式。 非常感谢你!