使用XLconnect和readWorksheet导入excel xlsx数据会导致格式错误

时间:2017-07-04 14:21:39

标签: r excel xlsx xlconnect

我有一个扩展名为xlsx的Excel文件,其中Sheet1和Sheet包含以下内容:18:20,10:10(A列,第1行:2行)。当我尝试将它们导入R时,我没有得到预期的结果。

library(XLConnect)

setwd("...")
my_book <- loadWorkbook("test.xlsx")

xlsx_import <- lapply(getSheets(my_book), readWorksheet, object = my_book) 
xlsx_import


# Returns some kind of date format

xlsx_import <- lapply(getSheets(my_book), readWorksheet, object = my_book, colTypes = "character")
xlsx_import


# Same as above

有可能以某种方式在R中解决这个问题吗?因为我有很多床单要经过。

1 个答案:

答案 0 :(得分:0)

Try This.

wb=loadWorkbook("Test.xlsx", create = TRUE)

setStyleAction(wb, XLC$"STYLE_ACTION.DATATYPE")
cs = createCellStyle(wb, name = "myDateStyle")
setDataFormat(cs, format = "dd-mm-yyyy")
setCellStyleForType(wb, style = cs, type = XLC$"DATA_TYPE.DATETIME")



s<-readWorksheet(wb,sheet = "Sheet1")

***Operations which you wanna do***

writeWorksheet(wb, wq, sheet = "Sheet1")
setForceFormulaRecalculation(wb,"*",TRUE)
saveWorkbook(wb)