简体   繁体   English

使用从 VBA 调用的 JAVA .jar 更改 Excel 中的单元格内容

[英]Change Cell content in Excel using JAVA .jar called from VBA

I have kind of specific problem at work.我在工作中遇到了一些具体问题。 I receive XLS file that has content in japanese characters and also alphabet letters and numbers, but all in full-width Japanese format.我收到的 XLS 文件包含日文字符以及字母和数字内容,但都是全角日文格式。 My problem is that Excel does not recognize these as normal letters and numbers.我的问题是 Excel 无法将这些识别为普通的字母和数字。 I found webpage with converter full-width <--> half-width characters, but it is too slow to manually copy, paste and overwrite each cell.我发现带有转换器全角 <--> 半角字符的网页,但是手动复制、粘贴和覆盖每个单元格太慢了。 There is also a JAVA .jar file that supposedly does the same converting (Class Transliterator).还有一个 JAVA .jar 文件,据说可以进行相同的转换(Class Transliterator)。 I wish to find a way how to run this Java function for each cell in defined range and return its value in half-width (normal) characters in order to create half-width copy of the original XLS file.我希望找到一种方法,如何为定义范围内的每个单元格运行此 Java 函数并以半角(正常)字符返回其值,以便创建原始 XLS 文件的半角副本。

Actual example of cell value is like this: Original cell content: #01A-110 Desired cell content after conversion: #01A-110单元格值的实际例子是这样的: 原始单元格内容:#01A-110 转换后所需的单元格内容:#01A-110

Thank you.谢谢你。 PS.附注。 I know how to loop cells and everything I need for it in VBA, but what I cannot find is bridging the JAVA that returns new value (as string).我知道如何在 VBA 中循环单元格和我需要的一切,但我找不到的是桥接返回新值(作为字符串)的 JAVA。

Actually, I found solution within VBA, because running .JAR turned out to be impossible.实际上,我在 VBA 中找到了解决方案,因为运行 .JAR 原来是不可能的。

The solution is StrConv( String, Conversion, [LocaleID] )解决方法是 StrConv( String, Conversion, [LocaleID] )

VBA selective conversion of double-byte to single-bye characters VBA 选择性地将双字节转换为单字节字符

Important: When in different lang environment, there must be LocaleID set to corresponding character set via [LocaleID] - An optional argument, specifying the LocaleID.重要提示:在不同的语言环境中,必须通过 [LocaleID] 将 LocaleID 设置为相应的字符集 - 一个可选参数,指定 LocaleID。

For ID codes see https://support.microsoft.com/cs-cz/help/221435/list-of-supported-locale-identifiers-in-word有关 ID 代码,请参阅https://support.microsoft.com/cs-cz/help/221435/list-of-supported-locale-identifiers-in-word

Working code then looks like this:工作代码如下所示:

Sub zen2han()子 zen2han()

Dim CLRange As Range Dim CLrange 作为范围

For Each CLRange In Selection对于选择中的每个 CLrange

CLRange.Value = StrConv(CLRange.Value, vbNarrow, 1041) CLRange.Value = StrConv(CLRange.Value, vbNarrow, 1041)

Next CLRange下一个 CL 范围

End Sub结束子

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM