找回密码
 加入
搜索
楼主: itzyx

[网络通信] 已解决 求助! EXCEL怎么读取 写入值错误

[复制链接]
发表于 2020-9-19 23:47:36 | 显示全部楼层
手机打字,没调试,
$aResult…返回的是单元格内容的数组,
_ArrayToString($aResult,@CR)……返回文本字符

msgboxMsgBox($MB_SYSTEMMODAL, "", _ArrayToString($aResult,@CR)

这样写的话,最右边是不是少了个右括号…………手机没调试………试试看
MsgBox($MB_SYSTEMMODAL, "", _ArrayToString($aResult,@CR))
发表于 2020-9-20 12:02:19 | 显示全部楼层
itzyx 发表于 2020-9-19 22:56
大佬您的方法没有问题, 但是我有个疑惑,想请教您,希望能够帮忙解答一下,感谢。
关于 $sresult =_Arr ...
#include <Array.au3>
#include<Excel.au3>
Local $oExcel = _Excel_Open()
Local $oWorkbook = _Excel_BookOpen($oExcel, @DesktopDir&"\新建 Microsoft Excel 工作表.xls");自己的桌面文档名称,自行更改
Local $aResult = _Excel_RangeRead($oWorkbook, "Sheet1","A1:A8")   ;读取Sheet1 里面A1-A8的内容
_ArrayDisplay($aResult,'Debug~~~')

$sresult =_ArrayToString($aResult,@CR)
MsgBox(262144,'Debug line ~' & @ScriptLineNumber,'Selection:' & @lf & '$sresult' & @lf & @lf & 'Return:' & @lf & $sresult & @lf & @lf & '@Error:' & @lf & @Error) ;### Debug MSGBOX
$zresult=StringRegExpReplace($sresult, '(\d+)\.(\d{3})\.(\d{3})', '$1.$2$3') ;利用正则替换小数点
MsgBox(262144,'Debug line ~' & @ScriptLineNumber,'Selection:' & @lf & '$zresult' & @lf & @lf & 'Return:' & @lf & $zresult & @lf & @lf & '@Error:' & @lf & @Error) ;### Debug MSGBOX

MsgBox($MB_SYSTEMMODAL, "", _ArrayToString($aResult,@CR));补充右括号之后。。。。。。。。。。。。。。。。

$aResult2=StringSplit($zresult, @CR,2);2, 关闭第一个元素中的返回数量 
_ArrayDisplay($aResult2,'Debug~~~')

_Excel_RangeWrite($oWorkbook,"Sheet1",$aResult2,"B1:B8",True) ;写入到B1:B8里面 
Local $FileNew = StringFormat('%04s%02s%02s_%02d%02d%02d.xls', @YEAR, @MON, @MDAY, @HOUR, @MIN, @SEC)  ;以当前时间给工作表命名
_Excel_BookSaveAs($oWorkbook, @DesktopDir & "" &$FileNew , Default, True)
 楼主| 发表于 2020-9-20 18:23:20 | 显示全部楼层
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-4-27 10:16 , Processed in 0.067495 second(s), 14 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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