如何在保留特殊字符的同时将特殊字符保存在csv中? [英] How to save special characters in a csv while preserving them for excel?
问题描述
让我们考虑使用带有特殊字符的数据框简单地创建一个csv文件:
Let's consider this simple creation of a csv file with a dataframe that contains special characters:
d <- data.frame(x = "Édifice", y="Arrêt")
write.table(x = d, file = "test.csv", sep = ",", row.names = F, col.names = F, quote = F, fileEncoding = "UTF-8")
csv文件看起来像预期的
The csv file looks like expected
Édifice,Arrêt
但是当我在excel中打开此csv时,我得到了:
But when I open this csv in excel I get:
我尝试使用readr,折叠列,然后使用writeLines编写它们,使用write.xlsx编写,检查编码选项.没有一个.
I have tried using readr, collapsing columns and then writing them with writeLines, writing using write.xlsx, checked for encoding options. None worked.
我的约束是输入是数据框,输出必须是excel中可读取的csv.
My constraint is that the input is a dataframe, and the output must be a csv readable in excel.
推荐答案
德语umlaute的问题相同.我使用 reader
中的 write_excel_csv
:
Same problem with german umlaute. I use write_excel_csv
from readr
:
library(readr)
write_excel_csv(x = d, path = "test.csv", col_names = F)
这篇关于如何在保留特殊字符的同时将特殊字符保存在csv中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!