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

Creating a macro - Writing a Script - Using the API

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

Postby maroun » Wed Mar 15, 2017 11:42 am

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)
maroun
 
Posts: 10
Joined: Tue Mar 14, 2017 2:55 pm

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

Postby Zizi64 » Wed Mar 15, 2017 1:32 pm

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; LibreOffice4.4.7 - Portable versions: LO3.3.0-LO5.3.1 and AOO4.1.3; on Win7x64Prof.
Please, edit the topic's initial post, and add the word "[Solved]" at the beginning of the subject line - if your problem has been solved.
User avatar
Zizi64
Volunteer
 
Posts: 4976
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

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

Postby maroun » Wed Mar 15, 2017 2:42 pm

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)
maroun
 
Posts: 10
Joined: Tue Mar 14, 2017 2:55 pm

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

Postby Zizi64 » Wed Mar 15, 2017 3:26 pm

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; LibreOffice4.4.7 - Portable versions: LO3.3.0-LO5.3.1 and AOO4.1.3; on Win7x64Prof.
Please, edit the topic's initial post, and add the word "[Solved]" at the beginning of the subject line - if your problem has been solved.
User avatar
Zizi64
Volunteer
 
Posts: 4976
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

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

Postby maroun » Wed Mar 15, 2017 3:31 pm

the file attached below.

the file format is utf8
Attachments
test.avi.utf8.txt
file
(598 Bytes) Downloaded 16 times
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

Postby Zizi64 » Wed Mar 15, 2017 3:53 pm

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; LibreOffice4.4.7 - Portable versions: LO3.3.0-LO5.3.1 and AOO4.1.3; on Win7x64Prof.
Please, edit the topic's initial post, and add the word "[Solved]" at the beginning of the subject line - if your problem has been solved.
User avatar
Zizi64
Volunteer
 
Posts: 4976
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

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

Postby maroun » Wed Mar 15, 2017 4:01 pm

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)
maroun
 
Posts: 10
Joined: Tue Mar 14, 2017 2:55 pm

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

Postby karolus » Wed Mar 15, 2017 4:08 pm

sorry, there is absolutly no problem with:

Code: Select all   Expand viewCollapse view
sub test

oDoc 
= ThisComponent

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

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

End sub
AOO4, Libreoffice - 5.1 … 5.3.2.2 on Linux Mint17
User avatar
karolus
Volunteer
 
Posts: 842
Joined: Sat Jul 02, 2011 9:47 am

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

Postby Zizi64 » Wed Mar 15, 2017 4:11 pm

i'm using open office 3.3

That is a very-very old version...
Tibor Kovacs, Hungary; LibreOffice4.4.7 - Portable versions: LO3.3.0-LO5.3.1 and AOO4.1.3; on Win7x64Prof.
Please, edit the topic's initial post, and add the word "[Solved]" at the beginning of the subject line - if your problem has been solved.
User avatar
Zizi64
Volunteer
 
Posts: 4976
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

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

Postby Sébastien C » Wed Mar 15, 2017 4:48 pm

Hello everyone
If I may ... Two solutions

Code: Select all   Expand viewCollapse view
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   Expand viewCollapse view
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 5.x under GNU-Linux Mageia 5.0 and M$-W XP
User avatar
Sébastien C
 
Posts: 21
Joined: Mon Jan 04, 2010 5:06 pm
Location: Meymac, France

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

Postby maroun » Wed Mar 15, 2017 5:21 pm

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

Postby maroun » Wed Mar 15, 2017 5:28 pm

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)
maroun
 
Posts: 10
Joined: Tue Mar 14, 2017 2:55 pm

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

Postby Sébastien C » Wed Mar 15, 2017 5:56 pm

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   Expand viewCollapse view
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 5.x under GNU-Linux Mageia 5.0 and M$-W XP
User avatar
Sébastien C
 
Posts: 21
Joined: Mon Jan 04, 2010 5:06 pm
Location: Meymac, France

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

Postby maroun » Wed Mar 15, 2017 6:10 pm

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

Postby maroun » Wed Mar 15, 2017 6:15 pm

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)
maroun
 
Posts: 10
Joined: Tue Mar 14, 2017 2:55 pm

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

Postby Villeroy » Wed Mar 15, 2017 6:18 pm

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   Expand viewCollapse view
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 16.04, OpenOffice 4.x & LibreOffice 5.x
User avatar
Villeroy
Volunteer
 
Posts: 23592
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

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

Postby Sébastien C » Wed Mar 15, 2017 8:06 pm

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 5.x under GNU-Linux Mageia 5.0 and M$-W XP
User avatar
Sébastien C
 
Posts: 21
Joined: Mon Jan 04, 2010 5:06 pm
Location: Meymac, France


Return to Macros and UNO API

Who is online

Users browsing this forum: No registered users and 4 guests