Foxtable(狐表)用户栏目专家坐堂 → [求助]报表单元格图片尺寸,怎么适应单元格


  共有4016人关注过本帖树形打印复制链接

主题:[求助]报表单元格图片尺寸,怎么适应单元格

帅哥哟,离线,有人找我吗?
有点甜
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:版主 帖子:85326 积分:427815 威望:0 精华:5 注册:2012/10/18 22:13:00
  发帖心情 Post By:2018/4/20 17:05:00 [显示全部帖子]

根据单元格的宽高设置图片的宽高,参考

 

Dim App As New MSExcel.Application
Dim Wb As MSExcel.WorkBook = App.WorkBooks.Open("d:\test.xls")
Dim Ws As MSExcel.WorkSheet = Wb.WorkSheets(1)
Dim Rng As MSExcel.Range
Dim Pic As MSExcel.shape


For Each Pic In ws.shapes
    On Error Resume Next
   
    rng = pic.TopLeftCell
    With Pic
        If .Height / .Width > rng.Height / rng.Width Then
            .Height = rng.Height - 5
            .Top = rng.Top + 2.5
            .Left = rng.Left + (rng.Width - .Width) / 2
            .Placement = 1
        Else
            .Width = rng.Width - 5
            .Left = rng.Left + 2.5
            .Top = rng.Top + (rng.Height - .Height) / 2
            .Placement = 1
        End If
    End With
Next
App.Visible = True

[此贴子已经被作者于2018/4/20 17:05:38编辑过]

 回到顶部
帅哥哟,离线,有人找我吗?
有点甜
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:版主 帖子:85326 积分:427815 威望:0 精华:5 注册:2012/10/18 22:13:00
  发帖心情 Post By:2018/4/20 17:54:00 [显示全部帖子]

Dim Book As New XLS.Book(ProjectPath & "Attachments\会签版现况一致.xlsx")
Dim fl As String = ProjectPath & "Reports\会签版现况一致.xlsx"

Dim Sheet As XLS.Sheet = Book.Sheets(0)
'Sheet(3,9).Value = "<列值 = # " & Date.Today & "#>"  '写入打印条件
'Sheet(46,10).Value = "<列值 = '0'>"  '写入打印条件
Sheet(8,10).Value = "<列值 = '0'>"  '写入打印条件

Book.Build() '生成报表
Book.Save(fl)

Dim App As New MSExcel.Application
Dim Wb As MSExcel.WorkBook = App.WorkBooks.Open(fl)
Dim Ws As MSExcel.WorkSheet = Wb.WorkSheets(1)
Dim Rng As MSExcel.Range
Dim Pic As MSExcel.shape


For Each Pic In ws.shapes
    On Error Resume Next
   
    rng = pic.TopLeftCell
    With Pic
        If .Height / .Width > rng.Height / rng.Width Then
            .Height = rng.Height - 5
            .Top = rng.Top + 2.5
            .Left = rng.Left + (rng.Width - .Width) / 2
            .Placement = 1
        Else
            .Width = rng.Width - 5
            .Left = rng.Left + 2.5
            .Top = rng.Top + (rng.Height - .Height) / 2
            .Placement = 1
        End If
    End With
Next
App.Visible = True


 回到顶部
帅哥哟,离线,有人找我吗?
有点甜
  3楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:版主 帖子:85326 积分:427815 威望:0 精华:5 注册:2012/10/18 22:13:00
  发帖心情 Post By:2018/4/20 18:20:00 [显示全部帖子]

不,可,能。上传实例测试。


 回到顶部
帅哥哟,离线,有人找我吗?
有点甜
  4楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:版主 帖子:85326 积分:427815 威望:0 精华:5 注册:2012/10/18 22:13:00
  发帖心情 Post By:2018/7/4 22:50:00 [显示全部帖子]


 回到顶部