r - 使用 Flextable to Word 进行自由文本调查回复
问题描述
我正在做一些调查分析,但遇到了一个奇怪的问题。
当我尝试将一个flextable
对象写到 Word 中时,我得到一个大约 30 页的空白文档。这以前在 R 和 R Markdown 中有效,没有任何问题,我不知道为什么会这样。
这是输出:
df <- structure(list(Response = c("Comment from patron 1", "Comment from customer 2",
"Comment from someone 3", "Comment from nobody 4", "Comment from patron 5",
"Comment from customer 6", "Comment from someone 7", "Comment from nobody 8"
)), row.names = c(NA, -8L), class = c("tbl_df", "tbl", "data.frame"
))
这是我用来写入我 100% 确定可以访问的目录的代码:
ft <- as.data.frame(df)
ft <- flextable(ft)
ft <- theme_zebra(ft)
ft <- autofit(ft)
doc <- read_docx()
doc <- body_add_flextable(doc, value = ft)
print(doc, target = "Doc2.docx")
有什么想法可以帮助解决或解决此问题吗?提前感谢您的任何帮助!
解决方案
正如 David Gohel 所提到的,添加一个宽度参数解决了这个问题:
ft <- as.data.frame(df)
ft <- flextable(ft)
ft <- theme_zebra(ft)
ft <- autofit(ft)
**ft <- width(ft, width = 7)**
doc <- read_docx()
doc <- body_add_flextable(doc, value = ft)
print(doc, target = "Doc2.docx")
推荐阅读
- ios - 将 WebKit 会话传递给另一个视图控制器 Swift
- c - fgets() 导致分段错误
- python - pandas 多行到单行,2 个索引上有多列
- mysql - mysqlworkbench 中的这个查询有什么问题?
- javascript - 如何将 JavaScript 二维数组复制到剪贴板以将其粘贴到 excel 中?
- r - raster::erase 函数 - RGEOSBinTopoFunc 中的错误:TopologyException
- aws-lambda - Lambda,排序键添加导致失败
- python - 在 azure 中运行 python 脚本以从流 API 获取数据的选项
- c# - BitmapImage isDownloading 始终为真
- powershell - Powershell:将单个正则表达式结果列出到 HTML 表中