Does the xlsx package work for xlsm files in R?

若如初见. 提交于 2019-12-10 14:13:25

问题


I am trying to read a range into a data.frame from a xlsm workbook. Can I do this with the xlsx package in R? If not, does anyone know of a way to do it?

Thank you!


回答1:


Did you try using read.xlsx or read.xlsx2 as described in the manual?

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

If these do not work with your file format, and you are trying to access tabular data you might want to open the .xlsm and export your data to csv format.

These are easily imported uisng read.csv('filename.csv')




回答2:


read.xlsx from R3.2 will read in data saved in an xlsm workbook, but you need the correct postfix and the file saved in the same directory (or full filename), e.g.

LotsofmydatainRdataframe <- read.xlsx(LotsofmydatainExcel.xlsm,sheetName="Deaths",as.data.frame=TRUE)

if you try just LotsofmydatainExcel or LotsofmydatainExcel.xlsx then file will not be found.

Annoyingly the following produces an unknown format xlsm error in R

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


来源:https://stackoverflow.com/questions/11215381/does-the-xlsx-package-work-for-xlsm-files-in-r

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!