本帖最后由 tubaba 于 2017-6-27 10:37 编辑
再不明白,我建议好好学习数组方面的基本知识
#include <Array.au3>
For $i = 0 To $iItemCount - 1
$aText[$i][0] = ControlListView('', '', 1703, 'GetText', $i, 0)
$aText[$i][1] = ControlListView('', '', 1703, 'GetText', $i, 1)
$aText[$i][2] = ControlListView('', '', 1703, 'GetText', $i, 2)
$aText[$i][3] = ControlListView('', '', 1703, 'GetText', $i, 3)
$aText[$i][4] = ControlListView('', '', 1703, 'GetText', $i, 4)
Next
_ArrayDisplay($aText);我不管你前面的代码,我只是假设你得到了$aText这个数组
_SaveToCsv1($aText, @ScriptDir & '\out.csv') ;写入文件
Local $out = _SaveToCsv2($aText);放入字符串变量
MsgBox(0, 0, $out) ;显示这个字符串变量
Func _SaveToCsv1($aArray, $sCsvSavePath)
Local $csv = FileOpen($sCsvSavePath, 2 + 8)
If UBound($aArray, 0) = 1 Then
For $i = 0 To UBound($aArray) - 1
Local $sStr = '"' & StringReplace($aArray[$i][$j], '"', '""') & '"'
FileWriteLine($csv, $sStr)
Next
ElseIf UBound($aArray, 0) = 2 Then
For $i = 0 To UBound($aArray, 1) - 1
Local $sStr = ''
For $j = 0 To UBound($aArray, 2) - 1
$sStr &= '"' & StringReplace($aArray[$i][$j], '"', '""') & '",'
Next
$sStr = StringTrimRight($sStr, 1)
FileWriteLine($csv, $sStr)
Next
EndIf
FileClose($csv)
EndFunc ;==>_SaveToCsv1
;如果不想写到文件,放入一个字符串变量,那么,如下
Func _SaveToCsv2($aArray)
Local $AllData = '' ;定义一个空字串,接收数据
If UBound($aArray, 0) = 1 Then
For $i = 0 To UBound($aArray) - 1
Local $sStr = '"' & StringReplace($aArray[$i][$j], '"', '""') & '"'
$AllData &= $sStr & @CRLF
Next
ElseIf UBound($aArray, 0) = 2 Then
For $i = 0 To UBound($aArray, 1) - 1
Local $sStr = ''
For $j = 0 To UBound($aArray, 2) - 1
$sStr &= '"' & StringReplace($aArray[$i][$j], '"', '""') & '",'
Next
$sStr = StringTrimRight($sStr, 1)
$AllData &= $sStr & @CRLF
Next
$AllData = StringTrimRight($AllData, 1)
EndIf
Return $AllData
EndFunc ;==>_SaveToCsv2
|