At 00:18 22/03/2013 +0100, Miroslaw Zalewski [Apologies for the lack
of your l-kreska in my plain-text e-mail] wrote:
Some time ago I had to write a function that will display filename
of current Calc workbook. After some Googling and trial and error I
came up with this monster:
=RIGHT(MID(CELL("FILENAME";A1);2;
FIND("'#";CELL("FILENAME";A1))-2);LEN(MID(CELL("FILENAME";A1);2;
FIND("'#";CELL("FILENAME";A1))-2))-FIND("$$$";SUBSTITUTE(
MID(CELL("FILENAME";A1);2;FIND("'#";CELL("FILENAME";A1))-2);"/";"$$$";
LEN(MID(CELL("FILENAME";A1);2;FIND("'#";CELL("FILENAME";A1))-2)) -
LEN(SUBSTITUTE(MID(CELL("FILENAME";A1);2;FIND("'#";CELL("FILENAME";A1))-2);"/";"")))))
(Of course it could be shorter if only temporary cells were allowed;
you can clearly see that much of this function is multiplication of
some formula set.)
I'm not sure what you mean by "if only temporary cells were allowed":
they surely are! You can put intermediate calculations into some
convenient area outside your print ranges - possibly even in hidden
cells or on another sheet. In (say) X1, enter:
=CELL("FILENAME")
Note that the second parameter for the CELL() function appears - at
least in this case - to be optional; the function presumably defaults
to the current cell.
In X2, enter:
=FIND("'#";X1)-2
and in X3 enter:
=MID(X1;2;X2)
Then your final formula - in the required cell - reduces to:
=RIGHT(X3;X2-FIND("$$$";SUBSTITUTE(X3;"/";"$$$";X2-
LEN(SUBSTITUTE(X3;"/";"")))))
which would be somewhat easier to understand and debug. (It's
probably capable of further simplification.)
But how about a simpler solution - using this time only two cells for
intermediate values?
In X1, enter:
=CELL("FILENAME")
as before.
In X2, enter:
=SEARCH("/[^/]+'#";X1)+1
and in the required cell:
=MID(X1;X2;FIND("'#";X1)-X2)
The regular expression in the SEARCH() function matches a slash
followed by any number of characters (at least one) not including a
slash followed by your single-quote hash-mark combination,
effectively finding the beginning of the file name, the FIND()
function reference then finds its end, and the MID() function picks
out the required file name itself.
Note that for this to work, you need to have the option ticked at
Tools | Options... | LibreOffice Calc | Enable regular expressions in formulas.
I trust this helps.
Brian Barker
--
For unsubscribe instructions e-mail to: users+help@global.libreoffice.org
Problems? http://www.libreoffice.org/get-help/mailing-lists/how-to-unsubscribe/
Posting guidelines + more: http://wiki.documentfoundation.org/Netiquette
List archive: http://listarchives.libreoffice.org/global/users/
All messages sent to this list will be publicly archived and cannot be deleted
Context
Privacy Policy |
Impressum (Legal Info) |
Copyright information: Unless otherwise specified, all text and images
on this website are licensed under the
Creative Commons Attribution-Share Alike 3.0 License.
This does not include the source code of LibreOffice, which is
licensed under the Mozilla Public License (
MPLv2).
"LibreOffice" and "The Document Foundation" are
registered trademarks of their corresponding registered owners or are
in actual use as trademarks in one or more countries. Their respective
logos and icons are also subject to international copyright laws. Use
thereof is explained in our
trademark policy.