[Solved] Display a file with utf-8 format with macro

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
maroun
Posts: 10
Joined: Tue Mar 14, 2017 2:55 pm

[Solved] Display a file with utf-8 format with macro

Post by maroun »

hi;

i'm trying to open a file with soffice GUI. after choosing the file to display the open office prompt the window " ascii filter options " as the file contains Arabic words so choosing the UTF-8 in character set permit to display the file properly.

i'm looking to create a macro to open the file as UTF-8 I created the 2 subs below

sub test5

oDoc = ThisComponent

url= ConvertToUrl ("/u/batch/test.utf8")

dim exportdata(0) as new com.sun.star.beans.PropertyValue
exportdata(0).Name = "FilterOptions"
exportdata(0).Value = "76"
oDoc = starDesktop.loadComponentFromURL(url, "_blank", 0, exportdata())

End sub

also I created the below sub

sub test6

oDoc = ThisComponent

url= ConvertToUrl ("/u/batch/test.utf8")

dim exportdata(0) as new com.sun.star.beans.PropertyValue
exportdata(0).Name = "FilterOptions"
exportdata(0).Value = "76"
oDoc = starDesktop.loadComponentFromURL(url, "_blank", 0, exportdata())

End sub

both subs still showing the Arabic characters as encrypted despite that when opening with soffice GUI the file is presented properly.
Last edited by Hagar Delest on Wed Mar 15, 2017 9:38 pm, edited 1 time in total.
Reason: tagged [Solved].
open office version: 3.3.0
operating system : solaris 10 ( sparc 5.10)
User avatar
Zizi64
Volunteer
Posts: 11353
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: display a file with utf-8 format with macro openOffice

Post by Zizi64 »

i'm trying to open a file with soffice GUI.
Is it a pure .txt file or it has other fileformat?

both subs still showing the Arabic characters as encrypted despite that when opening with soffice GUI the file is presented properly.
Maybe it is a missing font problem.


Can you upload your example file here?
Tibor Kovacs, Hungary; LO7.5.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
maroun
Posts: 10
Joined: Tue Mar 14, 2017 2:55 pm

Re: display a file with utf-8 format with macro openOffice

Post by maroun »

attached is the file.

when I open it via the soffice gui when I define character set to utf-8 in ascii filter options in window prompt it is displaying correctly.

the macro is still showing them as encrypted.
open office version: 3.3.0
operating system : solaris 10 ( sparc 5.10)
User avatar
Zizi64
Volunteer
Posts: 11353
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: display a file with utf-8 format with macro openOffice

Post by Zizi64 »

attached is the file.
There is not any attached file in your posts of this thread. The file size limit is 128 KiB in this Forum. You can share the larger files with a free file sharing service (like the Google drive)
Tibor Kovacs, Hungary; LO7.5.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
maroun
Posts: 10
Joined: Tue Mar 14, 2017 2:55 pm

Re: display a file with utf-8 format with macro openOffice

Post by maroun »

the file attached below.

the file format is utf8
Attachments
test.avi.utf8.txt
file
(598 Bytes) Downloaded 251 times
open office version: 3.3.0
operating system : solaris 10 ( sparc 5.10)
User avatar
Zizi64
Volunteer
Posts: 11353
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Display a file with utf-8 format with macro OpenOffice

Post by Zizi64 »

Open the .txt file with a pure text editor.
I Just copy-pasted the text from the Notepad into the LibreOffice 4.4.7:
UTF8.png
Tibor Kovacs, Hungary; LO7.5.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
maroun
Posts: 10
Joined: Tue Mar 14, 2017 2:55 pm

Re: Display a file with utf-8 format with macro OpenOffice

Post by maroun »

i'm using open office 3.3 on solaris sparc 5.10 when I open it via soffice it still open encrypted.

the file that I sent you is converted via iconv to utf8 . in windows I can display the charcters but in solaris via soffice no.

attached the image of the soffice
Attachments
image1.PNG
open office version: 3.3.0
operating system : solaris 10 ( sparc 5.10)
User avatar
karolus
Volunteer
Posts: 1158
Joined: Sat Jul 02, 2011 9:47 am

Re: Display a file with utf-8 format with macro OpenOffice

Post by karolus »

sorry, there is absolutly no problem with:

Code: Select all

sub test

oDoc = ThisComponent

url= ConvertToUrl ("/u/batch/test.utf8")

other_Doc = starDesktop.loadComponentFromURL( url, "_blank", 0, array() )

End sub
AOO4, Libreoffice 6.1 on Rasbian OS (on ARM)
Libreoffice 7.4 on Debian 12 (Bookworm) (on RaspberryPI4)
Libreoffice 7.6 flatpak on Debian 12 (Bookworm) (on RaspberryPI4)
User avatar
Zizi64
Volunteer
Posts: 11353
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Display a file with utf-8 format with macro OpenOffice

Post by Zizi64 »

i'm using open office 3.3
That is a very-very old version...
Tibor Kovacs, Hungary; LO7.5.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
User avatar
Sébastien C
Posts: 111
Joined: Mon Jan 04, 2010 5:06 pm
Location: Meymac, France

Re: Display a file with utf-8 format with macro OpenOffice

Post by Sébastien C »

Hello everyone
If I may ... Two solutions

Code: Select all

Sub ReadEncodedText1()
 Dim props(1) As New com.sun.star.beans.PropertyValue
 Dim      url As String

 url = convertToURL("/u/batch/test.utf8")

 props(0).Name = "FilterName"    : props(0).Value = "Text (encoded)"
 props(1).Name = "FilterOptions" : props(1).Value = "UTF8,LF"

 oDoc = StarDesktop.loadComponentFromURL(url, "_blank", 0, props())
End Sub
and

Code: Select all

Sub ReadEncodedText2()
 Dim  myTextFile As Object,  sf As Object, fileStream As Object
 Dim aLineOfText As String, url As String

 url = convertToUrl ("/u/batch/test.utf8")

  sf = createUnoService("com.sun.star.ucb.SimpleFileAccess")

 On Error Goto fichierKO

             fileStream = sf.openFileRead(url)
             myTextFile = createUnoService("com.sun.star.io.TextInputStream")
 myTextFile.InputStream = fileStream
    myTextFile.Encoding = "UTF-8"

 Do while not myTextFile.IsEOF
  aLineOfText = myTextFile.readLine
  msgBox(aLineOfText)
 Loop

 fileStream.closeInput : myTextFile.closeInput

 On Error Goto 0
 Exit Sub

 FichierKO:
 Resume FichierKO2

 FichierKO2:
 On Error Resume Next
 msgBox("File read error !", 16)

 fileStream.closeInput : myTextFile.closeInput
 On Error Goto 0
End Sub
Enjoy !
:D
LibreOffice v. 7.3.2.2, under GNU-Linux Mint and, in virtualization and just for tests, LibreOffice v. 7.3.2.2 an OpenOffice v. 4.1.12 under M$-W 10 :ouch: .
maroun
Posts: 10
Joined: Tue Mar 14, 2017 2:55 pm

Re: Display a file with utf-8 format with macro OpenOffice

Post by maroun »

Hello sebastien

I tried the first sub it still scrambling the characters.

do you have any idea on how to display in macro the image attached below.
Attachments
image2.PNG
open office version: 3.3.0
operating system : solaris 10 ( sparc 5.10)
maroun
Posts: 10
Joined: Tue Mar 14, 2017 2:55 pm

Re: Display a file with utf-8 format with macro OpenOffice

Post by maroun »

Hi sebastien;


i'm getting them as per your first sub as showing below in the image. any idea on how to progress more and get the Arabic words
Attachments
image10.PNG
open office version: 3.3.0
operating system : solaris 10 ( sparc 5.10)
User avatar
Sébastien C
Posts: 111
Joined: Mon Jan 04, 2010 5:06 pm
Location: Meymac, France

Re: Display a file with utf-8 format with macro OpenOffice

Post by Sébastien C »

Sorry, but this code works well at home. And I also agree with “Zizi64” that your softwares are a bit prehistorics ;)

I have no idea to make you display your dialog box
BUT
It seems that it is your default font that handles very badly the UTF8 ...

Start by locating a font that, since OpenOffice, handles Arabic characters. Let's call it “DejaVu Serif”. Then, try to correct the right line by:

Code: Select all

props(1).Name = "FilterOptions" : props(1).Value = "UTF8,CRLF,DejaVu Serif,en-CA"
In other words, you force
  • UTF8 : general encoding
  • CRLF : end lines encoding
  • DejaVu Serif : The font
  • En-CA : The language of the file
Is it better :?:
LibreOffice v. 7.3.2.2, under GNU-Linux Mint and, in virtualization and just for tests, LibreOffice v. 7.3.2.2 an OpenOffice v. 4.1.12 under M$-W 10 :ouch: .
maroun
Posts: 10
Joined: Tue Mar 14, 2017 2:55 pm

Re: Display a file with utf-8 format with macro OpenOffice

Post by maroun »

thanks sebastien the first one work well but i had problem with the file. thanks a lot for your time.
open office version: 3.3.0
operating system : solaris 10 ( sparc 5.10)
maroun
Posts: 10
Joined: Tue Mar 14, 2017 2:55 pm

Re: Display a file with utf-8 format with macro OpenOffice

Post by maroun »

with this sub the issue was fixed.


sub test5 ()
cFile="/u/batch/test.utf8"
rem oDoc = ThisComponent
url = ConvertToUrl (cFile)

Dim FileProperties(1) As New com.sun.star.beans.PropertyValue


FileProperties(0).Name = "FilterName"
FileProperties(0).Value ="Text (encoded)"
FileProperties(1).Name = "FilterOptions"
FileProperties(1).Value ="UTF8,LF"

oDoc = starDesktop.loadComponentFromURL(url, "_blank", 0, FileProperties())
open office version: 3.3.0
operating system : solaris 10 ( sparc 5.10)
User avatar
Villeroy
Volunteer
Posts: 31269
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Display a file with utf-8 format with macro OpenOffice

Post by Villeroy »

Sébastien C wrote:Sorry, but this code works well at home. And I also agree with “Zizi64” that your softwares are a bit prehistorics ;)

I have no idea to make you display your dialog box
BUT
It seems that it is your default font that handles very badly the UTF8 ...

Start by locating a font that, since OpenOffice, handles Arabic characters. Let's call it “DejaVu Serif”. Then, try to correct the right line by:

Code: Select all

props(1).Name = "FilterOptions" : props(1).Value = "UTF8,CRLF,DejaVu Serif,en-CA"
In other words, you force
  • UTF8 : general encoding
  • CRLF : end lines encoding
  • DejaVu Serif : The font
  • En-CA : The language of the file
Is it better :?:
Sébastien,
How/where did you find the right filter options?
 Edit: OK. I found out by opening the file as file type "Text - Choose Encoding" and then inspect ThisComponent.Args() 
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
User avatar
Sébastien C
Posts: 111
Joined: Mon Jan 04, 2010 5:06 pm
Location: Meymac, France

Re: Display a file with utf-8 format with macro OpenOffice

Post by Sébastien C »

As you know I am French and I read easily the fr-FR...

And in FR, we have the incredible chance to have the Bible written in fr ... Even if Andrew Pitonyak is a reference, it's MUCH MORE organized, laid out, structured.

It is very easy to find this text in pirated PDF in a relatively recent version, but I will not give the link here. The price of the rights of the book is totally donated to the community and the authors do not receive any money.

I did a search G***** with (in quotes) "UTF8" and "com.sun.star.beans.PropertyValue".

It brought me back to Bernard Marcelly's bible, a page that G***** gives to read.

But if you want the list of ALL filters, then Andrew Pitonyak is better ... On page 218 of the PDF, for example.

8-)
LibreOffice v. 7.3.2.2, under GNU-Linux Mint and, in virtualization and just for tests, LibreOffice v. 7.3.2.2 an OpenOffice v. 4.1.12 under M$-W 10 :ouch: .
Post Reply