Bug 149882 - Calc replaces all Greek characters in a BASIC macro with "?"
Summary: Calc replaces all Greek characters in a BASIC macro with "?"
Status: RESOLVED DUPLICATE of bug 75263
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: BASIC (show other bugs)
Version:
(earliest affected)
7.2.7.2 release
Hardware: x86-64 (AMD64) Linux (All)
: medium normal
Assignee: Not Assigned
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2022-07-06 15:09 UTC by Alexander
Modified: 2022-07-07 07:55 UTC (History)
2 users (show)

See Also:
Crash report or crash signature:


Attachments
The text of the actual Macro (3.43 KB, text/plain)
2022-07-06 15:10 UTC, Alexander
Details
the text of the macro after saving (3.07 KB, text/plain)
2022-07-06 15:11 UTC, Alexander
Details
The actual xlsm file (7.21 KB, application/vnd.ms-excel.sheet.macroEnabled.12)
2022-07-06 16:11 UTC, Alexander
Details
The correct xlsm file unopened from Libreoffice (14.89 KB, application/vnd.ms-excel.sheet.macroEnabled.12)
2022-07-07 07:34 UTC, Alexander
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Alexander 2022-07-06 15:09:23 UTC
Description:
I have some xlsm files that contain macros that need to have Greek characters. After opening and saving the file with libreoffice calc the Greek characters will change to "?" destroying the macro. Maybe valid for any non Latin character.

Whe the file is in ods format it seems to be function ok.

Steps to Reproduce:
1.Write a BASIC macro containing Greek characters in an xlsm file
2.Open and save the file with calc


Actual Results:
Every Greek Characher is changed to "?"

Expected Results:
Every Greek Characher should NOT be changed to "?"


Reproducible: Always


User Profile Reset: Yes


OpenGL enabled: Yes

Additional Info:
Version: 7.2.7.2 / LibreOffice Community
Build ID: 20(Build:2)
CPU threads: 12; OS: Linux 5.18; UI render: default; VCL: gtk3
Locale: el-GR (en_US.UTF-8); UI: en-US
7.2.7-3
Calc:
Comment 1 Alexander 2022-07-06 15:10:50 UTC
Created attachment 181141 [details]
The text of the actual Macro

The text of the actual Macro
Comment 2 Alexander 2022-07-06 15:11:26 UTC
Created attachment 181142 [details]
the text of the macro after saving

the text of the macro after saving
Comment 3 Eike Rathke 2022-07-06 15:48:19 UTC
Can't reproduce. If I save the "actual Macro" attachment, which is UTF-8, as file, open it in an editor displaying it fine, and copy-paste it into Calc's BASIC editor (or import it there as BASIC file), save the document, reload it, open the BASIC editor again it's still fine.

Probably the original .xlsm files have the macros encoded in some text encoding other than UTF-8, i.e some code page like Windows-1252 or so. Please attach such sample file.
Comment 4 Alexander 2022-07-06 16:08:59 UTC
I have done what you describe multiple times. I am attaching the actual file.
Comment 5 Alexander 2022-07-06 16:11:00 UTC
Created attachment 181143 [details]
The actual xlsm file

The actual xlsm file
Comment 6 Mike Kaganski 2022-07-06 19:57:10 UTC

*** This bug has been marked as a duplicate of bug 75263 ***
Comment 7 Mike Kaganski 2022-07-07 07:14:22 UTC
(In reply to Alexander from comment #5)
> Created attachment 181143 [details]
> The actual xlsm file

FTR: the said attachment is not the "actual" file, it is what was *destroyed* by LibreOffice 7.2 (not yet having the fix that appeared in to-be-released-soon 7.4, and so saving VBA modules in a hardcoded Windows-1252). To allow others to reproduce the *reported problem* (as opposed to "look at the results which you can't reproduce yourself"), the *original*, correct file is needed, which others can open, see the Greek characters, save locally, and see the breakage. Hope this helps you next time. Thank you for filing this bug!
Comment 8 Alexander 2022-07-07 07:34:52 UTC
Created attachment 181146 [details]
The correct xlsm file unopened from Libreoffice

The correct xlsm file unopened from Libreoffice
Comment 9 Mike Kaganski 2022-07-07 07:55:37 UTC
(In reply to Alexander from comment #8)

Thanks! Indeed, it has the problem in 7.3, and is fixed in 7.4. By the way, LibreOffice now works better in that regards than MS Office: the latter will destroy the macros on any non-Greek locale - e.g., on my Russian locale it shows opened the macro this way:

> Option Explicit
> 
> Public Function GreekToLatin(celltxt As Variant) As String
>     Dim i As Long, j As Long
>     
>     Dim txt As Variant
>     
>     txt = Application.WorksheetFunction.Trim(celltxt)
>     
>     If Len(txt) Then
>         'МефбфспрЮ уе режЬ
>         txt = LCase(txt)
> 
>         'БнфйкбфЬуфбуз т ме у
>         txt = Replace(txt, "т", "у")
> 
>         'БнфйкбфЬуфбуз 'пх' уе 'oy' ==> (9)
>         txt = Replace(txt, "ьх", "oy")
>         txt = Replace(txt, "ьы", "oy")
>         txt = Replace(txt, "пы", "oy")
> 
>         'БцбЯсеуз фьнщн клр
>         Dim MeTonous As Variant, Atona As Variant
>         MeTonous = Array("Ь", "Э", "Ю", "Я", "ь", "э", "ю", "ъ", "ы", "А", "а")
>         Atona = Array("б", "е", "з", "й", "п", "х", "щ", "й", "х", "й", "х")
> 
>         For i = 0 To UBound(MeTonous)
>             txt = Replace(txt, MeTonous(i), Atona(i))
>         Next
> 
>         'БнфйкбфЬуфбуз дйциьггщн (бх, ех, зх) ме (av, ev, iv)==> (3)
>         Dim Difth As Variant, tov As Variant, tof As Variant
>         Difth = Array("бх", "ех", "зх")
>         tov = Array("в", "г", "д", "ж", "л", "м", "н", "с", _
>                     "б", "е", "з", "й", "п", "х", "щ")
> 
>         For i = 0 To UBound(Difth)
>             For j = 0 To UBound(tov)
>                 txt = Replace(txt, Difth(i) & tov(j), Left(Difth(i), 1) & "v" & tov(j))
>             Next
>         Next
> 
>         'БнфйкбфЬуфбуз дйциьггщн (бх, ех, зх) ме (af, ef, if)==>(4)
>         tof = Array("и", "к", "о", "р", "у", "ф", "ц", "ч", "ш")
> 
>         For i = 0 To UBound(Difth)
>             For j = 0 To UBound(tof)
>                 txt = Replace(txt, Difth(i) & tof(j), Left(Difth(i), 1) & "f" & tof(j))
>             Next
>         Next
>         'јфбн еЯнбй  фЭлпт фзт лЭозт ==> (4)
>         For i = 0 To UBound(Difth)
>             txt = Replace(txt & " ", Difth(i) & " ", Left(Difth(i), 1) & "f ")
>         Next
> 
>         'Фп 'мр' уфзн бсчЮ  гЯнефбй 'b' ==> (5)
>         txt = Replace(" " & txt, " мр", " b")
> 
>         'Фп 'мр' уфп фЭлпт  гЯнефбй 'b' ==>(7)
>         txt = Replace(txt & " ", "мр ", "b ")
> 
>         'БнфйкбфЬуфбуз ухмрлькщн
>         Dim SimplocaGr As Variant, SimplocaLn As Variant
>         SimplocaGr = Array("гг", "гч", "го", "пх")
>         SimplocaLn = Array("ng", "nch", "nx", "ou")
>         For i = 0 To UBound(SimplocaGr)
>             txt = Replace(txt, SimplocaGr(i), SimplocaLn(i))
>         Next
> 
>         'БнфйкбфЬуфбуз хрьрпйрщн чбсбкфЮсщн
>         Dim Greek As Variant, Latin As Variant
>         Greek = Array("б", "в", "г", "д", "е", "ж", "з", "и", "й", "к", _
>                       "л", "м", "н", "о", "п", "р", "с", "у", "ф", "х", _
>                       "ц", "ч", "ш", "щ")
>         Latin = Array("a", "v", "g", "d", "e", "z", "i", "th", "i", "k", _
>                       "l", "m", "n", "x", "o", "p", "r", "s", "t", "y", _
>                       "f", "ch", "ps", "o")
> 
>         For i = 0 To UBound(Greek)
>             txt = Replace(txt, Greek(i), Latin(i))
>         Next
> 
>         txt = Trim(txt)
>         'МефбфспрЮ рсюфпх чбсбкфЮсб уе кецблбЯп (Proper)
>         txt = Application.WorksheetFunction.Proper(txt)
>         GreekToLatin = txt
>     End If
> End Function

i.e., it simply treats the stored Windows-1253 encoding as Windows-1251. In LibreOffice, which uses Unicode also for macros, it will import, show and export the macros correctly (with a caveat that, since MS formats use non-Unicode encoding, if you use some character not representable in the original macro encoding, it will still convert to ? - so you can't have both Greek and Cyrillic characters in one MS VBA macro).