调了个别还有空行出现。看了你昨天的提醒,我现在想用你第一次给设计的按行生成个性工资单,我修改了一下,按列生成。但有个问题,excel2000只有256列,而工资人数最少300人,这样一张工作表就生成不了,出现错误,现在想程序能不能判断超出256列,就生成到第二张工作表,或者用“转置”的方法。老师有什么更好的办法?
CLEAR ALL
CLEAR
Main()
CLEAR ALL
RETURN
PROCEDURE Main()
LOCAL loFileName, loExcel, lnRow, lnCol, lnIndex, lcField
IF !USED("工资")
USE prn_gz ALIAS 工资 IN 0
ENDIF
loFileName = Application.DefaultFilePath + "\工资清单\工资单s"
IF FILE(loFileName + ".xls")
loFileName = loFileName + ".xls"
DELETE FILE (loFileName)
ELSE
IF FILE(loFileName + ".xlsx")
loFileName = loFileName + ".xlsx"
DELETE FILE (loFileName)
ENDIF
ENDIF
? "正在启动 Microsoft Excel Application,请稍候……"
loExcel = CREATEOBJECT("Excel.Application")
? "正在生成工资条,请稍候……"
WITH loExcel
.SheetsInNewWorkbook = 1
.Workbooks.Add
.WorkSheets(1).Activate
lnRow = 0
lnCol = -2
SELECT 工资
SCAN ALL
lnRow = 1
lnCol = lnCol+3
FOR lnIndex = 1 TO FCOUNT()
&& 循环次数等于字段的数目
lcField = FIELD(lnIndex)
IF !EMPTY(EVALUATE(lcField))
.ActiveSheet.Columns(lnCol).HorizontalAlignment = 2
&&水平靠左对齐
.ActiveSheet.Columns(lnCol).VerticalAlignment =2
&&垂直居中对齐
.Cells(lnRow, lnCol).Value = lcField
.Cells(lnRow , lnCol+1).Value = TRANSFORM(EVALUATE(lcField))
lnRow =lnRow +1
ENDIF
NEXT
ENDSCAN
.ActiveSheet.Range("A:IV").Font.Name="宋体"
.ActiveSheet.Range("A:IV").Font.Size=10
.ActiveSheet.COLUMNS("A:IV").ENTIRECOLUMN.AUTOFIT
.ActiveWorkbook.SaveAs(loFileName)
.Quit
ENDWITH
RELEASE loExcel
? "工资清单已生成"
ENDPROC