apoc.export.xls.graph

Procedure APOC Full

apoc.export.xls.graph(graph,file,config) - exports given graph object as xls to the provided file

Signature

apoc.export.xls.graph(graph :: MAP?, 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

graph

MAP?

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

The XLS procedures have dependencies on libraries that are not included in the APOC Library.

These dependencies are included in apoc-xls-dependencies-4.1.0.9.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.

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:

play movies
Figure 1. Movies Graph Visualization

The apoc.export.xls.graph procedure exports a virtual graph to a CSV file or as a stream.

The examples in this section are based on a virtual graph that contains all PRODUCED relationships and the nodes either side of that relationship. We can then export that virtual graph to movies-producers.xls:

MATCH path = (:Person)-[produced:PRODUCED]->(:Movie)
WITH collect(path) AS paths
CALL apoc.graph.fromPaths(paths, "producers", {})
YIELD graph AS g
CALL apoc.export.xls.graph(g, "movies-producers.xls", {})
YIELD file, nodes, relationships, properties
RETURN file, nodes, relationships, properties;
Table 1. Results
file nodes relationships properties

"movies-producers.xls"

2

1

5

movies-producers.xls contains individual sheets for each node label and relationship type. In this case it contains the following sheets:

  • Movie

  • Person

  • 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-producers.xls", "Person");
Table 2. Results
lineNo list map

0

[7, 1952, "Joel Silver"]

{name: "Joel Silver", <nodeId>: 7, born: 1952}

CALL apoc.load.xls("file://movies-producers.xls", "PRODUCED");
Table 3. Results
lineNo list map

0

[6, 7, 0]

{<startNodeId>: 7, <endNodeId>: 0, <relationshipId>: 6}