7

How to add hotlink to QGIS? I saw this but had some problem. I want to open network location like \\fileserver\filefolder\file1.excel but it ends with error.

Edit: The network location is stored in a column of the table eg. URL column contains URL value for each attribute. Different row has different URL.

kinkajou
  • 4,406
  • 11
  • 52
  • 97

2 Answers2

8

This way it works for me on Windows and Qgis 1.8.0:

Create a point shapefile with a field url of type string. Add a point and fill the url field with

\\<host>\<path>\<file>.xls 

without any blanks or quotation marks unless you have blanks in folder and filenames. Don't forget to save the layer, end leave edit mode.

In the layers properties, create a new action of type Generic , name it open and add

cmd /c [% "url" %] 

as action.

Select the Action icon, move the mouse over the point and click to open the excel sheet. The Excel sheet should have the standard .xls extension.

AndreJ
  • 76,698
  • 5
  • 86
  • 162
  • tried it but my path has space i.e. my file name has space "test test12.xls" it opens a command window and nothing happens – kinkajou Sep 07 '12 at 12:00
  • 2
    It might work if you put the whole path inside quotes. Just guessing though. – Rayner Sep 07 '12 at 12:33
  • 1
    Just tested: "\fileserver\filefolder\file 1.xls" (with the quotation marks!) in the shapefile field works. – AndreJ Sep 07 '12 at 12:35
  • Glad I could help. Please vote my comment up if you think it was useful. – Rayner Sep 07 '12 at 16:45
  • @Rayner its helpful but my url is one of the column of table – kinkajou Sep 09 '12 at 09:47
  • I'm not quiet sure what you mean: Path-to-file has to be build of column(field) name and content of the field? That could be done in some way by field calculator. Can you add a screenshot of the table? – AndreJ Sep 09 '12 at 13:55
  • At last the solution : cmd /c "[% "URL_TSSR" %]". Using generic type action. See "" outside too. – kinkajou Sep 13 '12 at 11:14
2

I'd use python. After reading a blog post from Tim Sutton at linfiniti [1] I learned you can use python in actions:

eg something along those lines:

from pywin32.client import Dispatch
xl = Dispatch('Excel.Application')
wb = xl.Workbooks.Open('C:\\Documents and Settings\\GradeBook.xls')

taken from another post [2]

[1] http://linfiniti.com/2012/03/a-python-layer-action-to-open-a-wikipedia-page-in-qgis/

[2] https://stackoverflow.com/questions/247724/how-can-i-launch-an-instance-of-an-application-using-python

nickves
  • 11,519
  • 3
  • 42
  • 75
  • 1
    I don't know if it is excel or pdf as I have mentioned in the question it can be pdf or any other file too. I use it with mapinfo currently. It's easy in Mapinfo but I am not able to find this feature in Qgis easy. – kinkajou Sep 10 '12 at 01:52