Calc macro: write korean characters in a text file

Hi,
I use Calc to manage localization languages, with a macro to create
formatted .json files (one per language). One is korean (the only language I
use in something else than latin alphabet).

Calc display korean characters correctly, but the generated file is filled
with "?" instead of korean characters. How to fix it please?

That's the only problem I have, in this specific language.

Thanks,

A couple questions ...

What operating system are you using? (e.g. Windows 7, Ubuntu 16.10, or ...)

Is your system set up as UTF-8?

Can you confirm that your default keyboard layout is some Latin variant,
e.g. English?

Can you tell us how you switch from your default layout to Korean? (e.g.
using some Input Method Editor, or?)

Can you enter Korean in a terminal emulator?

Can you type Korean using a text editor?

Do you know for a fact that your font contains the Korean Jamo?

If you don't know the answers to any of these questions, answer the ones you
can, and someone here familiar with your Operating System will be better
able to guide you.

In several recent Linux releases, Korean support has become broken in
several respects, but can still be made to work.

Hi, thanks for your help

I'm on Windows 10, and my keyboard is AZERTY. As French, the system is
probably not UTF-8 by default.
I just copy/paste hangul from another .ods file.
I tried with 2 text editors and the .json reader from Firefox.

It seems the problem is the macro creates an ANSI file by default, and not a
UTF-8 version. I have no idea how to change it.

If I create an UTF-8 file before running the macro, the macro recreates it
in ANSI.

With the macro, *open *and *print *commands.

I just checked OOME 4, and I think that I have a glaring omission in that I do not test or document the behavior of using write or print with special characters. Sadly, I do not know the answer off hand, but, I expect that you are seeing that they are not properly supported.

Can you try using Simple File Access instead and let me know if that works?

There is an example her:

http://www.pitonyak.org/oo.php

http://www.pitonyak.org/OOME_4_0.odt

I include the example here, but, you should be able to see what you need to do. Also note that the ODT documents contains the macros and you can run the test program while reading the document if you eneable macros when you load the document.

This is the example macro:

Sub ExampleSimpleFileAccess
   Dim oSFA ' SimpleFileAccess service.
   Dim sFileName$ ' Name of file to open.
   Dim oStream ' Stream returned from SimpleFileAccess.
   Dim oTextStream ' TextStream service.
   Dim sStrings ' Strings to test write / read.
   Dim sInput$ ' The string that is read.
   Dim s$ ' Accumulate result to print.
   Dim i% ' Index variable.

   sStrings = Array("One", "UTF:Āā", "1@3")

   ' File to use.
   sFileName = CurDir() & "/delme.out"

   ' Create the SimpleFileAccess service.
   oSFA = CreateUnoService("com.sun.star.ucb.SimpleFileAccess")

   'Create the Specialized stream.
   oTextStream = CreateUnoService("com.sun.star.io.TextOutputStream")

   'If the file already exists, delete it.
   If oSFA.exists(sFileName) Then
     oSFA.kill(sFileName)
   End If

   ' Open the file for writing.
   oStream = oSFA.openFileWrite(sFileName)

   ' Attach the simple stream to the text stream.
   ' The text stream will use the simple stream.
   oTextStream.setOutputStream(oStream)

   ' Write the strings.
   For i = LBound(sStrings) To UBound(sStrings)
     oTextStream.writeString(sStrings(i) & CHR$(10))
   Next

   ' Close the stream.
   oTextStream.closeOutput()

   oTextStream = CreateUnoService("com.sun.star.io.TextInputStream")
   oStream = oSFA.openFileRead(sFileName)
   oTextStream.setInputStream(oStream)
   For i = LBound(sStrings) To UBound(sStrings)
     sInput = oTextStream.readLine()
     s = s & CStr(i)

     ' If the EOF is reached then the new line delimiters are
     ' not removed. I consider this a bug.
     If oTextStream.isEOF() Then
       If Right(sInput, 1) = CHR$(10) Then
         sInput = Left(sInput, Len(sInput) - 1)
       End If
     End If

     ' Verify that the read string is the same as the written string.
     If sInput <> sStrings(i) Then
       s = s & " : BAD "
     Else
       s = s & " : OK "
     End If
     s = s & "(" & sStrings(i) & ")"
     s = s & "(" & sInput & ")" & CHR$(10)
   Next
   oTextStream.closeInput()
   MsgBox s
End Sub

Let me know if this works, I believe that it will. I hope that it will.