找回密码
 加入
搜索
查看: 3319|回复: 1

[网络通信] excel操作问题(已经解决)

[复制链接]
发表于 2015-2-27 15:13:50 | 显示全部楼层 |阅读模式
本帖最后由 ak47gglllk 于 2015-3-1 17:02 编辑
#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <ListViewConstants.au3>
#include <Excel.au3>
#Include <WinAPIEx.au3>


Global $yonghuming,$shangpingmingcheng,$shuliang,$fapiaohaoma,$danwei,$danjia,$jiage,$zongjia,$tianjia,$daying,$neirong
_maingui()
#Region ### START Koda GUI section ### Form=
Func _maingui()
$Form1 = GUICreate("Form1", 634, 476, 187, 124)
$Label1 = GUICtrlCreateLabel("销售清单", 248, 8, 112, 31)
GUICtrlSetFont(-1, 20, 400, 0, "宋体")
$Label2 = GUICtrlCreateLabel("用户名称:", 32, 48, 63, 17)
GUICtrlSetFont(-1, 10, 400, 0, "宋体")
$yonghuming = GUICtrlCreateInput("", 128, 48, 121, 21)
$Label3 = GUICtrlCreateLabel("发票号码:", 288, 48, 69, 17)
GUICtrlSetFont(-1, 10, 400, 0, "宋体")
$fapiaohaoma = GUICtrlCreateInput("", 392, 48, 121, 21)
$shangpingmingcheng = GUICtrlCreateCombo("", 128, 96, 121, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL))
GUICtrlSetData(-1, "1|2|3|4|5|6|7|8|9|")
$Label4 = GUICtrlCreateLabel("商品名称:", 32, 96, 64, 17)
$Label5 = GUICtrlCreateLabel("单位:", 288, 96, 40, 17)
$danwei = GUICtrlCreateCombo("", 392, 96, 121, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL))
GUICtrlSetData(-1, "1|2|3|4|5|6|7|8|9")
$Label6 = GUICtrlCreateLabel("数量:", 40, 144, 40, 17)
$shuliang = GUICtrlCreateInput("", 128, 144, 121, 21,$ES_NUMBER)
$Label7 = GUICtrlCreateLabel("单价:", 288, 144, 40, 17)
$danjia = GUICtrlCreateInput("", 392, 144, 121, 21,$ES_NUMBER)
$neirong = GUICtrlCreateListView("用户名称|发票号码|商品名称|单位|数量|单价|价格|", 24, 220, 586, 200, -1, BitOR($WS_EX_CLIENTEDGE,$LVS_EX_GRIDLINES))
$tianjia = GUICtrlCreateButton("添加", 256, 176, 75, 25)
$daying = GUICtrlCreateButton("打印", 264, 432, 75, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
EndFunc

Func _daying()
        $excel=ObjCreate("excel.application")
        $excel.visible=False ;值为true则显示窗口
    $wb=$excel.workbooks.open(@DesktopDir&"\销售清单.xls")
    $wb.activesheet.range("B2").value=GUICtrlRead($yonghuming)
    $wb.activesheet.range("F2").value=GUICtrlRead($fapiaohaoma)
    $wb.activesheet.range("B4").value=GUICtrlRead($shangpingmingcheng)
    $wb.activesheet.range("C4").value=GUICtrlRead($danwei)
    $wb.activesheet.range("D4").value=GUICtrlRead($shuliang)
        $wb.activesheet.range("E4").value=GUICtrlRead($danjia)
        $wb.activesheet.range("I8").value=""
    $wb.close(True)
    $excel.quit
        
        Local $dayingji = _WinAPI_GetDefaultPrinter ( )
        If @error Then
                MsgBox(64,"错误","没有打印机,请添加")
                Return
        EndIf
        
        $o_Workbook=objget(@desktopdir&"\销售清单.xls")
        for $o_WS in $o_Workbook.worksheets
                $o_WS.printout
        next
        $o_Workbook.close(false)

EndFunc

While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                        Case $GUI_EVENT_CLOSE
                                Exit
                                
                        Case $tianjia
                                $jiage = GUICtrlRead($danjia) * GUICtrlRead($shuliang)
                                ConsoleWrite($shuliang)
                                GUICtrlCreateListViewItem(GUICtrlRead($yonghuming)&"|"&GUICtrlRead($fapiaohaoma)&"|"&GUICtrlRead($shangpingmingcheng)&"|"&GUICtrlRead($danwei)&"|"&GUICtrlRead($shuliang)&"|"&GUICtrlRead($danjia)&"|"&$jiage,$neirong)
                        Case $daying
                                _daying()
        EndSwitch
WEnd
现在能写入一次,求能重复写入。感谢大大,非常感谢。求万能的大大帮助   


感谢各位大大的帮助和支持

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×
发表于 2015-3-1 12:13:17 | 显示全部楼层
回复 1# ak47gglllk
嵌入式随你怎么写,Excel本来就能操作,用AU3不是多此?

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-12-28 03:38 , Processed in 0.072563 second(s), 22 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表