【问题标题】:Excel – Extracting the path information from Linked Images in a WorksheetExcel – 从工作表中的链接图像中提取路径信息
【发布时间】:2018-03-16 15:03:11
【问题描述】:

所有, 我有一个 Excel 电子表格,其中有一排图像通过 Insert\Picture From File 弹出窗口添加到工作表中。我没有嵌入图像,而是选择链接到文件的选项。我现在正在将工作表移动到 Access DB,但我不知道如何从图像行中提取每个链接图像的路径信息?

有谁知道我将如何做到这一点?任何帮助将不胜感激,在此先感谢 - CES

【问题讨论】:

    标签: excel vba


    【解决方案1】:

    您通过Insert\Picture From File popup window 在 Excel 中插入的图片不会保存为路径。它们“活”在 Excel 应用程序中。

    为了将它们“移动”到 Access DB,您必须将它们保存在某个地方,从而记住路径。根据Export Pictures Excel VBA这里的答案,这是一种方法:

    • 将图片放到图表中
    • 修正大小
    • 导出图表
    • 删除图表

    Public Sub TestMe()
    
        Dim pic As Shape
        Dim chrt As Chart
        Dim cnt As Long
        Dim ws As Worksheet
        Dim myPath As String
    
        Application.ScreenUpdating = False
        myPath = "C:\path\"
        Set ws = Worksheets(1)
    
        For cnt = 1 To ws.Shapes.Count
            If InStr(ws.Shapes(cnt).Name, "") > 0 Then
                Set chrt = Charts.Add.Location(Where:=xlLocationAsObject, Name:=ws.Name)
                chrt.ChartArea.Width = ws.Shapes(cnt).Width
                chrt.ChartArea.Height = ws.Shapes(cnt).Height
                chrt.Parent.Border.LineStyle = 0
    
                ws.Shapes(cnt).Copy
                chrt.ChartArea.Select
                chrt.Paste
                chrt.Export Filename:=myPath & ws.Shapes(cnt).Name & ".jpg"
                ws.ChartObjects(ws.ChartObjects.Count).Delete
            End If
        Next cnt
    
        Application.ScreenUpdating = True
    
    End Sub
    

    【讨论】:

      【解决方案2】:

      这不是 vba 代码答案,但它可以帮助您实现所需。

      如果您的文件以 excel 压缩格式保存,您也许可以获得链接位置,我认为这只是从 excel 2010 开始:

      保存文件副本并将文件重命名为文件名.zip

      解压压缩文件 . 浏览文件夹结构:\xl\drawings_rels\

      在那里你应该找到参考文件,例如'drawing1.xml.rels'

      <?xml version="1.0" encoding="UTF-8" standalone="true"?>
      
      -<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
      
      <Relationship TargetMode="External" Target="file:///C:\Users\exampleuser\Pictures\myimage.png" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/image" Id="rId1"/>
      

      您可以从这里提取带有 ID 的链接列表

      导航到文件夹:\xl\drawings\并打开图纸xml文件,从这里您可以找到图像ID及其Excel名称,您还可以从其余的 xml 代码。

      -<xdr:pic> 
      -<xdr:nvPicPr>
      <xdr:cNvPr name="Picture 3" id="4"/>
      -<xdr:cNvPicPr>
      <a:picLocks noChangeAspect="1"/>
      </xdr:cNvPicPr>
      </xdr:nvPicPr>
      -<xdr:blipFill>
      <a:blip r:link="rId1" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships"/>
      -<a:stretch>
      <a:fillRect/>
      </a:stretch>
      </xdr:blipFill> 
      </Relationships>
      

      有了这些信息,您应该能够确定哪些图片链接到哪个文件及其位置。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-08-21
        • 2011-02-28
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多