apoc.export.xls.all
Procedure APOC Full
apoc.export.xls.all(file,config) - exports whole database as xls to the provided file
Signature
apoc.export.xls.all(file :: STRING?, config :: MAP?) :: (file :: STRING?, source :: STRING?, format :: STRING?, nodes :: INTEGER?, relationships :: INTEGER?, properties :: INTEGER?, time :: INTEGER?, rows :: INTEGER?, batchSize :: INTEGER?, batches :: INTEGER?, done :: BOOLEAN?, data :: STRING?)
Output parameters
Name | Type |
---|---|
file |
STRING? |
source |
STRING? |
format |
STRING? |
nodes |
INTEGER? |
relationships |
INTEGER? |
properties |
INTEGER? |
time |
INTEGER? |
rows |
INTEGER? |
batchSize |
INTEGER? |
batches |
INTEGER? |
done |
BOOLEAN? |
data |
STRING? |
Install Dependencies
For loading XLS we’re using the Apache POI library, which works well with old and new Excel formats, but is quite large. That’s why we decided not to include it into the apoc jar, but make it an optional dependency.
These dependencies are included in apoc-xls-dependencies-4.1.0.11.jar, which can be downloaded from the releases page.
Once that file is downloaded, it should be placed in the plugins
directory and the Neo4j Server restarted.
Alternatively, you can download these jars from Maven Repository (putting them into plugins
directory as well):
Usage Examples
The examples in this section are based on the following sample graph:
CREATE (TheMatrix:Movie {title:'The Matrix', released:1999, tagline:'Welcome to the Real World'})
CREATE (Keanu:Person {name:'Keanu Reeves', born:1964})
CREATE (Carrie:Person {name:'Carrie-Anne Moss', born:1967})
CREATE (Laurence:Person {name:'Laurence Fishburne', born:1961})
CREATE (Hugo:Person {name:'Hugo Weaving', born:1960})
CREATE (LillyW:Person {name:'Lilly Wachowski', born:1967})
CREATE (LanaW:Person {name:'Lana Wachowski', born:1965})
CREATE (JoelS:Person {name:'Joel Silver', born:1952})
CREATE
(Keanu)-[:ACTED_IN {roles:['Neo']}]->(TheMatrix),
(Carrie)-[:ACTED_IN {roles:['Trinity']}]->(TheMatrix),
(Laurence)-[:ACTED_IN {roles:['Morpheus']}]->(TheMatrix),
(Hugo)-[:ACTED_IN {roles:['Agent Smith']}]->(TheMatrix),
(LillyW)-[:DIRECTED]->(TheMatrix),
(LanaW)-[:DIRECTED]->(TheMatrix),
(JoelS)-[:PRODUCED]->(TheMatrix);
The Neo4j Browser visualization below shows the imported graph:
The apoc.export.xls.all
procedure exports the whole database to an XLS file.
The following query exports the whole database to the file movies.xls
:
CALL apoc.export.xls.all("movies.xls", {});
file | source | format | nodes | relationships | properties | time | rows | batchSize | batches | done | data |
---|---|---|---|---|---|---|---|---|---|---|---|
"movies.xls" |
"database: nodes(8), rels(7)" |
"xls" |
8 |
7 |
21 |
102 |
15 |
20000 |
1 |
TRUE |
NULL |
movies.xls
contains individual sheets for each node label and relationship type.
In this case, it contains the following sheets:
-
Movie
-
Person
-
ACTED_IN
-
DIRECTED
-
PRODUCED
We can query the contents of those sheets using apoc.load.xls. Let’s have a look at a couple of the sheets:
CALL apoc.load.xls("file://movies.xls", "Movie");
lineNo | list | map |
---|---|---|
0 |
[0, 1999, "Welcome to the Real World", "The Matrix"] |
{tagline: "Welcome to the Real World", |
CALL apoc.load.xls("file://movies.xls", "ACTED_IN");
lineNo | list | map |
---|---|---|
0 |
[0, 1, 0, "Neo"] |
{ |
1 |
[1, 2, 0, "Trinity"] |
{ |
2 |
[2, 3, 0, "Morpheus"] |
{ |
3 |
[3, 4, 0, "Agent Smith"] |
{ |