EXCEL数据导入TIPTOP ERP 系统

测试系统TIPTOP GP 3.0

主要用到DDE API

函数描述
DDEConnectThis function opens a DDE connection
DDEExecuteThis function executes a command in the specified program
DDEFinishThis function closes a DDE connection
DDEFinishAllThis function closes all DDE connections, as well as the DDE server program
DDEErrorThis function returns DDE error information about the last DDE operation
DDEPeekThis function retrieves data from the specified program and document using the DDE channel
DDEPokeThis function sends data to the specified program and document using the DDE channel

首先看EXCEL文档内容如下图:

4gl程序如下图:

4gl程序代码如下:

[html]  view plain copy print ?
  1. ###20120406 BY FMX------LOAD FROM EXCEL-----------            
  2. FUNCTION load_from_excel()      
  3.  DEFINE program  VARCHAR(128),   #Name of the DDE server program  
  4.         document VARCHAR(128),   #Name of the DDE document  
  5.         ls_file_path string,   
  6.         row      SMALLINT,  
  7.         cel      SMALLINT,  
  8.         row_cel  STRING,  
  9.         l_msg    VARCHAR(100),  
  10.         l_len    SMALLINT,  
  11.         l_n      SMALLINT,  
  12.         l_excelseq SMALLINT,  
  13.         Returns  SMALLINT,  
  14.         l_ac     SMALLINT,   
  15.         l_sl     SMALLINT     
  16.  DEFINE l_tc_sfb RECORD LIKE tc_sfb_file.*      
  17.  DEFINE cmd VARCHAR(500)  
  18.  DEFINE res SMALLINT  
  19.  DEFINE val STRING  
  20.  DEFINE ret SMALLINT  
  21.  DEFINE var STRING  
  22.  DEFINE var2    VARCHAR(40)  
  23.  DEFINE l_flag  VARCHAR(100)  #判断必要栏位是否有输入  #No.FUN-690028 CHAR(1)  
  24.  DEFINE l_sql   STRING  
  25.    
  26.  LET l_ac=1  
  27.  LET l_sl=1  
  28.  LET program="EXCEL"  
  29.     
  30.   #开窗选择档案  
  31.    OPEN WINDOW csfi002_load_w WITH FORM "csf/42f/csfi002_load"   
  32.    CALL cl_ui_locale("csfi002_load")  
  33.      
  34.    INPUT ls_file_path WITHOUT DEFAULTS  FROM FORMONLY.doc_path                
  35.       ON ACTION open_file  
  36.          CALL cl_browse_file() RETURNING ls_file_path  
  37.          DISPLAY ls_file_path TO FORMONLY.doc_path  
  38.       ON ACTION exit  
  39.          EXIT INPUT  
  40.    END INPUT  
  41.      
  42.    IF INT_FLAG THEN  
  43.       LET INT_FLAG = FALSE  
  44.       CLOSE WINDOW csfi002_load_w  
  45.       RETURN  
  46.    END IF  
  47.   
  48. ###判断路径是否为空  
  49.    IF ls_file_path IS NULL  THEN  
  50.       CLOSE WINDOW csfi002_load_w  
  51.       RETURN  
  52.    ELSE  
  53.       LET document = ls_file_path  
  54.       DISPLAY 'ls_file_path = ',document  
  55.    END IF  
  56.   
  57.       LET l_len = LENGTH(document)  
  58.       IF l_len<=4 THEN  
  59.           LET documentdocument CLIPPED,'.xls'  
  60.         ELSE  
  61.           IF DOWNSHIFT(document[l_len-3,l_len])!='.xls' THEN  
  62.              LET documentdocument CLIPPED,'.xls'  
  63.           END IF  
  64.        END IF  
  65.          
  66.     CALL ui.Interface.frontCall("WINDDE","DDEConnect",[ program, document ], Returns )   
  67.     LET row=2   ###从第二行开始  
  68.     WHILE TRUE  
  69.             INITIALIZE l_tc_sfb.* TO NULL   
  70.          #读取工单单号 [tc_sfb01]  
  71.             LET cel=1    ##第一列  
  72.              LET row_cel='R',(row USING '<<<<<'),'C',(cel USING '<<<<<')  
  73.              CALL ui.Interface.frontCall("WINDDE","DDEPeek", [program,document,row_cel], [Returns,val])  
  74.               LET var2=val CLIPPED  
  75.             IF (var2 IS NULL OR var2=' ') THEN  
  76.                  ERROR '单号不可为空'  
  77.                EXIT WHILE  
  78.             END IF  
  79.             LET l_tc_sfb.tc_sfb01 = var2  
  80.   
  81.          #读取投产期 [tc_sfb022]  
  82.             LET cel=2   ##第二列  
  83.             LET row_cel='R',(row USING '<<<<<'),'C',(cel USING '<<<<<')  
  84.              CALL ui.Interface.frontCall("WINDDE","DDEPeek", [program,document,row_cel], [Returns,val])  
  85.              LET var2=val CLIPPED  
  86.             IF (var2 IS NULL OR var2=' ') THEN  
  87.                 ERROR '投产期不可为空'  
  88.                EXIT WHILE  
  89.             END IF  
  90.             LET l_tc_sfb.tc_sfb022 = var2  
  91.               
  92.          #读取完成期 [tc_sfb023]  
  93.             LET cel=3   ##第3列  
  94.             LET row_cel='R',(row USING '<<<<<'),'C',(cel USING '<<<<<')  
  95.              CALL ui.Interface.frontCall("WINDDE","DDEPeek", [program,document,row_cel], [Returns,val])  
  96.              LET var2=val CLIPPED  
  97.             IF (var2 IS NULL OR var2=' ') THEN  
  98.                 ERROR '完成期不可为空'  
  99.                EXIT WHILE  
  100.             END IF  
  101.             LET l_tc_sfb.tc_sfb023 = var2  
  102.               
  103.          #读取机台生产线 [tc_sfb03]  
  104.             LET cel=4   ##第4列  
  105.             LET row_cel='R',(row USING '<<<<<'),'C',(cel USING '<<<<<')  
  106.              CALL ui.Interface.frontCall("WINDDE","DDEPeek", [program,document,row_cel], [Returns,val])  
  107.              LET var2=val CLIPPED  
  108. #            IF (var2 IS NULL OR var2=' ') THEN  
  109. #               ERROR '机台生产线不可为空'  
  110. #               EXIT WHILE  
  111. #            END IF  
  112.             LET l_tc_sfb.tc_sfb03 = var2   
  113.   
  114.          #读取是否排班 [tc_sfb05]  
  115.             LET cel=5   ##第5列  
  116.             LET row_cel='R',(row USING '<<<<<'),'C',(cel USING '<<<<<')  
  117.             CALL ui.Interface.frontCall("WINDDE","DDEPeek", [program,document,row_cel], [Returns,val])  
  118.             LET var2=val CLIPPED  
  119.             LET l_tc_sfb.tc_sfb05 = var2  
  120.                
  121.          #读取白班 [tc_sfb07]  
  122.             LET cel=6  ##第6列  
  123.             LET row_cel='R',(row USING '<<<<<'),'C',(cel USING '<<<<<')  
  124.             CALL ui.Interface.frontCall("WINDDE","DDEPeek", [program,document,row_cel], [Returns,val])  
  125.             LET var2=val CLIPPED  
  126.             LET l_tc_sfb.tc_sfb07 = var2   
  127.               
  128.          #读取夜班  [tc_sfb08]  
  129.             LET cel=7   ##第7列  
  130.             LET row_cel='R',(row USING '<<<<<'),'C',(cel USING '<<<<<')  
  131.             CALL ui.Interface.frontCall("WINDDE","DDEPeek", [program,document,row_cel], [Returns,val])  
  132.             LET var2=val CLIPPED  
  133.             LET l_tc_sfb.tc_sfb08 = var2     
  134.                                     
  135.  LET row=row+1   
  136.     SELECT COUNT(*) into l_n FROM tc_sfb_file   
  137.     WHERE tc_sfb01 =l_tc_sfb.tc_sfb01   
  138. #   AND tc_sfb022 IS NULL   
  139. #   AND tc_sfb023 IS NULL  
  140.     IF l_n>0 THEN  
  141.         UPDATE tc_sfb_file SET tc_sfb022=l_tc_sfb.tc_sfb022,  
  142.                                tc_sfb023=l_tc_sfb.tc_sfb023,  
  143.                                tc_sfb03=l_tc_sfb.tc_sfb03,  
  144.                                tc_sfb05=l_tc_sfb.tc_sfb05,  
  145.                                tc_sfb07=l_tc_sfb.tc_sfb07,  
  146.                                tc_sfb08=l_tc_sfb.tc_sfb08   
  147.                          WHERE tc_sfb01=l_tc_sfb.tc_sfb01                          
  148.       IF STATUS OR SQLCA.SQLERRD[3] = 0 THEN  
  149.          CALL cl_err3("upd","tc_sfb_file",l_tc_sfb.tc_sfb01,"",STATUS,"","upd tc_sfb01",1) #TQC-660045  
  150.          LET g_success = 'N' RETURN  
  151.       END IF  
  152.   ###将导入的开工日和完工日更新到工单上------  
  153.       UPDATE sfb_file SET sfb13 = l_tc_sfb.tc_sfb022,  
  154.                           sfb15 = l_tc_sfb.tc_sfb023  
  155.                    WHERE  sfb01 = l_tc_sfb.tc_sfb01  
  156.      IF STATUS OR SQLCA.SQLERRD[3] = 0 THEN  
  157.         CALL cl_err3("upd","sfb_file",l_tc_sfb.tc_sfb01,"",STATUS,"","upd sfb01",1) #TQC-660045  
  158.         LET g_success = 'N' RETURN  
  159.      END IF                 
  160.    END IF                    
  161.   ###END------------------------  
  162.             CONTINUE WHILE  
  163.             IF row>20000 THEN  
  164.                ERROR '只能显示20000行!现只产生前20000行资料!'  
  165.                EXIT WHILE  
  166.             END IF  
  167.             LET l_ac=l_ac+1  
  168.             LET l_sl=l_sl+1  
  169.     END WHILE  
  170.   
  171. --   CALL DDEFinishAll()  
  172.      CALL cl_end2(1) RETURNING l_flag   
  173.        
  174.      CALL i002_b_fill('1=1')                 #单身  
  175.      CLOSE WINDOW csfi002_load_w    
  176.                                   
  177. END FUNCTION  
  178. ###END*******************************************   
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值