简体   繁体   English

不使用xlsx包将csv转换为excel

[英]convert a csv to excel without using xlsx package

I want to convert a csv file to excel. 我想将csv文件转换为excel。

I found from the search in Internet that the best proposal it to use the library(xlsx) and use the write.xlsx(..) to write my dataframe to excel file. 我从互联网搜索中发现最好的建议是使用库(xlsx)并使用write.xlsx(..)将我的数据帧写入excel文件。

However when I try to load and use the xlsx library and use it I receive the following: 但是,当我尝试加载和使用xlsx库并使用它时,我收到以下内容:

Loading required package: rJava
Error : .onLoad failed in loadNamespace() for 'rJava', details:
  call: inDL(x, as.logical(local), as.logical(now), ...)
  error: unable to load shared object 'C:/Users/Ban/Documents/R/win-library/3.1/rJava/libs/x64/rJava.dll':
  LoadLibrary failure:  Could not find the specified mode. unit.

Is there any other way to convert the csv to excel or is there anyone faced the previous problem? 有没有其他方法将csv转换为excel或者是否有人遇到过上一个问题?

You can do this in rio without needing a java dependency. 您可以在rio中执行此操作而无需java依赖项。 It calls the openxlsx package. 它调用openxlsx包。

install_github("leeper/rio")
library("rio")

# create an example CSV
export(mtcars, "mtcars.csv")

# convert the CSV to Excel (.xlsx)
convert("mtcars.csv", "mtcars.xlsx")

If you wanted to do this directly with openxlsx, you can run something like: 如果你想直接用openxlsx这样做,你可以运行如下:

library("openxlsx")
write.xlsx(read.csv("mtcars.csv"), "mtcars.xlsx")

Full disclosure: I'm the author of rio. 完全披露:我是rio的作者。

A minimum of research on CRAN reveals a number of packages: 对CRAN的最少研究揭示了许多包:

  • XLconnect needs Java XLconnect需要Java
  • xlsx needs Java xlsx需要Java
  • openxlsx does NOT need Java but is younger and not as widely used openxlsx不需要Java,但是更年轻,而不是广泛使用
  • writexls uses Perl under the hood which most system have. writexls在大多数系统使用的引擎盖下使用Perl。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM