找回密码
 加入
搜索
查看: 2518|回复: 6

[AU3基础] 【已解决】调用EXECL出现的小问题

  [复制链接]
发表于 2012-11-5 17:29:22 | 显示全部楼层 |阅读模式
本帖最后由 wanghao4023030 于 2012-11-7 09:31 编辑

大家好,我调用一个execl然后选取一列,做一张图表出来,结果图像显示有黑色的阴影,不知道各位有什么方法没有,感谢赐教。


代码如下:
#cs ----------------------------------------------------------------------------

 AutoIt Version: 3.3.8.1
 Author:         myName

 Script Function:
        Template AutoIt script.

#ce ----------------------------------------------------------------------------

; Script Start - Add your code below here

; ***************************************************************
; Example 1 - Open an existing workbook and returns its object identifier.
; *****************************************************************

#include <Excel.au3>

;~ Local $sFilePath1 = @ScriptDir & "\Test.xls" ;This file should already exist
Local $sFilePath1 = "C:\testfile.csv" ;This file should already exist
Local $oExcel = _ExcelBookOpen($sFilePath1)
        $oExcel.Columns("B:B").Select
    $oExcel.Charts.Add
    $oExcel.Charts.ActiveChart.ChartType = "xlLineMarkers"
        $oExcel.Charts.ActiveChart.SetSourceData.Source =$oExcel.Sheets("testfile").Range("B1:B729")
        $oExcel.Charts.ActiveChart.SetSourceData.PlotBy="xlColumns"
    $oExcel.ActiveChart.Location.Where="xlLocationAsNewSheet"
    With $oExcel.ActiveChart
        .HasTitle = True
        .ChartTitle.Characters.Text = "ProcessTime %"
        .Axes("xlCategory", "xlPrimary").HasTitle = False
        .Axes("xlCategory", "xlPrimary").HasTitle = False
        .Axes("xlValue", "xlPrimary").HasTitle = False
    EndWith
_ExcelSheetAddNew($oExcel,"123")

If @error = 1 Then
    MsgBox(0, "Error!", "Unable to Create the Excel Object")
    Exit
ElseIf @error = 2 Then
    MsgBox(0, "Error!", "File does not exist - Shame on you!")
    Exit
EndIf

本帖子中包含更多资源

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

×
 楼主| 发表于 2012-11-6 09:51:53 | 显示全部楼层
晕倒,我是请假问题,怎么变成分享了。
发表于 2012-11-6 09:58:56 | 显示全部楼层
楼主所说的阴影是指哪部分?另外你插入的是条形图?
 楼主| 发表于 2012-11-6 17:20:54 | 显示全部楼层
本帖最后由 wanghao4023030 于 2012-11-6 17:22 编辑

问题找到了 charttype有问题,造成的 最新代码如下:
#cs ----------------------------------------------------------------------------

 AutoIt Version: 3.3.8.1
 Author:         myName

 Script Function:
        Template AutoIt script.

#ce ----------------------------------------------------------------------------

; Script Start - Add your code below here

; ***************************************************************
; Example 1 - Open an existing workbook and returns its object identifier.
; *****************************************************************

#include <Excel.au3>
#include <File.au3>
#include <ExcelChart.au3>

Dim $sFilePath1,$oExcel


;~ Local $sFilePath1 = @ScriptDir & "\Test.xls" ;This file should already exist
$sFilePath1 = "C:\wanghao.csv" ;This file should already exist
$oExcel = _ExcelBookOpen($sFilePath1)
;~ $oExcel = ObjGet("","Excel.Application")
        $oExcel.Worksheets("wanghao").Activate
        $oExcel.Columns("A:B").Select
        $oExcel.Charts.Add
         $oExcel.ActiveChart.ChartType = "63"        
                $oExcel.ActiveChart.SetSourceData($oExcel.Sheets("wanghao").Range("A:A,B:B"),"xlColumns")
        $oExcel.ActiveChart.Location(2,"123")
    $oExcel.ActiveChart.HasTitle = True
    $oExcel.ActiveChart.ChartTitle.Characters.Text = "ProcessTime %"
;~     $oExcel.ActiveChart.Axes("xlCategory", "xlPrimary").HasTitle = False
;~         $oExcel.ActiveChart.Axes("xlCategory", "xlPrimary").HasTitle = False
;~         $oExcel.ActiveChart.Axes("xlValue", "xlPrimary").HasTitle = False
_ExcelBookSave($oExcel,-1)
;~ _ExcelSheetAddNew($oExcel,"123")
_ExcelBookClose($oExcel)
用字符代替了charttype的英文表示,就他娘的对了,fuck~~~
$oExcel.ActiveChart.ChartType = "63"
发表于 2012-11-6 19:12:08 | 显示全部楼层
原来是用常量名,在au3里一定要用常量值的,除非你声明了常量名对应的常量值
 楼主| 发表于 2012-11-7 09:20:02 | 显示全部楼层
啊 原来如此,气死我了
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-9-29 19:17 , Processed in 0.076353 second(s), 20 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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