使用 OfficeR 读取 rdocx 对象的正文

问题描述 投票:0回答:0

我正在尝试使用

officer
包读取 .docx 文件的主体,但我遇到了一个错误:

library(officer)

docx1 <- system.file(package = "officer", "template.docx")
content <- docx_summary(docx1)

x$doc_obj 中的错误:$ 运算符对于原子向量无效**

docx2 <- read_docx("template.docx")
content <- docx_summary(docx2)

data.frame(level = as.integer(xml_attr(xml_child(node, "w:pPr/w:numPr/w:ilvl"), : arguments imply different number of rows: 1, 0**

length(docx1) 
# 1
length(docx2) 
# 37

当我运行 docx2 时,我得到了一些有趣的信息,包括所有样式,然后我得到了这个:

text                                  
1.1                                   
Question 10:                          
1.4                                   
Some text here also                   
1.7                                   
Text for a heading                    
1.10                                  
1.13                                  
10.1                                  
1.16                                  
10.2                                  
1.19                                  
2.2                                   
<NA>                                  
2.5                                   
<NA>                                  
2.8                                   
<NA>                                  
2.11                                  
1 of 2 questions correct-50%          

上面的所有文字实际上都在我试图阅读的正文中。它很混乱,但这是我希望以正确的顺序得到的

r docx officer officedown
© www.soinside.com 2019 - 2024. All rights reserved.