版主,烦您忙中抽时间帮设计个打印模板,没这方面的编程经验。谢谢你了。
程序代码:
CLEAR ALL CLEAR Main() CLEAR ALL RETURN PROCEDURE Main() LOCAL lcFileName, loExcel, lnRow, lnCol, lnIndex, lcField, lnRecIndex LOCAL lnFile, laString[1], lnCounter, lcBuffer LOCAL lnMaxRows, lnMaxCols lnMaxRows = 5 lnMaxCols = 4 lcFileName = "工资条.txt" IF !FILE(lcFileName) MESSAGEBOX("文件" + lcFileName + "不存在!", 16, "") RETURN ENDIF lnFile = FOPEN(lcFileName) IF lnFile == -1 MESSAGEBOX("文件" + lcFileName + "打开失败!", 16, "") RETURN ENDIF lnIndex = 0 DO WHILE !FEOF(lnFile) lnIndex = lnIndex + 1 DIMENSION laString[lnIndex] laString[lnIndex] = ALLTRIM(FGETS(lnFile)) ENDDO FCLOSE(lnFile) IF !USED("工资") USE test_prn ALIAS 工资 IN 0 ENDIF lcFileName = Application.DefaultFilePath + "\工资条" IF FILE(lcFileName + ".xls") loFileName = lcFileName + ".xls" DELETE FILE (lcFileName) ELSE IF FILE(lcFileName + ".xlsx") lcFileName = lcFileName + ".xlsx" DELETE FILE (lcFileName) ENDIF ENDIF WAIT "正在启动 Microsoft Excel Application,请稍候……" WINDOW NOWAIT loExcel = CREATEOBJECT("Excel.Application") WAIT "正在生成工资条,请稍候……" WINDOW NOWAIT WITH loExcel .SheetsInNewWorkbook = 1 .Workbooks.Add .WorkSheets(1).Activate lnRecIndex = 0 SELECT 工资 SCAN ALL lnRecIndex = lnRecIndex + 1 lnRow = 1 + (lnRecIndex - 1) * lnMaxRows IF lnRecIndex > 1 .ActiveSheet.Rows(1 + (lnRecIndex - 1) * lnMaxRows).PageBreak = 1 ENDIF FOR lnIndex = 1 TO ALEN(laString, 1) lnCol = 2 lcBuffer = laString[lnIndex] DO WHILE !EMPTY(lcBuffer) lnPos = AT(",", lcBuffer, 1) IF lnPos > 0 lcField = LEFT(lcBuffer, lnPos - 1) lcBuffer = ALLTRIM(SUBSTR(lcBuffer, lnPos + 1)) .ActiveSheet.Rows(lnRow + lnIndex).HorizontalAlignment = 3 DO CASE CASE lcField == "月份" lcField = "日期" IF !EMPTY(EVALUATE(lcField)) .Cells(lnRow + lnIndex, lnCol).Value = lcField .Cells(lnRow + lnIndex, lnCol + 1).Value = TRANSFORM(MONTH(EVALUATE(lcField))) ENDIF CASE lcField == "车间" lcField = "部门" IF !EMPTY(EVALUATE(lcField)) .Cells(lnRow + lnIndex, lnCol).Value = lcField .Cells(lnRow + lnIndex, lnCol + 1).Value = TRANSFORM(EVALUATE(lcField)) ENDIF OTHERWISE IF !EMPTY(EVALUATE(lcField)) .Cells(lnRow + lnIndex, lnCol).Value = lcField .Cells(lnRow + lnIndex, lnCol + 1).Value = TRANSFORM(EVALUATE(lcField)) ENDIF ENDCASE lnCol = lnCol + 2 IF lnCol > 2 * lnMaxCols lnCol = 2 ENDIF ENDIF ENDDO NEXT ENDSCAN .ActiveWorkbook.SaveAs(lcFileName) .Quit ENDWITH RELEASE loExcel WAIT "工资条已生成" WINDOW ENDPROC
工资条.txt.zip
(150 Bytes)