使用R在Microsoft Word表中自动检索文件名
我在Microsoft Word文档中有一个大表 大多数行(但不是所有行)都附加了一个Microsoft Word文件 我的工作是进入每一行并手动键入提供附件的文件名 是否有任何方法可以使用R包自动化此任务?例如,对于具有文件附件的每一行,是否自动拉取文件名并将其直接记录在其左侧的字段中 这就是这张桌子的样子。文件位于最右边的列中。左边的那列是我要输入文件名的地方 我已尝试使用使用R在Microsoft Word表中自动检索文件名,r,officer,R,Officer,我在Microsoft Word文档中有一个大表 大多数行(但不是所有行)都附加了一个Microsoft Word文件 我的工作是进入每一行并手动键入提供附件的文件名 是否有任何方法可以使用R包自动化此任务?例如,对于具有文件附件的每一行,是否自动拉取文件名并将其直接记录在其左侧的字段中 这就是这张桌子的样子。文件位于最右边的列中。左边的那列是我要输入文件名的地方 我已尝试使用docxtracr导入docx文件,但它无法正确读取文件名。相反,它将它们替换为\s ievs_raw <- r
docxtracr
导入docx
文件,但它无法正确读取文件名。相反,它将它们替换为\s
ievs_raw <- read_docx("ievs-raw.docx")
tbls <- docx_extract_all_tbls(real_world)
view(as.data.frame.list(tbls))
ievs\u raw我无法使用R
软件包来解决这个问题,但是Microsoft社区论坛
上的善良人士提供了一个非常有用的visualbasic宏。这样做的好处是,它可以适应特定行中有多个附件的情况
Sub ObjectNames()
Dim ILS As InlineShape
Dim nObj As Long
Dim strName As String
Dim col As Long
Dim row As Long
With ActiveDocument.Tables(1)
col = .Columns.Count
For row = 1 To .Rows.Count
strName = ""
# loop through all shapes in this row's last cell
# (if there are none, the loop does nothing)
For nObj = 1 To .Cell(row, col).Range.InlineShapes.Count
Set ILS = .Cell(row, col).Range.InlineShapes(nObj)
If Not ILS.OLEFormat Is Nothing Then
# build up a string with as many names as
# there are embedded objects, separated by
# paragraph marks (vbCr)
If nObj > 1 Then strName = strName & vbCr
strName = strName & ILS.OLEFormat.IconLabel
End If
Next nObj
If Len(strName) > 0 Then
.Cell(row, col - 1).Range.Text = strName
End If
Next row
End With
End Sub