[已解决]按顺序出入图片到Excel
本帖最后由 天天笑 于 2018-8-2 08:15 编辑大神们,
有没有办法将一个文件夹下面的所有图片按顺序插入到Excel里面。
需要插入的图片如附件“picture”.zip
生成的Excel如附件“完成后的结果显示”.zip 有看帮助?
#include <Excel.au3>
#include <MsgBoxConstants.au3>
; 创建应用对象并打开示例工作簿
Local $oExcel = _Excel_Open()
If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_PictureAdd 示例", "创建 Excel 应用对象发生错误." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
; 创建新工作簿
Local $oWorkbook = _Excel_BookNew($oExcel)
If @error Then
MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_PictureAdd 示例", "创建工作簿失败." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
_Excel_Close($oExcel)
Exit
EndIf
Local $sPicture = @ScriptDir & "\1.jpg"
_Excel_PictureAdd($oWorkbook, Default, $sPicture, "A2:F24", Default, Default, Default, False)
Local $sPicture2 = @ScriptDir & "\2.jpg"
_Excel_PictureAdd($oWorkbook, Default, $sPicture2, "G2:L24", Default, Default, Default, False)
Local $sPicture3 = @ScriptDir & "\3.jpg"
_Excel_PictureAdd($oWorkbook, Default, $sPicture3, "M2:R24", Default, Default, Default, False)
Local $sPicture4 = @ScriptDir & "\4.jpg"
_Excel_PictureAdd($oWorkbook, Default, $sPicture4, "A25:F49", Default, Default, Default, False)
Local $sPicture5 = @ScriptDir & "\5.jpg"
_Excel_PictureAdd($oWorkbook, Default, $sPicture5, "G25:L49", Default, Default, Default, False)
Local $sPicture6 = @ScriptDir & "\6.jpg"
_Excel_PictureAdd($oWorkbook, Default, $sPicture6, "M25:R49", Default, Default, Default, False)
学习了 来个批量读取
#include <Excel.au3>
#include <MsgBoxConstants.au3>
; 创建应用对象并打开示例工作簿
Local $oExcel = _Excel_Open()
If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_PictureAdd 示例", "创建 Excel 应用对象发生错误." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
; 创建新工作簿
Local $oWorkbook = _Excel_BookNew($oExcel)
If @error Then
MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_PictureAdd 示例", "创建工作簿失败." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
_Excel_Close($oExcel)
Exit
EndIf
Local $iw = 1
Local $ih = 25
Local $ii = 1
Local $iw1 = 1
Local $ih1 = 25
Local $ii1 = 2
Local $iw2 = 1
Local $ih2 = 25
Local $ii2 = 2
For $i = 1 To 17
;Local $sPicture
;Local $sPicture = @ScriptDir & "\"&$ii&".jpg"
Local $sPicture1 = @ScriptDir & "\" & $ii & ".jpg"
Local $sPicture2 = @ScriptDir & "\" & $ii1 & ".jpg"
Local $sPicture3 = @ScriptDir & "\" & $ii2 & ".jpg"
_Excel_PictureAdd($oWorkbook, Default, $sPicture1, "A" & $iw+1 & ":F" & $ih, Default, Default, Default, False)
_Excel_PictureAdd($oWorkbook, Default, $sPicture2, "G" & $iw1+1 & ":L" & $ih1, Default, Default, Default, False)
_Excel_PictureAdd($oWorkbook, Default, $sPicture3, "M" & $iw1+1 & ":R" & $ih2, Default, Default, Default, False)
$iw += 24;1+$ih
$ih += 24
$ii += 3
$iw1 += 24;1+$ih
$ih1 += 24
$ii1 += 3
$iw2 += 24;1+$ih
$ih2 += 24
$ii2 += 3
Next
chzj589 发表于 2018-8-1 13:17
来个批量读取
能给我一下MsgBoxConstants.au3这个吗? 天天笑 发表于 2018-8-1 13:21
能给我一下MsgBoxConstants.au3这个吗?
不需要MsgBoxConstants.au3
#include <Excel.au3>
; 创建应用对象并打开示例工作簿
Local $oExcel = _Excel_Open()
If @error Then Exit MsgBox(0, "Excel UDF: _Excel_PictureAdd 示例", "创建 Excel 应用对象发生错误." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
; 创建新工作簿
Local $oWorkbook = _Excel_BookNew($oExcel)
If @error Then
MsgBox(0, "Excel UDF: _Excel_PictureAdd 示例", "创建工作簿失败." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
_Excel_Close($oExcel)
Exit
EndIf
Local $iw = 1
Local $ih = 25
Local $ii = 1
Local $iw1 = 1
Local $ih1 = 25
Local $ii1 = 2
Local $iw2 = 1
Local $ih2 = 25
Local $ii2 = 3
For $i = 1 To 20
;Local $sPicture
;Local $sPicture = @ScriptDir & "\"&$ii&".jpg"
Local $sPicture1 = @ScriptDir & "\" & $ii & ".jpg"
Local $sPicture2 = @ScriptDir & "\" & $ii1 & ".jpg"
Local $sPicture3 = @ScriptDir & "\" & $ii2 & ".jpg"
_Excel_PictureAdd($oWorkbook, Default, $sPicture1, "A" & $iw+1 & ":F" & $ih, Default, Default, Default, False)
_Excel_PictureAdd($oWorkbook, Default, $sPicture2, "G" & $iw1+1 & ":L" & $ih1, Default, Default, Default, False)
_Excel_PictureAdd($oWorkbook, Default, $sPicture3, "M" & $iw2+1 & ":R" & $ih2, Default, Default, Default, False)
$iw += 24;1+$ih
$ih += 24
$ii += 3
$iw1 += 24;1+$ih
$ih1 += 24
$ii1 += 3
$iw2 += 24;1+$ih
$ih2 += 24
$ii2 += 3
Next
chzj589 发表于 2018-8-1 13:38
不需要MsgBoxConstants.au3
我的Excel.au3和你的有差异,可以提供一下你的给我吗? 天天笑 发表于 2018-8-1 13:54
我的Excel.au3和你的有差异,可以提供一下你的给我吗?
应该是版本问题
我是AutoIt3\(3.3.14.2)版本 chzj589 发表于 2018-8-1 16:32
应该是版本问题
我是AutoIt3\(3.3.14.2)版本
感谢你,问题已经解决~
页:
[1]