2016年12月21日 星期三

excel 自動抓欄位資料生成qr code圖檔 貼在指定位置上

b1=qrcode(A1,ROW())

Function qrcode(qr, r)
if qr<>"" then
'因為google qrcode限制,中文需先轉成utf-8格式
'如果只有純英數,等號內的程式碼可以不要,utf8string 用您要的文字取代就可以了
'如果是excel 2013以後的版本,就不用程式碼來轉,記得有一個函數可以轉成utf-8
'=========================================================
'利用jscript來縮短轉成utf-8的程式碼
Dim ScriptEngine As Object
Dim utf8string As String
Set ScriptEngine = CreateObject("scriptcontrol")
ScriptEngine.Language = "JScript"
utf8string = ScriptEngine.Run("encodeURIComponent", qr)
'==========================================================
'取得google qrcode產生的圖片,插入excel表格
Set q = ActiveSheet.Pictures.Insert("https://chart.googleapis.com/chart?chs=70x70&cht=qr&chl=" & utf8string)
'調整圖片位置
With q
.Left = ActiveSheet.Cells(r, 2).Left
.Top = ActiveSheet.Cells(r, 2).Top
End With
end if
qrcode = ""

End Function


程式不用改,一樣可以轉的…重點是有中文就一定要先轉成utf-8,不然google會轉不出來
程式碼中這一串,圖片大小的定義等等…
https://chart.googleapis.com/chart?chs=70x70&cht=qr&chl= ..... ...

請參考google 官方說明修改
https://developers.google.com/chart/infographics/docs/qr_codes?csw=1

barcode 用字型就好了,不用寫程式,快又方便
請google "barcode 字型"

沒有留言:

張貼留言