找回密码
 加入
搜索
查看: 71750|回复: 153

[原创] Excel

[复制链接]
发表于 2008-8-12 06:54:50 | 显示全部楼层 |阅读模式
大家收收看囉
[AU3] excel 相關操作
;====================================================================
;檔案相關
;====================================================================
; 開一個新的 excel
_ExcelBookNew($fVisible = 1)  

; 開啟一個存在的檔案
_ExcelBookOpen($sFilePath, $fVisible = 1, $fReadOnly = False)

; 開啟一個 文字型的 象csv 那種的             $sDelimiter  分隔符號 預設是逗點
_ExcelBookOpenTxt($sFilePath, $sDelimiter = ",", $iStartRow = 1, $iDataType = 1, $iTextQualifier = 1, $fConsecDelim = False, $fVisible = 1)

;存檔
_ExcelBookSave($oExcel, $fAlerts = 0)

; 另存新檔
_ExcelBookSaveAs($oExcel, $sFilePath, $sType = "xls", $fAlerts = 0, $fOverWrite = 0)
#CS
                If $sType = "xls" Then $sType = $xlNormal
                If $sType = "csv" Then $sType = $xlCSVMSDOS
                If $sType = "txt" Then $sType = $xlTextWindows
                If $sType = "template" Then $sType = $xlTemplate
                If $sType = "html" Then $sType = $xlHtml
#CE

;關閉
_ExcelBookClose($oExcel, $fSave = 1, $fAlerts = 0)

; 沒用過 看的見看不見
_ExcelShow($oExcel)
_ExcelHide($oExcel)

;====================================================================
;重頭戲
;====================================================================

; 讀寫  資料
_ExcelWriteCell($oExcel, $sValue, $sRangeOrRow, $iColumn = 1)  
_ExcelReadCell($oExcel, $sRangeOrRow, $iColumn = 1)

;寫入公式 沒用過
_ExcelWriteFormula($oExcel, $sFormula, $sRangeOrRow, $iColumn = 1)

; 讀寫資料  ARRAY
_ExcelWriteArray($oExcel, $iStartRow, $iStartColumn, $aArray, $iDirection = 0, $iIndexBase = 0)
_ExcelReadArray($oExcel, $iStartRow, $iStartColumn, $iNumCells, $iDirection = 0, $iIndexBase = 0)

;覆制 貼上
_ExcelCopy($oExcel, $sRangeOrRowStart, $iColStart = 1, $iRowEnd = 1, $iColEnd = 1)
_ExcelPaste($oExcel, $sRangeOrRow, $iColumn = 1)

;  插入 沒用過
_ExcelInsert($oExcel, $sRangeOrRow, $iColumn = 1, $iShiftDirection = -4121)

; 整列操作  刪列 新增列    ==
_ExcelRowDelete($oExcel, $iRow, $iNumRows = 1)
_ExcelRowInsert($oExcel, $iRow, $iNumRows = 1)


; 整欄操作  刪欄  新增欄   ||
_ExcelColumnDelete($oExcel, $iColumn, $iNumCols = 1)
_ExcelColumnInsert($oExcel, $iColumn, $iNumCols = 1)

;====================================================================
;;其他功能
;====================================================================

; 搜尋  很好用    找字串 $sFindWhat
_ExcelFindInRange($oExcel, $sFindWhat, $sRangeOrRowStart, $iColStart = 1, $iRowEnd = 1, $iColEnd = 1, $iDataType = 0, $iWholeOrPart = 2, $fMatchCase = False, $fMatchFormat = False)

;範圍內取代
_ExcelReplaceInRange($oExcel, $sFindWhat, $sReplaceWith, $sRangeOrRowStart, $iColStart = 1, $iRowEnd = 1, $iColEnd = 1, $iWholeOrPart = 2, $fMatchCase = False, $fMatchFormat = False, $fReplaceFormat = False)



;====================================================================
; 格式相關  
;====================================================================
;set 為設定  get 為取得

; 字型相關   
; 設定字型   粗體  斜體 底線
_ExcelFontSetProperties($oExcel, $sRangeOrRowStart, $iColStart = 1, $iRowEnd = 1, $iColEnd = 1, $fBold = False, $fItalic = False, $fUnderline = False)

;設定字型   字體
_ExcelFontSet($oExcel, $sRangeOrRowStart, $iColStart = 1, $iRowEnd = 1, $iColEnd = 1, $sFontName = "Arial")
_ExcelFontGet($oExcel, $sRangeOrRow, $iColumn = 1)

;字體大小
_ExcelFontSetSize($oExcel, $sRangeOrRowStart, $iColStart = 1, $iRowEnd = 1, $iColEnd = 1, $iFontSize = 10)
_ExcelFontGetSize($oExcel, $sRangeOrRow, $iColumn = 1)

;字體顏色
_ExcelFontSetColor($oExcel, $sRangeOrRowStart, $iColStart = 1, $iRowEnd = 1, $iColEnd = 1, $iColorIndex = 1, $hColor = 0x000000)
_ExcelFontGetColor($oExcel, $sRangeOrRow, $iColumn = 1)

;格子的顏色
_ExcelCellColorSet($oExcel, $sRangeOrRowStart, $iColStart = 1, $iRowEnd = 1, $iColEnd = 1, $iColorIndex = 1, $hColor = 0x000000)
_ExcelCellColorGet($oExcel, $sRangeOrRow, $iColumn = 1)

;寬度  
_ExcelColWidthSet($oExcel, $vColumn, $vWidth)
_ExcelColWidthGet($oExcel, $vColumn)

;高度
_ExcelRowHeightSet($oExcel, $iRow, $vHeight)
_ExcelRowHeightGet($oExcel, $iRow)

;??
_ExcelCellFormat($oExcel, $sRangeOrRowStart, $iColStart = 1, $iRowEnd = 1, $iColEnd = 1, $fWrapText = False, $iOrientation = 0, $fAddIndent = False, $iIndentLevel = 0, $fShrinkToFit = False)


;====================================================================
; 試算表的動作
;====================================================================
;目標指向 該頁
_ExcelSheetActivate($oExcel, $vSheet)
;移動
_ExcelSheetMove($oExcel, $vMoveSheet, $vRelativeSheet = 1, $fBefore = True)
;新增
_ExcelSheetAddNew($oExcel, $sName = "")
;取得目前的名稱
_ExcelSheetNameGet($oExcel)
; 改名稱  or 設定名稱
_ExcelSheetNameSet($oExcel, $sSheetName)
;刪除頁
_ExcelSheetDelete($oExcel, $vSheet, $fAlerts = False)
; 取回頁  列表  array
_ExcelSheetList($oExcel)

;====================================================================
;比較少用到的函數
;====================================================================


;排序  沒用過
_ExcelSort($oExcel, $sKey, $sRangeOrRowStart, $iColStart = 1, $iRowEnd = 1, $iColEnd = 1, $iDirection = 2)
_ExcelSortExtended($oExcel, $sKey, $sRangeOrRowStart, $iColStart = 1, $iRowEnd = 1, $iColEnd = 1, $iDirection = 2, $iHeader = 0, $fMatchCase = False, $iOrientation = 2, $iDataOption = 0)

; 註解
_ExcelCommentAdd($oExcel, $sComment, $sRangeOrRow, $iColumn = 1, $fVisible = 0)
_ExcelCommentDelete($oExcel, $sRangeOrRowStart, $iColStart = 1, $iRowEnd = 1, $iColEnd = 1)
_ExcelCommentShow($oExcel, $sRangeOrRowStart, $iColStart = 1, $iRowEnd = 1, $iColEnd = 1, $fVisible = False)
_ExcelCommentRead($oExcel, $sRangeOrRow, $iColumn = 1)

;切開
_ExcelSplitWindow($oExcel, $iSplitRow, $iSplitColumn)

;不曉得怎麼用的
_ExcelNumberFormat($oExcel, $sFormat, $sRangeOrRowStart, $iColStart = 1, $iRowEnd = 1, $iColEnd = 1)
_ExcelPictureInsert($oExcel, $sFilePath, $iLeft, $iTop, $iWidth, $iHeight, $fLinkToFile = False, $fSaveWithDoc = False)
_ExcelPictureAdjust($oPicture, $iHorizontal, $iVertical, $iRotation = 0)
_ExcelPictureScale($oPicture, $nScaleWidth = 1, $nScaleHeight = 1, $fScaleOrigWidth = True, $fScaleOrigHeight = True, $iScaleFrom = 0)
_ExcelHyperlinkInsert($oExcel, $sLinkText, $sAddress, $sScreenTip, $sRangeOrRow, $iColumn = 1)


_ExcelCellMerge($oExcel, $fDoMerge, $sRangeOrRowStart, $iColStart = 1, $iRowEnd = 1, $iColEnd = 1)
_ExcelSheetUsedRangeGet($oExcel, $vSheet)

_ExcelHorizontalAlignSet($oExcel, $sRangeOrRowStart, $iColStart = 1, $iRowEnd = 1, $iColEnd = 1, $sHorizAlign = "left")
_ExcelVerticalAlignSet($oExcel, $sRangeOrRowStart, $iColStart = 1, $iRowEnd = 1, $iColEnd = 1, $sVertAlign = "bottom")

本帖子中包含更多资源

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

×

评分

参与人数 2金钱 +35 贡献 +7 收起 理由
zldfsz + 30 + 5 感谢
lynfr8 + 5 + 2 好东西,谢谢注释!

查看全部评分

发表于 2009-6-29 13:44:05 | 显示全部楼层
弄个简体版

[AU3] excel 相关操作
;====================================================================
;档案相关
;====================================================================
; 开一个新的 excel
_ExcelBookNew($fVisible = 1)  

; 开启一个存在的档案
_ExcelBookOpen($sFilePath, $fVisible = 1, $fReadOnly = False)

; 开启一个 文字型的 象csv 那种的             $sDelimiter  分隔符号 预设是逗点
_ExcelBookOpenTxt($sFilePath, $sDelimiter = ",", $iStartRow = 1, $iDataType = 1, $iTextQualifier = 1, $fConsecDelim = False, $fVisible = 1)

;存档
_ExcelBookSave($oExcel, $fAlerts = 0)

; 另存新档
_ExcelBookSaveAs($oExcel, $sFilePath, $sType = "xls", $fAlerts = 0, $fOverWrite = 0)
#CS
                If $sType = "xls" Then $sType = $xlNormal
                If $sType = "csv" Then $sType = $xlCSVMSDOS
                If $sType = "txt" Then $sType = $xlTextWindows
                If $sType = "template" Then $sType = $xlTemplate
                If $sType = "html" Then $sType = $xlHtml
#CE

;关闭
_ExcelBookClose($oExcel, $fSave = 1, $fAlerts = 0)

; 没用过 看的见看不见
_ExcelShow($oExcel)
_ExcelHide($oExcel)

;====================================================================
;重头戏
;====================================================================

; 读写  资料
_ExcelWriteCell($oExcel, $sValue, $sRangeOrRow, $iColumn = 1)  
_ExcelReadCell($oExcel, $sRangeOrRow, $iColumn = 1)

;写入公式 没用过
_ExcelWriteFormula($oExcel, $sFormula, $sRangeOrRow, $iColumn = 1)

; 读写资料  ARRAY
_ExcelWriteArray($oExcel, $iStartRow, $iStartColumn, $aArray, $iDirection = 0, $iIndexBase = 0)
_ExcelReadArray($oExcel, $iStartRow, $iStartColumn, $iNumCells, $iDirection = 0, $iIndexBase = 0)

;覆制 贴上
_ExcelCopy($oExcel, $sRangeOrRowStart, $iColStart = 1, $iRowEnd = 1, $iColEnd = 1)
_ExcelPaste($oExcel, $sRangeOrRow, $iColumn = 1)

;  插入 没用过
_ExcelInsert($oExcel, $sRangeOrRow, $iColumn = 1, $iShiftDirection = -4121)

; 整列操作  删列 新增列    ==
_ExcelRowDelete($oExcel, $iRow, $iNumRows = 1)
_ExcelRowInsert($oExcel, $iRow, $iNumRows = 1)


; 整栏操作  删栏  新增栏   ||
_ExcelColumnDelete($oExcel, $iColumn, $iNumCols = 1)
_ExcelColumnInsert($oExcel, $iColumn, $iNumCols = 1)

;====================================================================
;;其他功能
;====================================================================

; 搜寻  很好用    找字串 $sFindWhat
_ExcelFindInRange($oExcel, $sFindWhat, $sRangeOrRowStart, $iColStart = 1, $iRowEnd = 1, $iColEnd = 1, $iDataType = 0, $iWholeOrPart = 2, $fMatchCase = False, $fMatchFormat = False)

;范围内取代
_ExcelReplaceInRange($oExcel, $sFindWhat, $sReplaceWith, $sRangeOrRowStart, $iColStart = 1, $iRowEnd = 1, $iColEnd = 1, $iWholeOrPart = 2, $fMatchCase = False, $fMatchFormat = False, $fReplaceFormat = False)



;====================================================================
; 格式相关  
;====================================================================
;set 为设定  get 为取得

; 字型相关   
; 设定字型   粗体  斜体 底线
_ExcelFontSetProperties($oExcel, $sRangeOrRowStart, $iColStart = 1, $iRowEnd = 1, $iColEnd = 1, $fBold = False, $fItalic = False, $fUnderline = False)

;设定字型   字体
_ExcelFontSet($oExcel, $sRangeOrRowStart, $iColStart = 1, $iRowEnd = 1, $iColEnd = 1, $sFontName = "Arial")
_ExcelFontGet($oExcel, $sRangeOrRow, $iColumn = 1)

;字体大小
_ExcelFontSetSize($oExcel, $sRangeOrRowStart, $iColStart = 1, $iRowEnd = 1, $iColEnd = 1, $iFontSize = 10)
_ExcelFontGetSize($oExcel, $sRangeOrRow, $iColumn = 1)

;字体颜色
_ExcelFontSetColor($oExcel, $sRangeOrRowStart, $iColStart = 1, $iRowEnd = 1, $iColEnd = 1, $iColorIndex = 1, $hColor = 0x000000)
_ExcelFontGetColor($oExcel, $sRangeOrRow, $iColumn = 1)

;格子的颜色
_ExcelCellColorSet($oExcel, $sRangeOrRowStart, $iColStart = 1, $iRowEnd = 1, $iColEnd = 1, $iColorIndex = 1, $hColor = 0x000000)
_ExcelCellColorGet($oExcel, $sRangeOrRow, $iColumn = 1)

;宽度  
_ExcelColWidthSet($oExcel, $vColumn, $vWidth)
_ExcelColWidthGet($oExcel, $vColumn)

;高度
_ExcelRowHeightSet($oExcel, $iRow, $vHeight)
_ExcelRowHeightGet($oExcel, $iRow)

;??
_ExcelCellFormat($oExcel, $sRangeOrRowStart, $iColStart = 1, $iRowEnd = 1, $iColEnd = 1, $fWrapText = False, $iOrientation = 0, $fAddIndent = False, $iIndentLevel = 0, $fShrinkToFit = False)


;====================================================================
; 试算表的动作
;====================================================================
;目标指向 该页
_ExcelSheetActivate($oExcel, $vSheet)
;移动
_ExcelSheetMove($oExcel, $vMoveSheet, $vRelativeSheet = 1, $fBefore = True)
;新增
_ExcelSheetAddNew($oExcel, $sName = "")
;取得目前的名称
_ExcelSheetNameGet($oExcel)
; 改名称  or 设定名称
_ExcelSheetNameSet($oExcel, $sSheetName)
;删除页
_ExcelSheetDelete($oExcel, $vSheet, $fAlerts = False)
; 取回页  列表  array
_ExcelSheetList($oExcel)

;====================================================================
;比较少用到的函数
;====================================================================


;排序  没用过
_ExcelSort($oExcel, $sKey, $sRangeOrRowStart, $iColStart = 1, $iRowEnd = 1, $iColEnd = 1, $iDirection = 2)
_ExcelSortExtended($oExcel, $sKey, $sRangeOrRowStart, $iColStart = 1, $iRowEnd = 1, $iColEnd = 1, $iDirection = 2, $iHeader = 0, $fMatchCase = False, $iOrientation = 2, $iDataOption = 0)

; 注解
_ExcelCommentAdd($oExcel, $sComment, $sRangeOrRow, $iColumn = 1, $fVisible = 0)
_ExcelCommentDelete($oExcel, $sRangeOrRowStart, $iColStart = 1, $iRowEnd = 1, $iColEnd = 1)
_ExcelCommentShow($oExcel, $sRangeOrRowStart, $iColStart = 1, $iRowEnd = 1, $iColEnd = 1, $fVisible = False)
_ExcelCommentRead($oExcel, $sRangeOrRow, $iColumn = 1)

;切开
_ExcelSplitWindow($oExcel, $iSplitRow, $iSplitColumn)

;不晓得怎么用的
_ExcelNumberFormat($oExcel, $sFormat, $sRangeOrRowStart, $iColStart = 1, $iRowEnd = 1, $iColEnd = 1)
_ExcelPictureInsert($oExcel, $sFilePath, $iLeft, $iTop, $iWidth, $iHeight, $fLinkToFile = False, $fSaveWithDoc = False)
_ExcelPictureAdjust($oPicture, $iHorizontal, $iVertical, $iRotation = 0)
_ExcelPictureScale($oPicture, $nScaleWidth = 1, $nScaleHeight = 1, $fScaleOrigWidth = True, $fScaleOrigHeight = True, $iScaleFrom = 0)
_ExcelHyperlinkInsert($oExcel, $sLinkText, $sAddress, $sScreenTip, $sRangeOrRow, $iColumn = 1)


_ExcelCellMerge($oExcel, $fDoMerge, $sRangeOrRowStart, $iColStart = 1, $iRowEnd = 1, $iColEnd = 1)
_ExcelSheetUsedRangeGet($oExcel, $vSheet)

_ExcelHorizontalAlignSet($oExcel, $sRangeOrRowStart, $iColStart = 1, $iRowEnd = 1, $iColEnd = 1, $sHorizAlign = "left")
_ExcelVerticalAlignSet($oExcel, $sRangeOrRowStart, $iColStart = 1, $iRowEnd = 1, $iColEnd = 1, $sVertAlign = "bottom")
发表于 2008-8-14 14:24:16 | 显示全部楼层
3.2.13.6.1:里已经集成了excel的udf了,一批很详细的说明了
发表于 2008-8-14 17:25:24 | 显示全部楼层
越来越牛X!!!!!!!!
发表于 2008-8-17 11:51:29 | 显示全部楼层
学习了,谢谢分享。
发表于 2009-4-20 08:55:56 | 显示全部楼层
越来越牛X!!!!!!!!
发表于 2009-4-25 08:58:45 | 显示全部楼层
不错,学习了!
发表于 2009-4-27 10:08:01 | 显示全部楼层
的确是越来越强大了...
发表于 2009-6-15 23:10:22 | 显示全部楼层
看看自己还有没不!!!
发表于 2009-6-15 23:11:35 | 显示全部楼层
_Example01 也要钱 太霸道了  太穷了
发表于 2009-6-29 02:45:00 | 显示全部楼层
很好,谢谢分享
发表于 2009-6-29 13:39:48 | 显示全部楼层
谢谢分享!
学习中。
发表于 2009-6-30 16:24:23 | 显示全部楼层
这个UDF好像有了吧?

评分

参与人数 1金钱 -10 收起 理由
zldfsz -10 感谢方便别人

查看全部评分

发表于 2009-7-3 17:12:18 | 显示全部楼层
非常感谢,正在到处找呢,呵呵
发表于 2009-7-3 22:47:20 | 显示全部楼层
不是一般的厉害啊!谢谢了!
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-3-19 19:51 , Processed in 0.083855 second(s), 23 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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