加载 Excel (XLS)
库要求
为了加载 XLS 文件,我们使用了 Apache POI 库,该库与旧版本和新版本的 Excel 格式兼容,但体积较大。因此,我们决定不将其包含在 apoc jar 中,而是将其作为可选依赖项。
这些依赖项包含在 apoc-xls-dependencies-5.26.1-all.jar 文件中,可以从发布页面下载。下载该文件后,应将其放置在 plugins
目录中并重启 Neo4j 服务器。
或者,您可以从 Maven Repository 下载这些 jar 文件(也将其放入 plugins
目录中)
使用方法
apoc.load.xls
的用法与 apoc.load.csv
相似,主要区别在于可以从工作表或工作表的范围中选择加载数据。
您可以通过名称选择工作表,例如 'Kids'
,或通过偏移量选择范围,例如 'Results!B2:F3'
CALL apoc.load.xls({url}, {Name of sheet}, {config})
{config}
参数是一个 map
name | description |
---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
在 dateParse 中,首先匹配到的格式将返回格式化后的日期,否则将返回错误。 在 |
apoc.load.xls
示例
CALL apoc.load.xls('file:///path/to/file.xls','Full',{mapping:{Integer:{type:'int'}, Array:{type:'int',array:true,arraySep:';'}}})

CALL apoc.load.xls('http://bit.ly/2nXgHA2','Kids')
带 type/dateFormat 和 dateParse 的一些示例
CALL apoc.load.xls('test_date.xlsx','sheet',{mapping:{Date:{type:'String'}}})

CALL apoc.load.xls('test_date.xlsx','sheet',{mapping:{Date:{type:'String',dateFormat:'iso_date'}}})

CALL apoc.load.xls('test_date.xlsx','sheet',{mapping:{Date:{type:'String',dateParse:["wrongPath", "dd-MM-yyyy", "dd/MM/yyyy", "yyyy/MM/dd", "yyyy/dd/MM", "yyyy-dd-MM'T'hh:mm:ss"]}}})
