请教老师: 想在word报表中由几个单元格合并成的一个照片框中放置一个图片,并进行比例缩放
下面代码请老师看看有没有问题,给优化一下。现在照片框的宽度和高度是写死了,如何能用代码获取照片框的宽度和高度值?
Dim file As String = ProjectPath & "RemoteFiles\" & tb.Current("照片")
Dim img As image = getImage(file)
Dim ZPwidth As Integer = img.width '照片原始宽度 像素
Dim ZPheight As Integer = img.height '照片原始高度 像素
Dim Docwidth As Integer = 200 '432 '模板照片框宽度 像素
Dim Docheight As Integer = 150 '336 '模板照片框高度 像素
Dim bl,Wbl,Hbl As Double '原始图片像素和模板照片框比例
Wbl = ZPwidth/Docwidth
Hbl = ZPheight/Docheight
Dim width,height As Integer
If ZPwidth <= Docwidth AndAlso ZPheight <= Docheight Then
width = ZPwidth
height = ZPheight
ElseIf ZPwidth > Docwidth AndAlso ZPheight <= Docheight Then
width = ZPwidth
height = Cint(ZPheight/Wbl)
ElseIf ZPwidth <= Docwidth AndAlso ZPheight > Docheight Then
width = Cint(ZPwidth/Hbl)
height = Docheight
ElseIf ZPwidth > Docwidth AndAlso ZPheight > Docheight Then
If Wbl >= Hbl Then
width = Cint(ZPwidth/Wbl)
height = Cint(ZPheight/Wbl)
Else
width = Cint(ZPwidth/Hbl)
height = Cint(ZPheight/Hbl)
End If
End If
wrt.ReplaceWithImage("Tihuan照片",file, width, height)
[此贴子已经被作者于2017/8/4 15:45:27编辑过]