Ask Your Question
0

Unable to load file on network from Linux [closed]

asked 2013-12-10 12:47:37 +0200

jheath gravatar image

updated 2014-03-06 17:47:08 +0200

I am trying to load a .csv file over the network, copy some data out of it to put into the current spreadsheet, then close it. The code I'm using (simplified somewhat) is the following:

Dim fileURL As String
Dim fileProperties(1) As New com.sun.star.beans.PropertyValue
Dim oCSVFile As Object
Dim allData As Object

fileURL = "file://abc.def.org/server/Data/Finance/COA Master.csv"

' Open CSV file
fileProperties(0).Name = "FilterName"
fileProperties(0).Value = "Text - txt - csv (StarCalc)"
' Options: comma separator, double-quotes delimiter, system encoding (UTF-8),
'   start with first line, 6 cols text (use 9 instead of 2 to ignore a column)
fileProperties(1).Name = "FilterOptions"
fileProperties(1).Value = "44,34,76,1,1/2/2/2/3/2/4/2/5/2/6/2"
If FileExists(fileURL) Then
    MsgBox "File exists"
End If
oCSVFile = StarDesktop.loadComponentFromURL(fileURL, "_blank", 0, fileProperties())

' Get data from the CSV file (main sheet)
allData = oCSVFile.Sheets(0).getCellRangeByName("A1:F100").getDataArray
' do something with the data
oCSVFile.close(true)

The file is out on a DFS share on a Windows Server 2012 machine. This code works fine on a Windows machine, but when I tried it on a Linux machine, the loadComponentFromURL returned a NULL for oCSVFile - but no error. Then obviously the following reference to oCSVFile.Sheets is going to fail. Note that right before the load command, I check to see that the file exists, and it does exist, so Linux is able to see the file out on the network.

Furthermore, if I run the following test:

Dim fileURL As String
Dim sStr As String
fileURL = "file://abc.def.org/server/Data/Finance/COA Master.csv"
Open fileURL For Input As #1
Line Input #1, sStr
MsgBox sStr
Line Input #1, sStr
MsgBox sStr
Line Input #1, sStr
MsgBox sStr
Line Input #1, sStr
MsgBox sStr
Close #1

it can read the contents of the file just fine. So it is not a networking problem, and it is not an access to the file problem. What other options are there?


Update: I still have not solved this problem. Note that the code works fine on Windows computers. Also, if I put the .csv file in a local directory on the Linux computer, and access it from there, e.g.

fileURL = "file:///home/jheath/Bureau/COA Master.csv"

then that works fine. So the code for loading ... (more)

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by Alex Kemp
close date 2016-02-20 06:13:48.193035

Comments

Note that file:///abc.def.org/ should fail as the third slash is used to separate the hostname component from the path (localhost is suppressed, thus the third slash for local files). It is possible the space in the host/path/file combination is causing problems e.g., rename COA Master.csv to COA_Master.csv and see if the problem persists. The fileURL variable is likely going to have to be set via concatenation to include the surrounding quotation marks to cater for URLs with spaces. Also, how are the DFS shares being mounted on the Linux client? Evidently Samba is not required for DFS shares and I am not clear to what degree CIFS mounting may have an issue with this type of share (in LO).

oweng gravatar imageoweng ( 2014-03-07 00:10:23 +0200 )edit

That was a really good thought, OWENG! Of course my URL wasn't a "real" URL because of the space. Unfortunately, I have tried using both "COA%20Master.csv" and renaming the file on the server to "COA_Master.csv", and still neither of these works. They both pass the FileExists check, so they both seem to "see" the file out there, but unfortunately the loadComponentFromURL call still returns a Null.

jheath gravatar imagejheath ( 2014-03-07 07:59:58 +0200 )edit

I'm not a Linux expert, but I believe I am using Samba to access this share. To make the initial connection, I type "smb://abc.def.org/server" in the address bar, entering credentials for the connection. And yet I have been able to use a simple "file://abc.def.org/..." for access, both under Windows and Linux, until this problem. I really would like to have the same code on both Windows and Linux, so I wouldn't be real keen on some special syntax (like "smb://").

jheath gravatar imagejheath ( 2014-03-07 08:02:17 +0200 )edit

1 Answer

Sort by » oldest newest most voted
2

answered 2014-03-07 08:55:51 +0200

jheath gravatar image

Thanks to the comments from OWENG, I now have come up with a solution! I think it did really want "smb://" to access the file, but I didn't want to hard wire that in, because then the file accesses wouldn't work on Windows. Fortunately there is a function ConvertToURL, which makes sure that your file path is a valid URL. And if I run this function on my fileURL, guess what it does on Linux? It changes the "file:" at the beginning to "smb:"! And then my .csv file magically opens up!

So the solution to this problem (still to be tested further, but I'm pretty sure this will work) is to use the function ConvertToURL, even if we pretty much already have a URL, to make sure any additional magic happens in the URL before we open the file, like so:

fileURL = "file://abc.def.org/server/Data/Finance/COA Master.csv"
fileURL = ConvertToURL(fileURL)
...
oCSVFile = StarDesktop.loadComponentFromURL(fileURL, "_blank", 0, fileProperties())

Thanks for your help! Vive la communauté!

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2013-12-10 12:47:37 +0200

Seen: 999 times

Last updated: Mar 07 '14