找回密码
 加入
搜索
查看: 6906|回复: 26

[系统综合] 关于将数据写入excel制定单元格的问题

 火.. [复制链接]
发表于 2012-7-28 12:30:55 | 显示全部楼层 |阅读模式
我要将  123  写入到制定表格,如et.els 里面某个单元格,怎么写不进去啊!
#include <Excel.au3>

Local $oExcel = _ExcelBookNew()

_ExcelWriteCell($oExcel, "123", 1, 1)

MsgBox(4096, "Exiting", "Press OK to Save File and Exit")
_ExcelBookSaveAs($oExcel, @TempDir & "\Temp.xls", "xls", 0, 1)
_ExcelBookClose($oExcel)

我是不是错了! 望请指教!
发表于 2012-7-28 13:45:13 | 显示全部楼层
$excel=ObjCreate("excel.application")
$excel.visible=True
$wb=$excel.workbooks.open(@ScriptDir&"et.xls")
$wb.activesheet.range("a1").value=123
$wb.close(True)
$excel.quit
从打开到写入到关闭文件都在这了
 楼主| 发表于 2012-7-28 15:35:16 | 显示全部楼层
你这个提示$excel.visible=True
对象类型不为ObjC
发表于 2012-7-28 17:56:19 | 显示全部楼层
你没安装excel?还是你没有vba环境?不会是你用wps吧?
发表于 2012-7-28 23:00:22 | 显示全部楼层
从打开到写入到关闭文件都在这了
kevinch 发表于 2012-7-28 13:45



$wb = $excel.workbooks.open(@ScriptDir & "\et.xls")
发表于 2012-7-29 01:33:56 | 显示全部楼层
引用你的代码(加了一句代码调试语句可查看路径)
#include <Excel.au3>
MsgBox(0,"路径",@TempDir & "\Temp.xls")
Local $oExcel = _ExcelBookNew() 
_ExcelWriteCell($oExcel, "123", 1, 1) 
MsgBox(4096, "Exiting", "Press OK to Save File and Exit")
_ExcelBookSaveAs($oExcel, @TempDir & "\Temp.xls", "xls", 0, 1) 
_ExcelBookClose($oExcel) 

我在Win7+Office2013的环境下测试完全没问题! 我猜是不是你对这个临时文件夹路径不熟,找不到这个表格,所以~~~ 建议按我的方法到临时文件夹查看,或者修改路径为:@ScriptDir & "\Temp.xls", "xls",代码是这样的:(最后一句关闭表格被注释)
#include <Excel.au3>
MsgBox(0,"路径",@ScriptDir & "\Temp.xls")
Local $oExcel = _ExcelBookNew() 

_ExcelWriteCell($oExcel, "123", 1, 1) 

MsgBox(4096, "Exiting", "Press OK to Save File and Exit")
_ExcelBookSaveAs($oExcel,@ScriptDir & "\Temp.xls", "xls", 0, 1) 
;~ _ExcelBookClose($oExcel) 


本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×
发表于 2012-7-29 08:20:58 | 显示全部楼层
高手真多啊
发表于 2012-7-29 09:21:30 | 显示全部楼层
@scriptdir到底有什么悬机呢?我之前用的au3版本需要加后面的"\",现在的版本不用加,标准不统一?
 楼主| 发表于 2012-7-29 09:28:29 | 显示全部楼层
谢谢大家了!!!
 楼主| 发表于 2012-7-29 09:31:16 | 显示全部楼层
有没有就是不打开,就直接写到指定单元格啊!
 楼主| 发表于 2012-7-29 09:31:25 | 显示全部楼层
有没有就是不打开,就直接写到指定单元格啊!
 楼主| 发表于 2012-7-29 09:31:28 | 显示全部楼层
有没有就是不打开,就直接写到指定单元格啊!
 楼主| 发表于 2012-7-29 09:31:29 | 显示全部楼层
有没有就是不打开,就直接写到指定单元格啊!
 楼主| 发表于 2012-7-29 09:31:52 | 显示全部楼层
有没有就是不用打开,就直接写入到单元格啊!
 楼主| 发表于 2012-7-29 09:31:54 | 显示全部楼层
有没有就是不用打开,就直接写入到单元格啊!
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-5-20 04:02 , Processed in 0.084875 second(s), 25 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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