wanghao4023030 发表于 2012-11-5 17:29:22

【已解决】调用EXECL出现的小问题

本帖最后由 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

wanghao4023030 发表于 2012-11-6 09:51:53

晕倒,我是请假问题,怎么变成分享了。

kevinch 发表于 2012-11-6 09:58:56

楼主所说的阴影是指哪部分?另外你插入的是条形图?

wanghao4023030 发表于 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"

kevinch 发表于 2012-11-6 19:12:08

原来是用常量名,在au3里一定要用常量值的,除非你声明了常量名对应的常量值

wanghao4023030 发表于 2012-11-7 09:20:02

啊 原来如此,气死我了
页: [1]
查看完整版本: 【已解决】调用EXECL出现的小问题