flextable和officedown错误:read_docx仅支持docx文件

问题描述

flextable和officedown会产生一个错误:在使用officedown的最小尝试中,仅read_docx支持的docx文件出现。我已经看到了这个post,但是我的文件路径没有空格,所以这似乎不是问题。

$apache2ctl -S

VirtualHost configuration:
*:80                   is a NameVirtualHost
         default server localhost (/etc/apache2/sites-enabled/000-default.conf:1)
         port 80 namevhost localhost (/etc/apache2/sites-enabled/000-default.conf:1)
         port 80 namevhost localhost (/etc/apache2/sites-enabled/newsdesk.conf:1)
ServerRoot: "/etc/apache2"
Main DocumentRoot: "/var/www/html"
Main ErrorLog: "/var/log/apache2/error.log"
Mutex default: dir="/var/run/apache2/" mechanism=default 
Mutex watchdog-callback: using_defaults
PidFile: "/var/run/apache2/apache2.pid"
Define: DUMP_VHOSTS
Define: DUMP_RUN_CFG
User: name="www-data" id=33 not_used
Group: name="www-data" id=33 not_used

---
date: "`r Sys.Date()`"
author: "Your Name"
title: "officedown template"
output: 
  officedown::rdocx_document:
    mapstyles:
      Normal: ['First Paragraph']
---

knitr::opts_chunk$set(echo = TRUE,fig.cap = TRUE)
library(officedown)
library(officer)
library(flextable)

fp <- fp_par(
  text.align = "center",padding.bottom = 20,padding.top = 120,border.bottom = fp_border())

ft <- fp_text(shading.color='#EFEFEF',bold = TRUE)

flextable(mtcars)

解决方法

Jessica和David Gohel,

我看到this post在使用read_docx时也有与flextable相同的错误。根据Mike M的努力,问题很可能来自文件路径

我已经解决了我的问题,因为我终于在用户名中找到了一个空格,因此officedown生成的模板化文件的文件路径将被复制到C:\Users\Myfirstname Mygivenname\AppData\something_else。然后在终端它将是C:\Users\Myfirstname~Mygivenname\AppData\something_else并出错。对于Windows用户,这可能是个问题,因为我在Mac上尝试过相同的操作,并且可以正常工作。

因此请确保您的用户名(或整个文件路径)没有任何空格

感谢David提供的officedown软件包和Mike M的工作。

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...