Jump to content

[SOLVED] Insert base64 image in XLS sheet


Recommended Posts

Hi community

I would like to insert a base64 image into an Excel sheet. In fact I would like to avoir external files, so I used base64 image internaly coded

I can't figure out how to do it correctly

This is the code I tried up to now

#include-once
#include <Excel.au3>
Global $oExcel = _Excel_Open ( False, False, False, True, True )
Global $oWorkbook = _Excel_BookOpen ( $oExcel, @ScriptDir & "\Test Graphic.xlsx", True )
Global $Graphic = _Graphic_Base64_Generator ( "WS-C3750V2-48" ) ; <- My picture base64 encoded
With $oWorkbook.Activesheet
    .Shapes.AddPicture ( @ScriptDir & "\Cisco-3750V2-48.jpg", -1, -1, 0, 0, 300, 30 ) ; <- Works fine, original picture
    ;.Shapes.AddPicture ( $Graphic, -1, -1, 0, 0, 300, 30 ) ; <- Doewn't work
EndWith
_Excel_BookSaveAs ( $oWorkbook, @ScriptDir & "\Test Graphic Out.xlsx", Default, True )
_Excel_BookClose ( $oWorkbook, True )
_Excel_Close ( $oExcel, False, True )

Func _Graphic_Base64_Generator ( $sGraphic_Name, $bSaveBinary = False, $sSavePath = @ScriptDir )
    Local $sGraphic_Raw = ""

    Switch $sGraphic_Name
        Case "WS-C3750V2-48"
            $sGraphic_Raw &= '/9j/4AAQSkZJRgABAQEASABIAAD//gATQ3JlYXRlZCB3aXRoIEdJTVD/2wBDAAMCAgMCAgMDAwMEAwMEBQgFBQQEBQoHBwYIDAoMDAsKCwsNDhIQDQ4RDgsLEBYQERMUFRUVDA8XGBYUGBIUFRT/2wBDAQMEBAUEBQkFBQkUDQsNFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBT/wgARCAAeASwDAREAAhEBAxEB/8QAHAAAAgIDAQEAAAAAAAAAAAAAAwQBAgUGBwAI/8QAGAEBAQEBAQAAAAAAAAAAAAAAAAECAwT/2gAMAwEAAhADEAAAAch142l3HnseUhFGeLwagw1pKLSkKxQkMVPBqmgZWUcSSSCC2I1rmsr8dZftEOGh+jGW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694fhjKylYLv79bwYIADWCAixihRlf3nFEKPDZl/pnZjW3DuA/+Oy5UlCUBFmX3giVIIf7fB7fOu4NMo/SDXBmvUZhPEvXTDSOHI7EqUNFQKO7yg7CaXEvHGfE4aRAqYVIEBVYYq8fXUGtCphwMfEzoILxiynyYz45kkKE1qgAbud7QGp7vAK113XodAtgA8NTDFmHGU6LIfnt6fOHFXOikGLFL7vFJQHwGgGj4e9eMusOQHhMhnMRYHglAgVokWHPR4CbkRPQnzx/O/h08BgIB/Dk9cZvIeAsAvuHf63Dlci/9dYnatGkeRrgzXqP7pWHqaw03DmwKJVDRQRbyC+hZolomMnnW8+rVtYACrc4F8U6RJlSH1rvBnAkghBu3F96w1T6QhHAAkgTzOAGcDQkMr4cdKd2QRQkLVv0r7vC39Cx4HfSzgjQgG/53//Z'
    EndSwitch
    Return Binary ( _Graphic_WinAPI_Base64Decode ( $sGraphic_Raw ) )
EndFunc

Func _Graphic_WinAPI_Base64Decode ( $sB64String )
    Local $aCrypt = DllCall ( "Crypt32.dll", "bool", "CryptStringToBinaryA", "str", $sB64String, "dword", 0, "dword", 1, "ptr", 0, "dword*", 0, "ptr", 0, "ptr", 0 )
    If @error Or Not $aCrypt [0] Then Return SetError ( 1, 0, "" )
    Local $bBuffer = DllStructCreate ( "byte[" & $aCrypt [5] & "]" )
    $aCrypt = DllCall ( "Crypt32.dll", "bool", "CryptStringToBinaryA", "str", $sB64String, "dword", 0, "dword", 1, "struct*", $bBuffer, "dword*", $aCrypt [5], "ptr", 0, "ptr", 0 )
    If @error Or Not $aCrypt [0] Then Return SetError ( 2, 0, "" )
    Return DllStructGetData ( $bBuffer, 1 )
EndFunc

Any help appreciated

Best regards

Edited by Ebola57
Link to post
Share on other sites

Hi, 

one solution is to copy the base64 graphics into memory( aka clipboard) and insert it into the excel sheet

#include-once
#include <Excel.au3>
#include <GDIPlus.au3>
#include <Clipboard.au3>

_GDIPlus_Startup()

FileDelete(@ScriptDir & "\Test Graphic Out.xlsx")               ;delete output file

Global $Graphic = _Graphic_Base64_Generator("WS-C3750V2-48")    ; <- My picture base64 encoded

$hClipboard_Bitmap = _GDIPlus_BitmapCreateFromMemory($Graphic, True) ;make bitmap from base64 code
$hHBmp_Clipboard = _WinAPI_CopyImage($hClipboard_Bitmap, 0, 0, 0, BitOR($LR_COPYDELETEORG, $LR_COPYRETURNORG)) ;make image from bitmap

$ret = _WinAPI_Bitmap2Clipboard($hHBmp_Clipboard)               ; copy image to clipboard


Global $oExcel = _Excel_Open(False, False, False, True, True)
Global $oWorkbook = _Excel_BookOpen($oExcel, @ScriptDir & "\Test Graphic.xlsx", True)

$oWorkbook.Activesheet.Range("D8").activate                    ;position of picture
$oWorkbook.Activesheet.paste                                    ;paste image into excel sheet

_Excel_BookSaveAs($oWorkbook, @ScriptDir & "\Test Graphic Out.xlsx", Default, True)
_Excel_BookClose($oWorkbook, True)
_Excel_Close($oExcel, False, True)

ShellExecute(@ScriptDir & "\Test Graphic Out.xlsx")



Func _Graphic_Base64_Generator($sGraphic_Name, $bSaveBinary = False, $sSavePath = @ScriptDir)
    Local $sGraphic_Raw = ""

    Switch $sGraphic_Name
        Case "WS-C3750V2-48"
            $sGraphic_Raw &= '/9j/4AAQSkZJRgABAQEASABIAAD//gATQ3JlYXRlZCB3aXRoIEdJTVD/2wBDAAMCAgMCAgMDAwMEAwMEBQgFBQQEBQoHBwYIDAoMDAsKCwsNDhIQDQ4RDgsLEBYQERMUFRUVDA8XGBYUGBIUFRT/2wBDAQMEBAUEBQkFBQkUDQsNFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBT/wgARCAAeASwDAREAAhEBAxEB/8QAHAAAAgIDAQEAAAAAAAAAAAAAAwQBAgUGBwAI/8QAGAEBAQEBAQAAAAAAAAAAAAAAAAECAwT/2gAMAwEAAhADEAAAAch142l3HnseUhFGeLwagw1pKLSkKxQkMVPBqmgZWUcSSSCC2I1rmsr8dZftEOGh+jG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Q694fhjKylYLv79bwYIADWCAixihRlf3nFEKPDZl/pnZjW3DuA/+Oy5UlCUBFmX3giVIIf7fB7fOu4NMo/SDXBmvUZhPEvXTDSOHI7EqUNFQKO7yg7CaXEvHGfE4aRAqYVIEBVYYq8fXUGtCphwMfEzoILxiynyYz45kkKE1qgAbud7QGp7vAK113XodAtgA8NTDFmHGU6LIfnt6fOHFXOikGLFL7vFJQHwGgGj4e9eMusOQHhMhnMRYHglAgVokWHPR4CbkRPQnzx/O/h08BgIB/Dk9cZvIeAsAvuHf63Dlci/9dYnatGkeRrgzXqP7pWHqaw03DmwKJVDRQRbyC+hZolomMnnW8+rVtYACrc4F8U6RJlSH1rvBnAkghBu3F96w1T6QhHAAkgTzOAGcDQkMr4cdKd2QRQkLVv0r7vC39Cx4HfSzgjQgG/53//Z'
    EndSwitch
    Return Binary(_Graphic_WinAPI_Base64Decode($sGraphic_Raw))
EndFunc                                                         ;==>_Graphic_Base64_Generator

Func _Graphic_WinAPI_Base64Decode($sB64String)
    Local $aCrypt = DllCall("Crypt32.dll", "bool", "CryptStringToBinaryA", "str", $sB64String, "dword", 0, "dword", 1, "ptr", 0, "dword*", 0, "ptr", 0, "ptr", 0)
    If @error Or Not $aCrypt[0] Then Return SetError(1, 0, "")
    Local $bBuffer = DllStructCreate("byte[" & $aCrypt[5] & "]")
    $aCrypt = DllCall("Crypt32.dll", "bool", "CryptStringToBinaryA", "str", $sB64String, "dword", 0, "dword", 1, "struct*", $bBuffer, "dword*", $aCrypt[5], "ptr", 0, "ptr", 0)
    If @error Or Not $aCrypt[0] Then Return SetError(2, 0, "")
    Return DllStructGetData($bBuffer, 1)
EndFunc                                                         ;==>_Graphic_WinAPI_Base64Decode



Func _WinAPI_Bitmap2Clipboard($hHBitmap)
    If Not _ClipBoard_Open(0) Then Return 1
    If Not _ClipBoard_Empty() Then Return 2
    Local Const $hCP = _ClipBoard_SetDataEx($hHBitmap, $CF_BITMAP)
    If Not $hCP Or @error Then Return 3
    _ClipBoard_Close()
    Return 0
EndFunc                                                         ;==>_WinAPI_Bitmap2Clipboard

 

Link to post
Share on other sites

Many thanks, your method works flawlessly, but I forgot to mention that this routine is intensively used. I also need to make it as fast as possible

The alt way, I found is to write a temp pic. file then delete it (but I dislike it, because of temp file)

; 45 ms method
Global $oExcel = _Excel_Open ( False, False, False, True, True )
Global $oWorkbook = _Excel_BookOpen ( $oExcel, @ScriptDir & "\Test Graphic.xlsx", True )

Global $hTimer = TimerInit ( )
Global $sGraphic = _Graphic_Base64_Generator ( "WS-C3750V2-48" ) ; <- My picture base64 encoded
FileWrite ( @ScriptDir & "\Toto.jpg", $sGraphic )
With $oWorkbook.Activesheet
    .Shapes.AddPicture ( @ScriptDir & "\Toto.jpg", -1, -1, 0, 0, 400, 40 )
EndWith
FileDelete ( @ScriptDir & "\Toto.jpg" )
ConsoleWrite ( "Méthode 1 : " & Round ( TimerDiff ( $hTimer ), 2  ) & " ms" & @CRLF )

_Excel_BookSaveAs ( $oWorkbook, @ScriptDir & "\Test Graphic Out 1.xlsx", Default, True )
_Excel_BookClose ( $oWorkbook, True )
_Excel_Close ( $oExcel, False, True )

; 110 ms method
_GDIPlus_Startup ( )
Global $oExcel = _Excel_Open ( False, False, False, True, True )
Global $oWorkbook = _Excel_BookOpen ( $oExcel, @ScriptDir & "\Test Graphic.xlsx", True )

Global $hTimer = TimerInit ( )
Global $Graphic = _Graphic_Base64_Generator ( "WS-C3750V2-48" )
Local $hClipboard_Bitmap = _GDIPlus_BitmapCreateFromMemory ( $Graphic, True )       ; Make bitmap from base64 code
Local $hHBmp_Clipboard = _WinAPI_CopyImage ( $hClipboard_Bitmap, 0, 0, 0, BitOR ( $LR_COPYDELETEORG, $LR_COPYRETURNORG ) ) ;make image from bitmap
$ret = _WinAPI_Bitmap2Clipboard ( $hHBmp_Clipboard )               ; copy image to clipboard
With $oWorkbook.Activesheet
    .Range( "D8" ).Activate                    ;position of picture
    .Paste                                    ;paste image into excel sheet
EndWith
ConsoleWrite ( "Méthode 3 : " & Round ( TimerDiff ( $hTimer ), 2  ) & " ms" & @CRLF )

Do you think there's a way to fasten your method, that is about 120 ms long on my PC ( meaning > 2x longer than with temp. file) ?

Edited by Ebola57
Link to post
Share on other sites
2 hours ago, Ebola57 said:

Do you think there's a way to fasten your method, that is about 120 ms long on my PC ( meaning > 2x longer than with temp. file) ?

Unfortunately not...

The "paste" lasts almost 90-100ms on my PC, while the AddPicture-Method runs under 20ms

An other advantage of the  AddPicture-Method is that you can set the size and rotation of the Picture.

Link to post
Share on other sites
  • Ebola57 changed the title to [SOLVED] Insert base64 image in XLS sheet

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...