| View previous topic :: View next topic |
| Author |
Message |
fb314 General User

Joined: 14 Feb 2005 Posts: 8 Location: Nice (France)
|
Posted: Fri Dec 09, 2005 6:24 am Post subject: using a name from another file |
|
|
Hi,
let be in a file F2. If I want to reference the cell A1 of sheet 'sheet1' of file 'F1', I can write
| Code: | | 'file:/tmp/F1.ods'#$sheet1.A1 |
now, I assign the name "dummy" to this cell A1. What's the syntax to use this name in an external file ? I've tried
| Code: | 'file:/tmp/F1.ods'#$sheet1.dummy
'file:/tmp/F1.ods'#$sheet1.'dummy'
'file:/tmp/F1.ods'#$'dummy' |
and none works. What's the good syntax ? |
|
| Back to top |
|
 |
noranthon Super User

Joined: 07 Jul 2005 Posts: 3318
|
Posted: Tue Dec 13, 2005 10:21 pm Post subject: |
|
|
I've just managed to alter a DDE link from a reference to the cell address to a reference to the name of the cell as follows:
=DDE("soffice";"/home/terry/Work/Tables.ods";"DateCalcs") - DateCalcs being the name of the cell.
On principle, you should not have to use a sheet name or number because a cell/range name is unique in a spreadsheet document.
Like you, I cannot get it to work with the format you are using. I have found that references to named cells do not even work in other sheets in the same document. |
|
| Back to top |
|
 |
Villeroy Super User


Joined: 04 Oct 2004 Posts: 10065 Location: Germany
|
Posted: Wed Dec 14, 2005 2:33 am Post subject: |
|
|
| noranthon wrote: | I've just managed to alter a DDE link from a reference to the cell address to a reference to the name of the cell as follows:
=DDE("soffice";"/home/terry/Work/Tables.ods";"DateCalcs") - DateCalcs being the name of the cell.
On principle, you should not have to use a sheet name or number because a cell/range name is unique in a spreadsheet document.
Like you, I cannot get it to work with the format you are using. I have found that references to named cells do not even work in other sheets in the same document. |
Sorry, the latter is not true:
Without sheet-name, a range-name refers to the specified range in each sheet (eg. $A$1:$C$3).
$Sheet1.$A$1:$C$3 always refers to the top left 3x3-square on sheet1.
You can even use relative sheet-addressing:
When $Sheet2.$C$3 is the active cell while you define a name like:
prevShTopLeft referring to Sheet1.A1:B2
This name refers to all top-left precedents on the previous sheet.
If there is no previous sheet, then it refers to the last one.
Handle relative addressing with care. It's powerful.  |
|
| Back to top |
|
 |
noranthon Super User

Joined: 07 Jul 2005 Posts: 3318
|
Posted: Thu Dec 15, 2005 1:27 am Post subject: using a name from another file |
|
|
I'm not sure I understand the previous post. In the file, I was thinking about, Sheet1 is named "Main" and Sheet2 is named "Data". A cell on Main is named "DateCalcs". (It contains a formula which gets a date a specified number of days from another date.) If I enter on "Data" the formula "=DateCalcs", I get "0" (zero). If I try anything else, such as "=$Main.DateCalcs", I get "#NAME?" On the other hand, a formula which uses a rangename from that sheet produces the desired result.
Error messages also result, as the originator of this subject indicates, when you try to refer to a range by name from another document (unless you use a DDE link). It is not so with other software. The spreadsheet I previously used automatically substituted range names for cell/range addresses in formulas, wherever they occurred. |
|
| Back to top |
|
 |
Villeroy Super User


Joined: 04 Oct 2004 Posts: 10065 Location: Germany
|
Posted: Thu Dec 15, 2005 6:47 am Post subject: |
|
|
Sorry, I was talking about the definition of names (Ctrl+F3) in Calc, rather
than usage of named ranges in Excel. A Calc-name "can remember it's fixed
star at birth"(merry christmas, meaning: it's relative position to the
currently active cell *and* the relative position of currently active sheet).
For the API-aware readers: I'm talking about com.sun.star.sheet.XNamedRange.getReferencePosition
In Calc you can define range-names like:
$Main.$A$1:C$3 ->Name refers to A1:C3 on sheet Main
Main.$A$1:C$3 ->Name refers to A1:C3 on the (next/previous/Nth offest) sheet if Main was the (next/previous/Nth offset) sheet when the name was created.
$A$1:$C3 -> Name refers to A1:C3 on any sheet.
Sheet-positions can be relative or absolute just like columns and rows.
Relative sheet-positions are not known in Excel.
In Excel version>8 you may refer to a defined name on another sheet. I don't know. My Excel 8 replaces the sheet-name with the workbook-name and "$Sheet1" is an invalid sheet-identifier.
If you really need this kind of named reference in Calc:
=INDIRECT(ADDRESS(ROW(VectorX);COLUMN(VectorX)))
In this example VectorX is an absolute reference to a cellrange in another sheet. The function returnes the value of the first cell from the address of VectorX on *this* sheet.
The same with address of VectorX on a sheet named "Times":
=INDIRECT("Times."&ADDRESS(ROW(VectorX);COLUMN(VectorX)))
Unfortunately Calc's INDIRECT() does not work in array-context, but you can refer to the second cell of VectorX:
=INDIRECT(ADDRESS(ROW(VectorX)+1;COLUMN(VectorX)))
'+1' could be a calculated offset, depending on your needs.
Another approach if you want to drag/copy the reference from $G$12 downward or to the right:
=INDEX(INDIRECT("Times."&ADDRESS(ROW(VectorX);COLUMN(VectorX))&":"&ADDRESS(ROWS(VectorX);COLUMNS(VectorX)));ROW()-ROW($G$12)+1;COLUMN()-COLUMN($G$12)+1)
Unfortunately Excel uses "!" as sheet-separator, but you want to use the
INDIRECT()- addressing in both programs:
Define name "ShSep" referring to =MID(ADDRESS(1;1;1;"Foo");4;1)
(Sheet "Foo" may exist or not)
=INDIRECT("Times"&ShSep&ADDRESS(ROW(VectorX);COLUMN(VectorX)))
This will use 'Times.' as sheet-prefix in Calc and 'Times!' in Excel.
| Quote: |
The spreadsheet I previously used automatically substituted range names for cell/range addresses in formulas,
wherever they occurred. |
That sounds very complicated. What if more than one name intersects with the
referred address? Does this replace a relative address as well?
The spreadsheet I currently prefer, offers insertion of range names while
typing a formula since it can not decide if I refer to the cell A1234 or a
range name which happens to be at that position. |
|
| Back to top |
|
 |
noranthon Super User

Joined: 07 Jul 2005 Posts: 3318
|
Posted: Thu Dec 15, 2005 6:48 pm Post subject: using a name from another file |
|
|
I believe we're discussing the use of range names in Calc. I've never used Excel and have no wish to do so. The point is that the range name appears to have limited uses, compared to legitimate expectations and, incidentally, compared to other software.
Since any range name is unique to a file, it seems that it should be possible to use the name anywhere in the file and, for that matter, in other files, as a reference to the cell or cells so named.
We are not talking about the cell/range address, which is freely useable so long as 1. the file (if necessary) is identified; 2. the sheet (if necessary) is specified and the column and row numbers are stated. We are simply talking about the use which may be made of a defined range name. |
|
| Back to top |
|
 |
Villeroy Super User


Joined: 04 Oct 2004 Posts: 10065 Location: Germany
|
Posted: Sat Dec 17, 2005 5:31 am Post subject: Re: using a name from another file |
|
|
| fb314 wrote: | Hi,
let be in a file F2. If I want to reference the cell A1 of sheet 'sheet1' of file 'F1', I can write
| Code: | | 'file:/tmp/F1.ods'#$sheet1.A1 |
now, I assign the name "dummy" to this cell A1. What's the syntax to use this name in an external file ? I've tried
| Code: | 'file:/tmp/F1.ods'#$sheet1.dummy
'file:/tmp/F1.ods'#$sheet1.'dummy'
'file:/tmp/F1.ods'#$'dummy' |
and none works. What's the good syntax ? |
I can not see, in which file you defined "dummy".
-------------<dummy in F1.ods>------------------
You defined 'dummy' in F1.ods?
Then this is the only one way, I know:
=DDE("soffice";"/tmp/F1.ods";"dummy")
Caution: If "dummy" is defined in F1.ods without sheet name ($A$1) you always get A1 from first sheet.
With DDE it makes no difference if dummy is A1 or $A$1
Just in case you like dummy to have more than one cell (A1:B10) you get the whole range with DDE used as array-function:
Select 10rows/2 columns
Type =DDE("soffice";"/tmp/F1.ods";"dummy")
and confirm with Ctrl+Shift+Enter
-------------<dummy in F2.ods>------------------
Defining dummy in this file (F2.ods) gives you more flexibility:
You defined 'dummy' in this file (F2.ods), referring to something in this file(F2.ods) and you want access to the corresponding address in F1?
Name dummy refers to $anySheetHere.$A$1 or simply $A$1
=DDE("soffice";"/tmp/F1.ods";"sheet1."&ADDRESS(ROW(dummy);COLUMN(dummy))
the third paramter evaluates to string "sheet1.$A$1". If you leave out "sheet1.", you get $A$1 from first sheet in F1.ods which may be another one.
Name dummy refers to $anySheetHere.A1 or simply A1 and it was defined while A1was active:
=DDE("soffice";"/tmp/F1.ods";"sheet1."&ADDRESS(ROW(dummy);COLUMN(dummy))
Now you get another Row and Column because "dummy" is $someSheet.B2 from the viewpoint of B2. So the third paramter evaluates to string "sheet1.$B$2"
------------------------------------------------------
You can define name "dummy" in this file (F2.ods) as:
'file:/tmp/F1.ods'#$sheet1.$A$1
Always returns the content of that cell in F1.ods
-------------------
For relative addressing -which is more flexible- select A1 in current sheet of F2 and use relative address:
'file:/tmp/F1.ods'#$sheet1.A1
In B2 =dummy returnes F1.ods#$sheet1.B2
In IV65536 =dummy returnes F1.ods#$sheet1.IV65536
If you have B2 selected while defining dummy as relative 'file:/tmp/F1.ods'#$sheet1.A1 then you get an offset of one row and one column, which can be useful if you do it intentionally.
------------------ |
|
| Back to top |
|
 |
Villeroy Super User


Joined: 04 Oct 2004 Posts: 10065 Location: Germany
|
Posted: Sat Dec 17, 2005 5:43 am Post subject: |
|
|
Just another way of dummy in this file (F2.ods):
Define the names as literal strings within doublequotes.
Name dummyPath ="/tmp/F1.ods"
Name dummySheet ="$sheet1."
Name dummyURLPrefix ="'file:///tmp/F1.ods'#"
Name dummyAddress = "A1"
=DDE("soffice";dummyPath;dummySheet&dummyAddress)
=INDIRECT(dummyURLPrefix&dummySheet&dummyAddress)
INDIRECT() converts a string to a reference |
|
| Back to top |
|
 |
|