xlsx包是否适用于R中的xlsm文件?

时间:2012-06-26 20:25:09

标签: r xlsx xlsm

我正在尝试从xlsm工作簿中读取一个data.frame范围。我可以使用R中的xlsx包吗?如果没有,有没有人知道如何做到这一点?

谢谢!

3 个答案:

答案 0 :(得分:7)

您是否尝试过使用手册中描述的read.xlsx或read.xlsx2?

http://cran.r-project.org/web/packages/xlsx/xlsx.pdf

如果这些不适用于您的文件格式,并且您尝试访问表格数据,则可能需要打开.xlsm并将数据导出为csv格式。

可以轻松导入这些read.csv('filename.csv')

答案 1 :(得分:3)

来自R3.2的read.xlsx将读取保存在xlsm工作簿中的数据,但是您需要正确的后缀并将文件保存在同一目录(或完整文件名)中,例如

write.xlsx(LotsofmydatainRdataframe, LotsofmydatainExcel.xlsm,sheetName="Output")

如果您只尝试LotsofmydatainExcel或LotsofmydatainExcel.xlsx,则找不到文件。

令人讨厌的是,以下内容在R

中产生了未知格式的xlsm错误
ld: warning: directory not found for option '-F/Users/harpreet/Documents/FacebookSDK'
Undefined symbols for architecture x86_64:
  "_GSDK_NSClassFromString", referenced from:
      l010 in GoogleSignIn(GIDSignIn.o)
      l059 in GoogleSignIn(GIDSignIn.o)
  "_OBJC_CLASS_$_GSDK_GTMOAuth2Authentication", referenced from:
      objc-class-ref in GoogleSignIn(GIDSignIn.o)
      objc-class-ref in GoogleSignIn(GIDAuthentication.o)
  "_OBJC_CLASS_$_GSDK_GTMOAuth2Keychain", referenced from:
      objc-class-ref in GoogleSignIn(GIDSignIn.o)
  "_OBJC_CLASS_$_GSDK_GTMOAuth2SignIn", referenced from:
      objc-class-ref in GoogleSignIn(GIDSignIn.o)
      objc-class-ref in GoogleSignIn(GIDAuthentication.o)
  "_OBJC_CLASS_$_GSDK_GTMOAuth2ViewControllerTouch", referenced from:
      objc-class-ref in GoogleSignIn(GIDSignIn.o)
  "_OBJC_CLASS_$_GSDK_GTMSessionFetcher", referenced from:
      objc-class-ref in GoogleSignIn(GIDSignIn.o)
      objc-class-ref in GoogleSignIn(GIDRuntimeConfigFetcher.o)
  "_OBJC_CLASS_$_GSDK_GTMSessionFetcherService", referenced from:
      objc-class-ref in GoogleSignIn(GIDSignIn.o)
  "_OBJC_CLASS_$_GSDK_OpenInChromeController", referenced from:
      objc-class-ref in GoogleSignIn(GIDSignIn.o)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

答案 2 :(得分:1)

为了将来参考(该问题来自2012年),您可以使用read_excel软件包来完成此操作,并在2015年添加了xlsm支持

read_excel('filename.xlsm', sheet = 'sheetname', range = 'A1:B5')