word批量插入某目录下的所有图片及图片名称

1、 新建一空白word文档



图片

 

2、 ALT+F11调出开发工具




3、 点击“宏”,显示宏列表




输入宏名,如:test

点击“新建”,然后在Sub test() End Sub间输入如下代码:

 

‘’’’’’’’’’’’’’’’’’’’

'插入一表格

ActiveDocument.Tables.Add Range:=Selection.Range, NumRows:=1, NumColumns:= _

       1, DefaultTableBehavior:=wdWord9TableBehavior, AutoFitBehavior:= _

       wdAutoFitFixed

   With Selection.Tables(1)

       If .Style <> "网格型" Then

           .Style = "网格型"

       End If

       .ApplyStyleHeadingRows = True

       .ApplyStyleLastRow = False

       .ApplyStyleFirstColumn = True

       .ApplyStyleLastColumn = False

       .ApplyStyleRowBands = True

       .ApplyStyleColumnBands = False

   End With

   

   ' 显示 C:\目录下的名称。

MyPath = "F:\self\照片&视频\会展中心\"   ' 指定路径。最后必须加上\

MyName = Dir(MyPath, vbDirectory)   ' 找寻第一项。

Do While MyName <> ""   ' 开始循环。

   ' 跳过当前的目录及上层目录。

   If MyName <> "." And MyName <> ".." Then

       ' 使用位比较来确定 MyName代表一目录。

       If InStr(MyName, "jpg") Then

          ' Debug.Print MyName    ' 如果它是一个目录,将其名称显示出来。

           Selection.InsertRows 1

           Selection.Collapse Direction:=wdCollapseStart

           

           Selection.InlineShapes.AddPicture FileName:=MyPath + MyName, LinkToFile:= _

       False, SaveWithDocument:=True

           Selection.TypeText Text:=MyName

       End If

   End If

   MyName = Dir    ' 查找下一个目录。

Loop

‘’’’’’’’’’’’’’’’’’’’’’’’’’

 


 

其中:


修改成你自己的图片所在目录,记得最后必须加上“\

 

4、 保存,返回原来空白的word文档




点击“宏”,选择“test”,然后点击运行~

5、 接着就是结果

 

 

  • 6
    点赞
  • 37
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
你可以使用Python的Pillow库来批量插入图片,以下是一个示例代码: ```python from PIL import Image, ImageDraw, ImageFont # 打开一个文本文件 with open('text.txt', 'r') as f: text = f.read() # 分割文本为单词列表 words = text.split() # 设置文字字体和大小 font = ImageFont.truetype("arial.ttf", 16) # 设置文字颜色和背景色 text_color = (0, 0, 0) background_color = (255, 255, 255) # 设置图片大小 img_width = 800 img_height = 600 # 创建一个新的空白图片 img = Image.new('RGB', (img_width, img_height), color=background_color) # 创建一个绘图对象 draw = ImageDraw.Draw(img) # 定义图片内边距 padding = 10 # 定义当前行的宽度和高度 current_width = padding current_height = padding # 循环遍历单词列表 for word in words: # 获取当前单词的大小 word_size = draw.textsize(word, font=font) # 判断当前行是否能容纳下该单词 if current_width + word_size[0] + padding > img_width: # 如果当前行容纳不下该单词,则换行 current_width = padding current_height += word_size[1] + padding # 将单词插入图片中 img.paste(Image.open('image.png'), (current_width, current_height)) # 绘制单词 draw.text((current_width, current_height), word, fill=text_color, font=font) # 更新当前行的宽度 current_width += word_size[0] + padding # 保存图片 img.save('output.png') ``` 上述代码会按照单词列表中的顺序,依次将每个单词插入到指定的图片中,并将最终结果保存为一张新的图片。你需要将代码中的'image.png'替换为你的图片路径,'text.txt'替换为你的文本文件路径。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值