【问题标题】:How to replace Text with corresponding images如何用相应的图像替换文本
【发布时间】:2012-10-23 03:35:35
【问题描述】:

我有一个包含 300 多条记录的 Excel 文档。

在每条记录的第一行,有一个用户图像变量。 此记录将始终为 username.jpg 或为空。

我有一个包含相应图片的文件夹,所有图片都以完全相同的方式命名。

有什么办法可以自动将第一行的文字替换为相关的图片?

【问题讨论】:

  • 应该像 if(condition) column.row.loadimage() 一样简单。尝试在 Excel 上使用 Visual Basic 进行一些研究。因为我不会说 VB,所以我帮不了你。
  • 我猜这个链接很接近:stackoverflow.com/questions/7382739/…
  • xD 需要在 45 分钟内完成此操作...我是 C# 人员。我也在寻找 Excel 中的方法来执行此操作。我已经从 XML 生成了 excel 表。

标签: excel excel-2010


【解决方案1】:

如果您的用户图像变量在 A 列中,则此代码会将图片插入到 A 列中,并将行高调整为图片的高度。您可能需要稍微调整一下代码。

Sub insertPic()

Dim pic As String
Dim url As String
Dim r As Integer
Dim he As Integer



url = "C:\User\Pictures\" ' This is the variable to the folder

For r = 1 To 300
pic = Sheets("Sheet1").Range("A" & r).Value ' This is your username file
pic = url & pic



With ActiveSheet.Pictures.Insert(pic) ' Insert picture into active sheet
    .Left = ActiveSheet.Range("A" & r).Left ' left and top align the left and top of the picture with the specified cell
    .Top = ActiveSheet.Range("A" & r).Top
    he = .Height ' get height of image


End With
Sheets("Sheet1").Range("A" & r).Select
    Selection.RowHeight = he ' match row height to picture height
Next r


End Sub

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-03-19
    • 2010-09-19
    • 2012-11-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多