pictures物件實作(工程登記卡)

一般的報表常常用Excel實作,但這個報表比較重要的是他需要貼不同型式的渠道示意圖。
有關圖片的部分在填寫竣工資料也有施工照片與查驗照片等等表格,但針對圖片物件的描述並不是那麼豐富,因此本文主要在練習如何使用pictures物件。

pictures物件為picture物件的集合,透過pictures.insert(path)可以將指定的路徑照片給插入,因為有些照片太大或太小,可以使用pictrue物件的width跟height屬性調整,以下先讀取資料庫中的ch_type判斷其為何種型式再用select case去索取需要的照片檔,進而貼上。

圖一、工程登記卡大致長相
圖二、工程登記卡之基本資料庫

Private g_name As String
Public ch_name As String
Private ch_location As String
Public ch_type As Byte
Private ch_se As String
Public ch_length As Double
Private shtModel As Object
Private Sub Class_Initialize()
Set shtModel = Sheets("工程登記卡(模板)")
End Sub

Sub CollectData(ByVal r As Double)

With Sheets("Main")
       'BasicData
    
        g_name = .Cells(r, 1)
        ch_name = .Cells(r, 2)
        ch_location = .Cells(r, 3)
        ch_type = .Cells(r, 4)
        ch_se = Format(.Cells(r, 5), "0+000") & "~" & Format(.Cells(r, 6), "0+000")
        ch_length = .Cells(r, 6) - .Cells(r, 5)

End With
End Sub

Sub CreatePic(ByVal mode As Byte)

Select Case ch_type

Case 1: fsname = "U型溝(簡化).jpg"
Case 2: fsname = "內面工(簡化).jpg"
Case 3: fsname = "砌石工(簡化).jpg"

End Select

Path = ThisWorkbook.Path & "\" & fsname
Set pics = shtModel.Pictures
Set pic = pics.Insert(Path)

Select Case mode

Case 1: l = 300: t = 100: pics.Delete
Case 2: l = 510: t = 100
Case 3: l = 300: t = 225
Case 4: l = 510: t = 225

End Select

pic.Left = l
pic.Top = t
'pic.Width = SigWidth
'pic.height = SigHeight

End Sub


留言

Popular Posts

Excel VBA @ 監造日報表、查驗表 -2

ExcelVBA@施工照片整理的應用範例

Excel VBA@ 監造日報表、查驗表