是否可以从在线 ZIP 文件中读取 Excel 文件?
我一直在尝试类似的事情read.csv
:
nuts = url("http://ec.europa.eu/eurostat/ramon/documents/nuts/NUTS_2010.zip")
xlsx::read.xlsx(unz(nuts, "NUTS_2010.xls"), 1)
close(nuts)
……无济于事。
这有点不方便,但是怎么样:
basefn <- "NUTS_2010"
urlPath <- "http://ec.europa.eu/eurostat/ramon/documents/nuts/"
xlsFile <- paste0(basefn,".xls")
zipFile <- paste0(basefn,".zip")
download.file(paste0(urlPath,zipFile),zipFile)
unzip(zipFile)
## I had trouble with xlsx::read.xlsx, but gdata::read.xls was OK
## xlsx::read.xlsx(xlsFile,1)
gdata::read.xls(xlsFile)
unlink(zipFile)
readZipURL <- function(urlPath,basefn) {...}
如果您想定期执行此操作,您可以随时将其打包到一个函数中(您可能也想清理下载的 XLS 文件......)
这对我有用
options( java.parameters = "-Xmx4g" )
library(XLConnect)
temp <- tempfile()
zipfile <- paste0("https://www.cms.gov/Research-Statistics-Data-and-Systems/Statistics-Trends-and-Reports/MCRAdvPartDEnrolData/Downloads/"
,year,"/",year,"-", "Low-Income-Subsidy-Contract-Enrollment-by-County.zip")
download.file(zipfile,temp)
filename <- paste0("WEB Tables LIS by state -county ",month2,"-","1","-",year,".xlsx")
temp1 <- unzip(temp)
assign(paste0("scc_pdp_lis_",year),readWorksheetFromFile(temp1,sheet=1,startRow=7,header=F))
我正在阅读一些我感兴趣的 CMS 文件