apoc.export.xls.data
Procedure APOC Full
apoc.export.xls.data(nodes,rels,file,config) - exports given nodes and relationships as xls to the provided file
Signature
apoc.export.xls.data(nodes :: LIST? OF NODE?, rels :: LIST? OF RELATIONSHIP?, 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?)
Input parameters
Name | Type | Default |
---|---|---|
nodes |
LIST? OF NODE? |
null |
rels |
LIST? OF RELATIONSHIP? |
null |
file |
STRING? |
null |
config |
MAP? |
null |
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.3.0.12.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.data
procedure exports the specified nodes and relationships to a XLS file.
The following query exports all nodes with the :Person
label with a name
property that starts with L
to the file movies-l.csv
:
MATCH (person:Person)
WHERE person.name STARTS WITH "L"
WITH collect(person) AS people
CALL apoc.export.xls.data(people, [], "movies-l.xls", {})
YIELD file, source, format, nodes, relationships, properties, time, rows, batchSize, batches, done, data
RETURN file, source, format, nodes, relationships, properties, time, rows, batchSize, batches, done, data;
file | source | format | nodes | relationships | properties | time | rows | batchSize | batches | done | data |
---|---|---|---|---|---|---|---|---|---|---|---|
"movies-l.xls" |
"data: nodes(3), rels(0)" |
"xls" |
3 |
0 |
6 |
10 |
3 |
20000 |
1 |
TRUE |
NULL |
movies-l.xls
contains individual sheets for each node label and relationship type.
In this case it contains a Person
sheet.
We can query the contents of those sheets using apoc.load.xls.
Let’s have a look at the Person
sheet:
CALL apoc.load.xls("file://movies-l.xls", "Person");
lineNo | list | map |
---|---|---|
0 |
[3, 1961, "Laurence Fishburne"] |
{name: "Laurence Fishburne", |
1 |
[5, 1967, "Lilly Wachowski"] |
{name: "Lilly Wachowski", |
2 |
[6, 1965, "Lana Wachowski"] |
{name: "Lana Wachowski", |
You can also compress the files to export. See here for more information |