以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  [求助]导出excle图片跑出单元格及图片不居中单元格中间  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=121362)

--  作者:湛江智
--  发布时间:2018/7/4 16:12:00
--  [求助]导出excle图片跑出单元格及图片不居中单元格中间

不改变图片长宽比例前提下,导出exlce图片位置不对,及图片居中单元格,求助


图片点击可在新窗口打开查看此主题相关图片如下:绿色图片正确位置+图片居中单元格示意.png
图片点击可在新窗口打开查看

[此贴子已经被作者于2018/7/6 9:31:04编辑过]

--  作者:有点甜
--  发布时间:2018/7/4 18:56:00
--  

1、模板

 

 下载信息  [文件大小:   下载次数: ]
图片点击可在新窗口打开查看点击浏览该文件:会签版现况一致.xlsx
 

 

2、代码

 

Dim Book As New XLS.Book(ProjectPath & "Attachments\\会签版现况一致.xlsx")
\'Dim fl As String = ProjectPath & "Reports\\施工图版物料快速输出.xlsx"
Dim fl As String = "D:\\会签版现况一致.xlsx" \'指定目标文件
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
    Dim i As Integer = 0
    output.show(pic.TopLeftCell.address)
    Dim ar() As String = pic.TopLeftCell.address.split("$")
    If ar(1) = "A" Then
        rng =Ws.Range(pic.TopLeftCell, Ws.Cells(ar(2)+2,5))
    Else
        rng =Ws.Range(pic.TopLeftCell, Ws.Cells(ar(2)+14, 9))
    End If
    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
\'MessageBox.Show("已经导出EXCLE在 D盘 施工图版物料快速输出.xlsx")


--  作者:湛江智
--  发布时间:2018/7/5 18:42:00
--  回复:(有点甜)1、模板?[upload=xlsx,会签...

参照老师的模板,模板改用2张、3张图片,导出图片不居中单元格,请帮助



图片点击可在新窗口打开查看此主题相关图片如下:2张图片 不居中单元格.png
图片点击可在新窗口打开查看

图片点击可在新窗口打开查看此主题相关图片如下:3张图片 不居中单元格.png
图片点击可在新窗口打开查看

[此贴子已经被作者于2018/7/6 9:30:54编辑过]

--  作者:有点甜
--  发布时间:2018/7/5 21:17:00
--  

mark excel图片自动比例

 

Dim Book As New XLS.Book(ProjectPath & "Attachments\\会签版三图部分.xlsx")
\'Dim fl As String = ProjectPath & "Reports\\施工图版物料快速输出.xlsx"
Dim fl As String = "D:\\会签版二图部分.xlsx" \'指定目标文件
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
    Dim i As Integer = 0
    rng = pic.TopLeftCell
    Dim width As Double = 0
    Dim height As Double = 0
    If rng.MergeCells Then
        For Each tempcol As object In rng.MergeArea.Columns
            width = width + tempcol.width
        Next
        For Each temprow As object In rng.MergeArea.Rows
            height = height + temprow.height
        Next
    Else
        width = rng.width
        height = rng.height
    End If
    With Pic
        If .Height / .Width > Height / Width Then
            .Height = Height - 5
            .Top = rng.Top + 2.5
            .Left = rng.Left + (Width - .Width) / 2
            .Placement = 1
        Else
            .Width = Width - 5
            .Left = rng.Left + 2.5
            .Top = rng.Top + (Height - .Height) / 2
            .Placement = 1
        End If
    End With
Next
App.VISIBLE = True
\'MessageBox.Show("已经导出EXCLE在 D盘 施工图版物料快速输出.xlsx")


--  作者:湛江智
--  发布时间:2018/7/13 18:22:00
--  回复:(有点甜)mark excel图片自动比例?Di...
.Height = Height - 50
            .Top = rng.Top + 25
            .Left = rng.Left + (Width - .Width) / 2
            .Placement = 1
        Else
            .Width = Width - 50
            .Left = rng.Left + 25
图片离单元格边线距离在老师基础上扩大10倍,改成上面有问题,怎么修改呢?
扩大8倍数值又怎么修改呢?

[此贴子已经被作者于2018/7/13 18:24:26编辑过]

--  作者:有点甜
--  发布时间:2018/7/13 18:38:00
--  

单独做个例子发上来测试。