英文:
Separated Character Generation convert from IBM i series (AS400) to Java text file
问题
我试图创建一个“XLS”文件,但它将以txt文件的形式可用(这意味着在Windows中右键单击并选择“打开方式”并选择记事本时,它将显示为制表符分隔的文本文件)。
这是我试图创建的示例文件(我不得不删除一些条目,因为它很大)。当您在Notepad++中打开文件并选择UTF-8编码时,您会看到像下面的图片中的“隐藏字符”:
如果您能看到xA0,那是IBM I Series(AS400)的COBOL程序生成的隐藏字符之一。
然而,如果您看到这些黄色高亮部分,那也是AS400的一个字符。它是这样声明的:
DCL VAR(&FLDDLM) TYPE(*CHAR) LEN(1) VALUE(X'05')
现在,我能够使用以下测试代码生成xA0:
List<Object[]> data = new ArrayList<>();
data.add(new Object[] { "AS1", "185914", "NETHERLANDS", "NL", "", "202023714", "2023714", "27-AUG-2022",
"03-FEB-2023", "", "", "00000000", "IF-ADAMAS", "", "PTF166091NL00",
"P166091NL00", "", "", "", "", "IF ADAMAS B V" });
data add(new Object[] { "AS1", "20200893", "GERMANY", "DE", "", "13801864.3", "2915188",
"05-NOV-2022", "22-FEB-2023", "R80049", "10", "00000434", "MICRONIT M", "",
"PTF124241DEEP", "P118354DEEP", "", "", "", "",
"MICRONIT MICROFLUIDICS B.V." });
OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream("output.XLS"),"windows-1252");
writer.write(
"\\"Client\\"\\t\\"Case Number\\"\\t\\"Country\\"\\t\\"WIPO\\"\\t\\"Subcase\\"\\t\\"Application Number\\"\\t\\"Patent Number\\"\\t\\"Due Date\\"\\t\\"Paid Date\\"\\t\\"Invoice Number\\"\\t\\"Annuity Number\\"\\t\\"Invoice Amount\\"\\t\\"Client/Division\\"\\t\\"Client Ref(Inv)\\"\\t\\"Client Ref#1(Ctry)\\"\\t\\"Client Ref#2(Ctry)\\"\\t\\"Attorney(Inv)\\"\\t\\"Attorney(Ctry)\\"\\t\\"Remarks\\"\\t\\"Local Title\\"\\t\\"Title Holder\\"\\n");
for (Object[] row : data) {
for (int i = 0; i < row.length; i++) {
writer.write("\\"\"" + "\\u00a0" + row[i].toString() + "\\""");
if (i < row.length - 1) {
writer.write("\\t");
}
}
writer.write("\\n");
}
writer.close();
System.out.println("Done");
}
我必须在FileOutputStream("output.XLS"),"windows-1252"
中加入"windows-1252"
,以便生成像上面图片中看到的xA0
,就像您在图片中看到的那样。
然而,
DCL VAR(&FLDDLM) TYPE(*CHAR) LEN(1) VALUE(X'05')
我在
if (i < row.length - 1) {
writer.write(" ");
}
中使用了"\u0005"
而不是简单的"\t"
,它给我带来了ENQ,就像下面的图片一样:
这不是我想要的。我想要像第一张图片一样的效果。因此,有人能告诉我X'05'
字段分隔符的等效项是什么吗?我应该做什么改变?
有人能帮助我吗?
非常感谢!
英文:
I'm trying to create an "XLS" file, but it will be available as a txt file. (It means when you right click and select open with in windows and choose notepad it will show as tab separated text file.)
This is the sample file that I'm trying to create (I have to remove some entry because it is big). When you open the file in notepad++ and choose encoding in UTF-8, you will see "hidden characters" like the picture below:
If you can see xA0 that is one of the hidden characters that is generated by a COBOL program of the IBM I Series (AS400).
However, if you see those yellow highlighted part, that is also a character of the AS400. It was declared like this below:
DCL VAR(&FLDDLM) TYPE(*CHAR) LEN(1) VALUE(X'05')
Now I was able to generate the xA0 with these test code below:
List<Object[]> data = new ArrayList<>();
data.add(new Object[] { "AS1", "185914", "NETHERLANDS", "NL", "", "202023714", "2023714", "27-AUG-2022",
"03-FEB-2023", "", "", "00000000", "IF-ADAMAS", "", "PTF166091NL00",
"P166091NL00", "", "", "", "", "IF ADAMAS B V" });
data.add(new Object[] { "AS1", "20200893", "GERMANY", "DE", "", "13801864.3", "2915188",
"05-NOV-2022", "22-FEB-2023", "R80049", "10", "00000434", "MICRONIT M", "",
"PTF124241DEEP", "P118354DEEP", "", "", "", "",
"MICRONIT MICROFLUIDICS B.V." });
OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream("output.XLS"),"windows-1252");
writer.write(
"\"Client\"\t\"Case Number\"\t\"Country\"\t\"WIPO\"\t\"Subcase\"\t\"Application Number\"\t\"Patent Number\"\t\"Due Date\"\t\"Paid Date\"\t\"Invoice Number\"\t\"Annuity Number\"\t\"Invoice Amount\"\t\"Client/Division\"\t\"Client Ref(Inv)\"\t\"Client Ref#1(Ctry)\"\t\"Client Ref#2(Ctry)\"\t\"Attorney(Inv)\"\t\"Attorney(Ctry)\"\t\"Remarks\"\t\"Local Title\"\t\"Title Holder\"\n");
for (Object[] row : data) {
for (int i = 0; i < row.length; i++) {
writer.write("\"" + "\u00a0" + row[i].toString() + "\"");
if (i < row.length - 1) {
writer.write("\t");
}
}
writer.write("\n");
}
writer.close();
System.out.println("Done");
}
I must put in the "windows-1252"
in FileOutputStream("output.XLS"),"windows-1252");
to generate the xA0
with "\u00a0"
like you see in the picture above. However,
DCL VAR(&FLDDLM) TYPE(*CHAR) LEN(1) VALUE(X'05')
I put in the "\u0005"
instead of simple "\t"
in the
if (i < row.length - 1) {
writer.write("\t");
}
It gives me ENQ
like this picture below
That is not what I want to achieve. I want to achieve like the first picture.
Thus, can someone tell me what is the equivalent of X'05'
field separator? What should I change?
Can someone help me with this please?
I would be very appreciated!
答案1
得分: 2
你可以查看ASCII表和EBCDIC表,这样你可以自己确定这些映射关系。但无论如何,你可以在这里找到EBCDIC表,以及在这里找到ASCII表。如果你要查找TAB或水平制表符,你会发现在EBCDIC中它是x05,在ASCII中是x09。由于windows-1252是ASCII编码,你应该将\u0009加载到文件中。
英文:
You might want to Google ASCII table, and EBCDIC table. That way you can determine these mappings yourself. But anyway, you can find an EBCDIC table here and an ASCII table here. If you look for TAB or horizontal tab, you will find that it is x05 in EBCDIC, and x09 in ASCII. Since windows-1252 is an ASCII code, you should be loading \u0009 into the file.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论