在R中将.xlsm转换为.xlsx

我想将保存为启用macros的工作簿(Jimmy.xlsm)的Excel文件(称为“Jimmy”)转换为Jimmy.xlsx。

我需要在编码环境中完成这个工作。 我不能简单地通过在Excel中打开文件并分配不同的文件types来改变这一点。 我目前在R编程。如果我使用的function

file.rename("Jimmy.xlsm", "Jimmy.xlsx") 

该文件被损坏。

在你的框架中,你必须阅读工作表并将其写回。 假设你有一个名为“testXLSM2X.xlsm”的XLSM文件(包含macros,我假设)包含一个带有表格列数据的工作表。 这将做的伎俩:

 library(xlsx) r <- read.xlsx("testXLSMtoX.xlsm", 1) # read the first sheet # provides a data frame # use the first column in the spreadsheet to create row names then delete that column from the data frame # otherwise you will get an extra column of row index numbers in the first column r2w<-data.frame(r[-1],row.names=r[,1]) w <- write.xlsx(r2w,"testXLSMtoX.xlsx") # write the sheet 

当然,这些macros将被剥离出来。

这是一个答案,但我会质疑你想要完成的。 一般来说,从Excel中控制R比从R中控制Excel更容易。我使用http://rcom.univie.ac.at/中&#x7684; REXCEL,它不是开源的,但非常强大。