Skip to content

Commit

Permalink
apoc.export.xls + apoc.load.xls
Browse files Browse the repository at this point in the history
  • Loading branch information
mneedham committed Jan 22, 2021
1 parent 764a0d2 commit ac2564a
Show file tree
Hide file tree
Showing 16 changed files with 742 additions and 321 deletions.
Expand Up @@ -43,3 +43,10 @@ apoc.export.xls.all(file :: STRING?, config :: MAP?) :: (file :: STRING?, source
|data|STRING?
|===

== Install Dependencies
include::partial$xls-dependencies.adoc[]

[[usage-apoc.export.xls.all]]
== Usage Examples
include::partial$usage/apoc.export.xls.all.adoc[]

Expand Up @@ -45,3 +45,10 @@ apoc.export.xls.data(nodes :: LIST? OF NODE?, rels :: LIST? OF RELATIONSHIP?, fi
|data|STRING?
|===

== Install Dependencies
include::partial$xls-dependencies.adoc[]

[[usage-apoc.export.xls.data]]
== Usage Examples
include::partial$usage/apoc.export.xls.data.adoc[]

Expand Up @@ -44,3 +44,10 @@ apoc.export.xls.graph(graph :: MAP?, file :: STRING?, config :: MAP?) :: (file :
|data|STRING?
|===

== Install Dependencies
include::partial$xls-dependencies.adoc[]

[[usage-apoc.export.xls.graph]]
== Usage Examples
include::partial$usage/apoc.export.xls.graph.adoc[]

Expand Up @@ -44,3 +44,10 @@ apoc.export.xls.query(query :: STRING?, file :: STRING?, config :: MAP?) :: (fil
|data|STRING?
|===

== Install Dependencies
include::partial$xls-dependencies.adoc[]

[[usage-apoc.export.xls.query]]
== Usage Examples
include::partial$usage/apoc.export.xls.query.adoc[]

Expand Up @@ -27,6 +27,9 @@ apoc.load.xls(url :: STRING?, selector :: STRING?, config = {} :: MAP?) :: (line
|config|MAP?|{}
|===

== Config parameters
include::partial$usage/config/apoc.load.xls.adoc[]

== Output parameters
[.procedures, opts=header]
|===
Expand All @@ -36,3 +39,10 @@ apoc.load.xls(url :: STRING?, selector :: STRING?, config = {} :: MAP?) :: (line
|map|MAP?
|===

== Install Dependencies
include::partial$xls-dependencies.adoc[]

[[usage-apoc.load.xls]]
== Usage Examples
include::partial$usage/apoc.load.xls.adoc[]

Expand Up @@ -34,5 +34,12 @@ apoc.load.xml(url :: STRING?, path = / :: STRING?, config = {} :: MAP?, simple =
|value|MAP?
|===

== Reading from a file
include::../../import/includes/enableFileImport.adoc[]

[[usage-apoc.load.xml]]
== Usage Examples
include::partial$usage/apoc.load.xml.adoc[]

xref::import/xml.adoc[More documentation of apoc.load.xml,role=more information]

63 changes: 63 additions & 0 deletions docs/asciidoc/modules/ROOT/partials/usage/apoc.export.xls.all.adoc
@@ -0,0 +1,63 @@
The examples in this section are based on the following sample graph:

include::partial$createExportGraph.adoc[]

The Neo4j Browser visualization below shows the imported graph:

image::play-movies.png[]

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`:

[source,cypher]
----
CALL apoc.export.xls.all("movies.xls", {});
----

.Results
[opts="header"]
|===
| 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 xref::overview/apoc.load/apoc.load.xls.adoc[].
Let's have a look at a couple of the sheets:

[source,cypher]
----
CALL apoc.load.xls("file://movies.xls", "Movie");
----

.Results
[opts="header"]
|===
| lineNo | list | map
| 0 | [0, 1999, "Welcome to the Real World", "The Matrix"] | {tagline: "Welcome to the Real World", `<nodeId>`: 0, title: "The Matrix", released: 1999}
|===

[source,cypher]
----
CALL apoc.load.xls("file://movies.xls", "ACTED_IN");
----

.Results
[opts="header"]
|===
| lineNo | list | map
| 0 | [0, 1, 0, "Neo"] | {`<startNodeId>`: 1, `<endNodeId>`: 0, `<relationshipId>`: 0, roles: "Neo"}
| 1 | [1, 2, 0, "Trinity"] | {`<startNodeId>`: 2, `<endNodeId>`: 0, `<relationshipId>`: 1, roles: "Trinity"}
| 2 | [2, 3, 0, "Morpheus"] | {`<startNodeId>`: 3, `<endNodeId>`: 0, `<relationshipId>`: 2, roles: "Morpheus"}
| 3 | [3, 4, 0, "Agent Smith"] | {`<startNodeId>`: 4, `<endNodeId>`: 0, `<relationshipId>`: 3, roles: "Agent Smith"}

|===
@@ -0,0 +1,48 @@
The examples in this section are based on the following sample graph:

include::partial$createExportGraph.adoc[]

The Neo4j Browser visualization below shows the imported graph:

image::play-movies.png[]

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`:

[source,cypher]
----
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;
----

.Results
[opts="header"]
|===
| 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 xref::overview/apoc.load/apoc.load.xls.adoc[].
Let's have a look at the `Person` sheet:

[source,cypher]
----
CALL apoc.load.xls("file://movies-l.xls", "Person");
----

.Results
[opts="header"]
|===
| lineNo | list | map
| 0 | [3, 1961, "Laurence Fishburne"] | {name: "Laurence Fishburne", `<nodeId>`: 3, born: 1961}
| 1 | [5, 1967, "Lilly Wachowski"] | {name: "Lilly Wachowski", `<nodeId>`: 5, born: 1967}
| 2 | [6, 1965, "Lana Wachowski"] | {name: "Lana Wachowski", `<nodeId>`: 6, born: 1965}
|===
@@ -0,0 +1,65 @@
The examples in this section are based on the following sample graph:

include::partial$createExportGraph.adoc[]

The Neo4j Browser visualization below shows the imported graph:

image::play-movies.png[title="Movies Graph Visualization"]

The `apoc.export.xls.graph` procedure exports a xref::virtual/index.adoc[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`:

[source,cypher]
----
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;
----

.Results
[opts="header"]
|===
| 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 xref::overview/apoc.load/apoc.load.xls.adoc[].
Let's have a look at a couple of the sheets:

[source,cypher]
----
CALL apoc.load.xls("file://movies-producers.xls", "Person");
----

.Results
[opts="header"]
|===
| lineNo | list | map
| 0 | [7, 1952, "Joel Silver"] | {name: "Joel Silver", `<nodeId>`: 7, born: 1952}
|===


[source,cypher]
----
CALL apoc.load.xls("file://movies-producers.xls", "PRODUCED");
----

.Results
[opts="header"]
|===
| lineNo | list | map
| 0 | [6, 7, 0] | {`<startNodeId>`: 7, `<endNodeId>`: 0, `<relationshipId>`: 6}
|===
@@ -0,0 +1,46 @@
The examples in this section are based on the following sample graph:

include::partial$createExportGraph.adoc[]

The Neo4j Browser visualization below shows the imported graph:

image::play-movies.png[]

The `apoc.export.xls.query` procedure exports the results of a Cypher query to a XLS file.

The following query exports all `DIRECTED` relationships and the nodes with `Person` and `Movie` labels on either side of that relationship to the file `movies-directed.csv`:

[source,cypher]
----
WITH "MATCH path = (person:Person)-[:DIRECTED]->(movie)
RETURN person.name AS name, person.born AS born,
movie.title AS title, movie.tagline AS tagline, movie.released AS released" AS query
CALL apoc.export.xls.query(query, "movies-directed.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;
----

.Results
[opts="header"]
|===
| file | source | format | nodes | relationships | properties | time | rows | batchSize | batches | done | data
| "movies-directed.xls" | "statement: cols(5)" | "xls" | 0 | 0 | 0 | 12 | 0 | 20000 | 1 | TRUE | NULL
|===

`movies-directed.xls` contains one sheet with the name `Sheet0`.

We can query the contents of this sheet using xref::overview/apoc.load/apoc.load.xls.adoc[].
Let's have a look at a couple of the sheets:

[source,cypher]
----
CALL apoc.load.xls("file://movies-directed.xls", "Sheet0");
----

.Results
[opts="header"]
|===
| lineNo | list | map
| 0 | ["Lilly Wachowski", 1967, "The Matrix", "Welcome to the Real World", 1999] | {name: "Lilly Wachowski", tagline: "Welcome to the Real World", title: "The Matrix", released: 1999, born: 1967}
| 1 | ["Lana Wachowski", 1965, "The Matrix", "Welcome to the Real World", 1999] | {name: "Lana Wachowski", tagline: "Welcome to the Real World", title: "The Matrix", released: 1999, born: 1965}
|===

0 comments on commit ac2564a

Please sign in to comment.