[已解决]导入EXCEL文件后,读取INI文件问题
本帖最后由 731106 于 2011-4-28 21:01 编辑这段代码我怎么搞都不行,如果在代码所在目录导入EXCEL文件(或者不导入),代码就能正常运行,也能读取INI文件,但是如果导入代码所在目录以外EXCEL文件,就无法读取INI文件,到底问题出在哪啊?
INI文件内容:
信息=00318300,11020201,01,000655
信息=00319300,11020202,01,001432
信息=00382300,11020203,01,000670
信息=00309300,11020204,01,000670
信息=00359300,11020205,01,000654
信息=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
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)
MsgBox(0, "", "值是: " & @CRLF & $array)
MsgBox(0, "", "值是: " & @CRLF & $array)
MsgBox(0, "", "值是: " & @CRLF & $array) 本帖最后由 731106 于 2011-4-28 07:44 编辑
又试了一晚上还是不行,帮助也看了,问题到底出在哪里?是不是EXCEL文件非要放在根目录啊?如何不放在根目录里啊 好弱智,问题终于找到,还要继续提高啊,哎
$txt = IniRead("123.ini", $bb, "信息", "")
这句改成
$txt = IniRead(@ScriptDir & '\123.ini',$bb, "信息", "")
这样就行了,一直都没有加\,所以找不到 LZ厉害 。。。。。。。。
页:
[1]