【发布时间】:2014-03-31 10:44:37
【问题描述】:
我正在尝试从 R 创建一个新的 excel 工作簿,以使用 xlsx 包保存一些小数据集。出于某种原因,它工作正常,但我无法再次这样做。
创建新工作簿的代码
library("xlsx")
library("xlsxjars")
library("rJava")
file <- "marca_imei.xlsx"
wb <- loadWorkbook(file)
# The error:
# Error in .jcall("RJavaTools", "Ljava/lang/Object;", "invokeMethod", cl, :
# java.lang.IllegalArgumentException: Your InputStream was neither an OLE2 stream, nor an OOXML stream
我已经搜索过答案,但似乎人们在从 excel 导入数据时遇到了同样的错误。 我已经尝试过推荐的方法,但没有奏效。以下是一些供未来搜索者使用的链接:
- http://r.789695.n4.nabble.com/Read-shortcuts-of-MS-Excel-files-through-R-td4677020.html
- http://r.789695.n4.nabble.com/Problem-with-xlsx-package-td3298470.html
sessionInfo():
locale:
[1] LC_COLLATE=Spanish_Spain.1252 LC_CTYPE=Spanish_Spain.1252 LC_MONETARY=Spanish_Spain.1252
[4] LC_NUMERIC=C LC_TIME=Spanish_Spain.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] xlsx_0.5.5 xlsxjars_0.6.0 RJDBC_0.2-3 rJava_0.9-6
[5] DBI_0.2-7 slidifyLibraries_0.3.1 slidify_0.4 knitr_1.5
[9] devtools_1.4.1 scales_0.2.3 ggplot2_0.9.3.1 data.table_1.8.11
[13] reshape2_1.2.2
loaded via a namespace (and not attached):
[1] colorspace_1.2-4 dichromat_2.0-0 digest_0.6.4 evaluate_0.5.1 formatR_0.10
[6] grid_3.0.2 gtable_0.1.2 httr_0.2 labeling_0.2 markdown_0.6.3
[11] MASS_7.3-29 memoise_0.1 munsell_0.4.2 parallel_3.0.2 plyr_1.8
[16] proto_0.3-10 RColorBrewer_1.0-5 RCurl_1.95-4.1 stringr_0.6.2 tools_3.0.2
[21] whisker_0.3-2 yaml_2.1.10
【问题讨论】:
-
无论如何都不是答案,但我更喜欢 XLConnect 包。
-
嗯,谢谢你的评论。我来看看包裹。
-
要排除您的
xlsx文件的问题,您可以试试wb <- createWorkbook()吗?如果您收到错误,则表明您的安装存在问题。 -
成功了。无论如何,感谢您的尝试。
> wb <- createWorkbook() > wb [1] "Java-Object{Name: /xl/workbook.xml - Content Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml}" -
我最终使用了 XLConnect 包,它运行良好,并且有很好的文档记录。