使用AU3把EXCEL转换成JPG
本人经常使用表格转换成图片的功能,但很多软件需要开会员才能使用。使用前,电脑先安装WPS或者OFFICE。
原理:
读取表格内有数据的部分,然后利用GDIPlus保存成图片。
#include <Excel.au3>
#include <MsgBoxConstants.au3>
#include <ClipBoard.au3>
#include <GDIPlus.au3>
Local $sMessage = "请选择EXCEL文件"
Local $sFileOpenDialog = FileOpenDialog($sMessage, @ScriptDir & "\", "EXCEL文件 (*.xls;*.xlsx)", $FD_FILEMUSTEXIST)
If Not @Error Then
FileChangeDir(@ScriptDir)
$sFileOpenDialog = StringReplace($sFileOpenDialog, "|", @CRLF)
Global $xlScreen = 1
Global $xlPicture = -4147
Global $xlBitmap = 2
Global$oExcel = _Excel_Open(False,True)
Global$oWorkbook = _Excel_BookOpen($oExcel, $sFileOpenDialog, False,False)
$rowcount = $oWorkBook.ActiveSheet.UsedRange.Rows.Count
$columnscount = Chr ( 64 + $oWorkBook.ActiveSheet.UsedRange.Columns.count)
$oWorkbook.ActiveSheet.Range("A1:"&$columnscount&""&$rowcount&"").CopyPicture($xlScreen, $xlBitmap)
If Not _ClipBoard_Open(WinGetHandle(AutoItWinGetTitle())) Then MsgBox(0, "提示", "无法打开剪贴板!")
$hClipboardImage = _ClipBoard_GetDataEx($CF_BITMAP)
_ClipBoard_Close()
_GDIPlus_Startup()
$hBitmap = _GDIPlus_BitmapCreateFromHBITMAP($hClipboardImage)
$sCLSID = _GDIPlus_EncodersGetCLSID("JPG")
_GDIPlus_ImageSaveToFileEx($hBitmap, @ScriptDir & "\" & TimerInit() & "_Clipboard_Image.jpg", $sCLSID, 0)
_GDIPlus_BitmapDispose($hBitmap)
_GDIPlus_Shutdown()
_Excel_Close($oExcel)
Else
MsgBox(64, "提示", "没有选择EXCEL文件!")
EndIf
感谢分享! 感谢分享 感谢分享哈 楼主大侠好,这个能编译下吗?{:1_893:}
页:
[1]