i'm trying to open a file with soffice GUI.
both subs still showing the Arabic characters as encrypted despite that when opening with soffice GUI the file is presented properly.
attached is the file.
sub test
oDoc = ThisComponent
url= ConvertToUrl ("/u/batch/test.utf8")
other_Doc = starDesktop.loadComponentFromURL( url, "_blank", 0, array() )
End sub
i'm using open office 3.3
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
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
props(1).Name = "FilterOptions" : props(1).Value = "UTF8,CRLF,DejaVu Serif,en-CA"
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
Edit: OK. I found out by opening the file as file type "Text - Choose Encoding" and then inspect ThisComponent.Args() |
Users browsing this forum: No registered users and 2 guests