如何在Progress 4Gl中将数据从浏览器窗口小部件导出到CSV

时间:2014-04-09 06:15:47

标签: progress-4gl

是否有人尝试将数据直接从浏览器导出到CSV?我们将数据填充到具有复杂逻辑的浏览器。如果我可以直接从浏览器获取数据,那将会有所帮助。

谢谢, MSK

1 个答案:

答案 0 :(得分:0)

您指的是浏览小部件吗?浏览小部件可视化基础查询中的数据 - 查询结果集将是您要导出的内容。查询没有EXPORT方法,所以不幸的是你需要自己滚动。这样的事情(省略了许多细节):

function exportData returns logical ( input bh as handle ):

  define variable bf as handle    no-undo.                                      /* handle to the field                          */
  define variable f  as integer   no-undo.                                      /* field number                                 */
  define variable i  as integer   no-undo.                                      /* array index                                  */

  do f = 1 to bh:num-fields:                                                    /* for each field...                            */

    bf = bh:buffer-field( f ).                                                  /* get a pointer to the field                   */

    if f > 1 then put stream expFile unformatted field_sep.                     /* output field separator                       */

    if bf:extent = 0 then                                                       /* is it an array?                              */
      put stream expFile unformatted
        ( if bf:data-type = "character" then                                    /* character data needs to be quoted to */
          quoter( string( bf:buffer-value ))                                    /* handle (potential) embedded delimiters       */
         else                                                                   /* and quotes within quotes!                    */
          string( bf:buffer-value )                                             /* other data types should not be quoted        */
        )
      .
     else                                                                       /* array fields need special handling           */
      do i = 1 to bf:extent:                                                    /* each extent is exported individually         */
        if i > 1 then put stream expFile unformatted field_sep.                 /* and a field separator                        */
        put stream expFile unformatted
          ( if bf:data-type = "character" then                                  /* see above...                                 */
            quoter( string( bf:buffer-value( i )))
           else
            string( bf:buffer-value( i ))
          )
          field_sep
        .
      end.

  end.

  put stream expFile skip.                                                      /* don't forget the newline! ;-)                */

  return true.

end.


/* main block...
 */

/* skipping a few things like defining variables and setting up the query that you have, presumably, already done... */

output to "output.dat".
qh:get-first( no-lock ) no-error.                                           /* try to fetch the first record                */

do while ( qh:query-off-end = no ):                                         /* loop while there is data being fetched       */
  exportData( bh ).                                                         /* write it to the output file!                 */
  assign                                                                    /* track the number of records written...       */
    r = r + 1                                                               /* per table                                    */
  .
  qh:get-next( no-lock ) no-error.                                          /* fetch the next record                        */
end.