Viewing document files

Post

Posted
Rating:
#1 (In Topic #323)
Regular
bill-lancaster is in the usergroup ‘Regular’
 DocumentViewer and the gb.pdf components are OK for .pdf files.
What is the best way to view the other document types (.doc, .ODT, .txt)?
Is there a way, for example to display a .doc file in imageview?
Online now: No Back to the top

Post

Posted
Rating:
#2
Avatar
Expert
Quincunxian is in the usergroup ‘Expert’
Hi Bill,
Do you need to open the document "in program" or just open the document externally for review ?
If just for a review, you can use the Linux application xdg-open {document path}

xdg-open will open most document types within their native applications and is installed on most common Linux distros. You can install easily it if it's not on yours.

From within Gambas you would use something like this:

Code (gambas)

  1.  Exec ["xdg-open", SelectedPath]
  2.  

It will also open a web link in your default browser but the path must have the http header included.
just using www.someaddress.com won't work.

For example, using xdg-open with the path:
"Google" & "{search term}+{search term}+…
will open Google in your browser with the results of the search terms that you entered.

Cheers - Quin.
I code therefore I am
Online now: No Back to the top

Post

Posted
Rating:
#3
Avatar
Guru
cogier is in the usergroup ‘Guru’
'xdg' is being deprecated https://github.com/github/hub/issues/1473

If you add the 'gb.desktop' component you can use

Code (gambas)

  1. Desktop.Open(User.home &/ "MyFile.odt")
If you want to display something like an .odt or .doc then I don't thing Gambas can help you read the files but LibreOffice can convert those files to a text file, below converts the spreadsheet file 'temp.ods' to a 'csv' file: -

Code (gambas)

  1. Dim sData as String
  2. Dim sFolder as String = User.Home 'Change as necessary. The file name below in this case is temp.ods but could be Hello.xls
  3.  
  4. Shell "cd " & sFolder & " && " & "libreoffice --headless --convert-to csv temp.ods" Wait
  5. sData = File.Load(sFolder &/ "temp.csv")
  6.  
  7. 'You now have all the data from temp.ods in your variable sData!
  8.  

NOTE:  If LibreOffice is open then this trick wont work!
Online now: No Back to the top

Post

Posted
Rating:
#4
Regular
bill-lancaster is in the usergroup ‘Regular’
Thank you Quincunxian, just what I needed.
Online now: No Back to the top
1 guest and 0 members have just viewed this.