[SOLVED] How do I test for an external file?

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
CarlB
Posts: 2
Joined: Tue Jul 09, 2019 8:34 pm

[SOLVED] How do I test for an external file?

Post by CarlB »

I would like to test for the existing of an external file from within a cell formulae e.g.

if c:\users\carl\tst.txt exists then output "Yes" otherwise output ""

Is this possible in OO Calc?

Any help much appreciated
Last edited by MrProgrammer on Thu Aug 01, 2019 8:30 pm, edited 3 times in total.
Reason: Moved from Calc forum to OpenOffice Basic, Python, BeanShell, JavaScript
OpenOffice 4.1.6 on Windows 10 64-bit
User avatar
RusselB
Moderator
Posts: 6646
Joined: Fri Jan 03, 2014 7:31 am
Location: Sarnia, ON

Re: How do I test for an external file?

Post by RusselB »

Welcome to the Forums.
Based on the wording of your request, while Calc might be able to do this, I believe it would require a macro.
I'm not familiar with macros, but a quick Google search brought up https://stackabuse.com/python-check-if- ... ry-exists/
As this is a Python code, it (to my knowledge) is compatible with Calc, and thus may be what you are wanting.
OpenOffice 4.1.7, LibreOffice 7.0.1.2 on Windows 7 Pro, Ultimate & Windows 10 Home (2004)
If you believe your problem has been resolved, please go to your first post in this topic, click the Edit button and add [Solved] to the beginning of the Subject line.
User avatar
Zizi64
Volunteer
Posts: 11359
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: How do I test for an external file?

Post by Zizi64 »

You can test it with a macro written in the Basic. The Basic has IDE in the AOO/LO. The usage of the Basic maybe easier than the Python for a beginner.

Code: Select all

REM  *****  BASIC  *****
Option explicit

Function MyFileExists(sFullPath as string) as boolean

 dim sFileUrl as string
 
	sFileURL = ConvertToUrl(sFullPath)	
	
	If FileExists(sFileUrl) then 
		MyFileExists = True
	else 
		MyFileExists = False
	end if
End function
Copy the code into a Module of the MyMacros, and then you will able to call the function from a cell of any spreadsheet document.
Tibor Kovacs, Hungary; LO7.5.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
CarlB
Posts: 2
Joined: Tue Jul 09, 2019 8:34 pm

Re: How do I test for an external file?

Post by CarlB »

That's great thanks
OpenOffice 4.1.6 on Windows 10 64-bit
Post Reply