找回密码
 加入
搜索
查看: 3872|回复: 3

[AU3基础] [已解决]导入EXCEL文件后,读取INI文件问题

[复制链接]
发表于 2011-4-27 21:14:20 | 显示全部楼层 |阅读模式
本帖最后由 731106 于 2011-4-28 21:01 编辑

这段代码我怎么搞都不行,如果在代码所在目录导入EXCEL文件(或者不导入),代码就能正常运行,也能读取INI文件,但是如果导入代码所在目录以外EXCEL文件,就无法读取INI文件,到底问题出在哪啊?
INI文件内容:
[1111]
信息=00318300,11020201,01,000655
[2222]
信息=00319300,11020202,01,001432
[3333]
信息=00382300,11020203,01,000670
[4444]
信息=00309300,11020204,01,000670
[5555]
信息=00359300,11020205,01,000654
[6666]
信息=00316300,11020206,01,000669


代码如下:
#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GUIConstants.au3>
#include <Excel.au3>
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <ProgressConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <ComboConstants.au3>
#include <WindowsConstants.au3>

HotKeySet("`", "Terminate")
Func Terminate()
        ProcessClose("EXCEL.exe")
        Exit
EndFunc   ;==>Terminate

TraySetIcon("1.ico", "")

$Form1 = GUICreate("Form1", 350, 200)
$Label1 = GUICtrlCreateLabel("请选择:", 70, 100, 85, 22)
GUICtrlSetFont(-1, 14, 400, 0, "黑体")
$Label2 = GUICtrlCreateLabel("请选择Excel文件:", 22, 16, 218, 22)
GUICtrlSetFont(-1, 14, 400, 0, "黑体")
$Input1 = GUICtrlCreateInput("", 22, 45, 297, 20)
$Button3 = GUICtrlCreateButton("浏  览", 240, 12, 70, 25, 0)
$Combo1 = GUICtrlCreateCombo("", 170, 95, 100, 25)
$Button1 = GUICtrlCreateButton("确 定", 50, 160, 75, 25)
$Button2 = GUICtrlCreateButton("退 出", 230, 160, 75, 25)
GUISetState(@SW_SHOW)

read()
Func read()
        $var = IniReadSectionNames(@ScriptDir & '\123.ini')
        If @error Then
                MsgBox(1 + 4144, "Form1", "配置文件錯誤")
                Exit
        Else
                For $i = 1 To $var[0]
                        GUICtrlSetData($Combo1, $var[$i])
                Next
        EndIf
EndFunc   ;==>read

While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        ProcessClose("EXCEL.exe")
                        Exit
                Case $Button3
                        $folder = FileOpenDialog("浏览", @MyDocumentsDir, "EXCEL 电子表格(*.xls)")
                        If Not @error Then
                                GUICtrlSetData($Input1, $folder)
                                $oExcel = _ExcelBookOpen($folder, 0)
                                Global Const $xlUp = -4162
                                $c = $oExcel.Sheets("Sheet1" ).Range("A65536" ).End($xlUp).Row
                        EndIf
                Case $Button1
                        $bb = GUICtrlRead($Combo1)
                        $txt = IniRead("123.ini", $bb, "信息", "")
                        $array = StringSplit($txt, ",", 1)
                        GUISetState(@SW_HIDE, $Form1)
                        ExitLoop
                Case $Button2
                        _ExcelBookClose($oExcel, 0)
                        Exit
        EndSwitch
WEnd

MsgBox(0, "", "值是: " & @CRLF & $array[1])
MsgBox(0, "", "值是: " & @CRLF & $array[2])
MsgBox(0, "", "值是: " & @CRLF & $array[3])
MsgBox(0, "", "值是: " & @CRLF & $array[4])
 楼主| 发表于 2011-4-28 07:39:52 | 显示全部楼层
本帖最后由 731106 于 2011-4-28 07:44 编辑

又试了一晚上还是不行,帮助也看了,问题到底出在哪里?是不是EXCEL文件非要放在根目录啊?如何不放在根目录里啊
 楼主| 发表于 2011-4-28 21:00:39 | 显示全部楼层
好弱智,问题终于找到,还要继续提高啊,哎
$txt = IniRead("123.ini", $bb, "信息", "")

这句改成
$txt = IniRead(@ScriptDir & '\123.ini',$bb, "信息", "")
这样就行了,一直都没有加\,所以找不到
发表于 2013-8-31 21:48:54 | 显示全部楼层
LZ厉害 。。。。。。。。
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-9-28 21:22 , Processed in 0.113922 second(s), 23 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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