2007年5月15日火曜日

如何判断Excel是否为空

public sub xlprintout()

dim xl as Excel.Application
dim wb as Excel.Workbook
dim ws as Excel.Worksheet

dim xBorder as Excel.Border
dim RRR as long
dim CCC as long
dim Flag as boolean

set xl = CreateObject("Excel.application")
xl.visible = true
set wb = xl.Workbooks.Open("C:\Test.xls")
set ws = sb.Activesheet

flag = false
if ws.shapes.count > 0 then flag = true

for CCC = 1 to ws.range("A1").specialcells(xllastcell).column
for RRR = 1 to ws.range("A1").specialcells(xllastcell).row

if ws.cells(RRR, CCC).formula <> "" then flag = true

if ws.cells(RRR, CCC). interior.colorindex <>"" then flag = true

for each xBorder in ws.cells(RRR, CCC).borders
if xborder.linestyle <> xlNone then flag = true
next xborder

if flag then exit for
next RRR
if flag the exit for
next CCC

if flag then
ws.printout
else
Msgbox "can't print out"
end if

wb.close flase
xl.quit
set ws = nothing
set wb = nothing
set xl = nothing

end sub

上面的程序是VB的,如果谁想要C++的版本,我可以贴出来