请问在Excel里面如何才能直接显示二进制备注字段保存的图片文件字符串?
在不转换成磁盘文件的情况下。
文件 --- 字符串 --- 图片
“文件 --- 字符串”其实都是在文件,只是变了一下位置
直接的不好吗
文件 --- 图片
DECLARE LONG GlobalAlloc IN Kernel32 LONG, LONG DECLARE LONG GlobalLock IN Kernel32 LONG DECLARE LONG GlobalUnlock IN Kernel32 LONG DECLARE LONG GlobalFree IN Kernel32 LONG DECLARE LONG GetDC IN user32 LONG DECLARE LONG ReleaseDC IN user32 LONG, LONG DECLARE LONG CreateCompatibleBitmap IN gdi32 LONG, LONG, LONG DECLARE LONG SetDIBits IN gdi32 LONG, LONG, LONG, LONG, LONG, LONG, LONG DECLARE LONG DeleteObject IN gdi32 LONG DECLARE LONG OpenClipboard IN user32 LONG DECLARE LONG EmptyClipboard IN user32 DECLARE LONG CloseClipboard IN user32 DECLARE LONG SetClipboardData IN user32 LONG, LONG USE 表1 nBufSize = LEN(pp) nOffBits = CTOBIN(SUBSTR(pp,11,4),"4RS") nWidth = CTOBIN(SUBSTR(pp,19,4),"4RS") nHeight = CTOBIN(SUBSTR(pp,23,4),"4RS") LOCAL hImageMemory, pImageMemory hImageMemory = GlobalAlloc(0x42, nBufSize) pImageMemory = GlobalLock(hImageMemory) SYS(2600, pImageMemory, nBufSize, pp) && 载入内存 GlobalUnlock(hImageMemory) USE ** 将图片数据复制到剪贴板 hDC = GetDC(0) hBitmap = CreateCompatibleBitmap(hDC, nWidth, nHeight) && 创建与当前DC兼容的位图 SetDIBits(hDC, hBitmap, 0, nHeight, pImageMemory+nOffBits, pImageMemory+14, 0) && DIB_RGB_COLORS=0使用指定的DIB颜色数据来设置位图中的像素 OpenClipboard(0) EmptyClipboard() SetClipboardData(2, hBitmap) &&CF_BITMAP=2 CloseClipboard() DeleteObject(hBitmap) ReleaseDC(0, hDC) GlobalFree(hImageMemory) ** 粘贴到EXCEL ec = CREATEOBJECT("Excel.Application") ec.DisplayAlerts = 0 ec.WorkBooks.add ec.ActiveSheet.Paste ec.Visible = 1 CLEAR ALL
[此贴子已经被作者于2021-12-23 22:03编辑过]
** Excel显示数据流的图片 picFile = GETPICT("bmp,jpg,png") IF !FILE(picFile) RETURN ENDIF DECLARE long GlobalAlloc IN Kernel32 long,long DECLARE long GlobalLock IN Kernel32 long DECLARE long GlobalUnlock IN Kernel32 long DECLARE long GlobalFree IN Kernel32 long DECLARE long CreateStreamOnHGlobal IN ole32 long,long,long@ DECLARE long GdiplusStartup IN gdiplus long@,string@,long DECLARE long GdiplusShutdown IN gdiplus long DECLARE long GdipLoadImageFromStream IN gdiplus long,long@ DECLARE long GdipDisposeImage IN gdiplus long DECLARE long GdipGetImageDimension IN gdiplus long,single@,single@ DECLARE long GdipSaveImageToStream IN gdiplus long,long,string@,long DECLARE long GetDC IN user32 long DECLARE long ReleaseDC IN user32 long, long DECLARE long CreateCompatibleBitmap IN gdi32 long,long,long DECLARE long SetDIBits IN gdi32 long,long,long,long,long,long,long DECLARE long DeleteObject IN gdi32 long DECLARE long OpenClipboard IN user32 long DECLARE long EmptyClipboard IN user32 DECLARE long CloseClipboard IN user32 DECLARE long SetClipboardData IN user32 long,long stGSI = 0h01000000000000000000000000000000 lpGDI = 0 GdiplusStartup(@lpGDI,@stGSI,0) picStr = FILETOSTR(picFile) nSize = LEN(picStr) hMem = GlobalAlloc(0x42, nSize) pMem = GlobalLock(hMem) pStream = 0 CreateStreamOnHGlobal(hMem, 0, @pStream) && 创建流对象 SYS(2600, pMem, nSize, picStr) && 数据流 GlobalUnlock(hMem) pImage = 0 GdipLoadImageFromStream(pStream, @pImage) && 根据数据流创建图片对象 nWidth = 0 nHeight = 0 GdipGetImageDimension(pImage, @nWidth, @nHeight) hBitMem = GlobalAlloc(0x42, 54+nWidth*nHeight*4) pBitMem = GlobalLock(hBitMem) pBitStream = 0 CreateStreamOnHGlobal(hBitMem, 0, @pBitStream) CLSID_BMP = 0h00F47C55041AD3119A730000F81EF32E GdipSaveImageToStream(pImage, pBitStream, CLSID_BMP, 0) GlobalUnlock(hBitMem) nOffBits = CTOBIN(SYS(2600,pBitMem+10,4),"4RS") nWidth = CTOBIN(SYS(2600,pBitMem+18,4),"4RS") nHeight = CTOBIN(SYS(2600,pBitMem+22,4),"4RS") hDC = GetDC(0) hBitmap = CreateCompatibleBitmap(hDC, nWidth, nHeight) SetDIBits(hDC, hBitmap, 0, nHeight, pBitMem+nOffBits, pBitMem+14, 0) OpenClipboard(0) EmptyClipboard() SetClipboardData(2, hBitmap) CloseClipboard() DeleteObject(hBitmap) ReleaseDC(0, hDC) GlobalFree(hBitMem) GdipDisposeImage(pImage) GlobalFree(hMem) GdiplusShutdown(lpGDI) ec = CREATEOBJECT("Excel.Application") ec.DisplayAlerts = 0 ec.WorkBooks.add ec.ActiveSheet.Paste ec.Visible = 1 CLEAR ALL