ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

DB2 to Excel spreadsheet

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • DB2 to Excel spreadsheet

    OK,

    I have read a number of articles and threads about taking a db2 database and converting it to Excel. This is very confusing to me. What is the best method for creating an Excel spreadsheet? I don't believe I have POI's installed on my system. Do I need Java on my System I5 to accomphlish this. What is the best method of doing this?

    Thanks,

    DAC


    P.S. I created this program from Code400 but am getting compiler errors with the called procedures. Do I need to install the POIs on my system to get this to work?
    PHP Code:
         H Option(*SrcStmt)
         
    FRPTAGSTMP IF   E             Disk
         D Count           S             10I 0 Inz
    (0)
         
    D C               S              5I 0 Inz(0)
         
    D IFSFile         S           1024    Inz('/spltopdf/RPTAGSTMP.xls')
          * 
    OBJECT Variables
          
    // String.
         
    D string          S               O   CLASS(*JAVA
         D                                     
    :'java.lang.String')
          * 
    // String with fileName.
         
    D filename        S               O   CLASS(*JAVA
         D                                     
    :'java.lang.String')
          * 
    // FileOutputStream.
         
    D outFile         S               O   CLASS(*JAVA
         D                                     
    :'java.io.FileOutputStream')
         
    D wb              S               O   CLASS(*JAVA
         D                                     
    :'org.apache.poi.hssf.usermodel-
         D                                     .HSSFWorkbook'
    )
          * 
    // Sheet.
         
    D s               S               O   CLASS(*JAVA
         D                                     
    :'org.apache.poi.hssf.usermodel-
         D                                     .HSSFSheet'
    )
          * 
    // Row.
         
    D row             S               O   CLASS(*JAVA
         D                                     
    :'org.apache.poi.hssf.usermodel-
         D                                     .HSSFRow'
    )
          * 
    // Cell.
         
    D cell            S               O   CLASS(*JAVA
         D                                     
    :'org.apache.poi.hssf.usermodel-
         D                                     .HSSFCell'
    )
          * 
    CONSTRUCTOR Methods.
         *************************************************
          * 
    // String CONSTRUCTOR
          
    // new String(byte b[])
         
    D createString    PR              O   EXTPROC(*JAVA
         D                                     
    :'java.lang.String'
         
    D                                     :*CONSTRUCTOR)
         
    D                                     CLASS(*JAVA
         D                                     
    :'java.lang.String')
         
    D parm                        1024
          
    // FileOutputStream CONSTRUCTOR
          
    // new FileOutputStream(String file)
         
    D createFile      PR              O   EXTPROC(*JAVA
         D                                     
    :'java.io.FileOutputStream'
         
    D                                     :*CONSTRUCTOR)
         
    D                                     CLASS(*JAVA
         D                                     
    :'java.io.FileOutputStream')
         
    D parm                            O   CLASS(*JAVA
         D                                     
    :'java.lang.String')
          * 
    // WorkBook CONSTRUCTOR
         
    D createWB        PR              O   EXTPROC(*JAVA
         D                                     
    :'org.apache.poi.hssf.usermodel-
         D                                     .HSSFWorkbook'
         
    D                                     :*CONSTRUCTOR)
         
    D                                     CLASS(*JAVA
         D                                     
    :'org.apache.poi.hssf.usermodel-
         D                                     .HSSFWorkbook'
    )
          * 
    METHODS
         
    ****************************************************************
          * 
    // java.lang.trim()
         
    D trimString      PR              O   EXTPROC(*JAVA
         D                                     
    :'java.lang.String'
         
    D                                     :'trim')
         
    D                                     CLASS(*JAVA
         D                                     
    :'java.lang.String')
          * 
    // WorkBook.createSheet()
         
    D createSheet     PR              O   EXTPROC(*JAVA
         D                                     
    :'org.apache.poi.hssf.usermodel-
         D                                     .HSSFWorkbook'
         
    D                                     :'createSheet')
         
    D                                     CLASS(*JAVA
         D                                     
    :'org.apache.poi.hssf.usermodel-
         D                                     .HSSFSheet'
    )
          * 
    // WorkBook.write(FileOutputStream out)
         
    D writeWB         PR                  EXTPROC(*JAVA
         D                                     
    :'org.apache.poi.hssf.usermodel-
         D                                     .HSSFWorkbook'
         
    D                                     :'write')
         
    D parm                            O   CLASS(*JAVA
         D                                     
    :'java.io.OutputStream')
          * 
    // Sheet.createRow()
         
    D createRow       PR              O   EXTPROC(*JAVA
         D                                     
    :'org.apache.poi.hssf.usermodel-
         D                                     .HSSFSheet'
         
    D                                     :'createRow')
         
    D                                     CLASS(*JAVA
         D                                     
    :'org.apache.poi.hssf.usermodel-
         D                                     .HSSFRow'
    )
         
    D parm                          10I 0 value
          
    // Row.createCell()
         
    D createCell      PR              O   EXTPROC(*JAVA
         D                                     
    :'org.apache.poi.hssf.usermodel-
         D                                     .HSSFRow'
         
    D                                     :'createCell')
         
    D                                     CLASS(*JAVA
         D                                     
    :'org.apache.poi.hssf.usermodel-
         D                                     .HSSFCell'
    )
         
    D parm                           5I 0 value
          
    // Cell.setCellType(int)
         
    D setCellType     PR                  EXTPROC(*JAVA
         D                                     
    :'org.apache.poi.hssf.usermodel-
         D                                     .HSSFCell'
         
    D                                     :'setCellType')
         
    D parm                          10I 0 value
          
    // Cell.setCellValue(String)
         
    D setCellValStr   PR                  EXTPROC(*JAVA
         D                                     
    :'org.apache.poi.hssf.usermodel-
         D                                     .HSSFCell'
         
    D                                     :'setCellValue')
         
    D parm                            O   CLASS(*JAVA
         D                                     
    :'java.lang.String')
          * 
    // Cell.setCellValue(double)
         
    D setCellValD     PR                  EXTPROC(*JAVA
         D                                     
    :'org.apache.poi.hssf.usermodel-
         D                                     .HSSFCell'
         
    D                                     :'setCellValue')
         
    D parm                           8F   value
         D valueAlf        S           1024
         D valueNUM        S              8F
         
    ***********************************************************************
          /
    Free
             Count 
    0;
             
    wb createWB();
             
    createSheet(wb);
             
    Read RPTAGSTMP;
                  
    Dow not %eof(RPTAGSTMP);
                      
    Exsr DBRec2Excel;
             
    Read RPTAGSTMP;
                  
    Enddo;
             
    IFSFile = %trim(IFSFile);
             
    filename createString(IFSFile);
             
    filename trimString(filename);
             
    outFile createFile(filename);
             
    writeWB(wb:outFile);
             *
    inlr = *on;
          /
    End-Free

          
    /Free
           Begsr DBRec2Excel
    ;
             
    row createRow(s:Count);
             
    0;

             
    cell createCell(row:c);
             
    setCellType(cell:0);
             
    valueNUM BALANCEO;
             
    setCellValD(cell:valueNUM);
             
    c+1;

             
    cell createCell(row:c);
             
    setCellType(cell:1);
             
    valueALF RMSDATEASG;
             
    string createString(valueALF);
             
    string trimString(String);
             
    setCellValStr(cell:string);
             
    c+1;

              
    Count  Count +1;
              
    Endsr;
          /
    End-Free 
    Last edited by jamief; November 22, 2006, 02:45 PM. Reason: format with [ php ]

  • #2
    Re: DB2 to Excel spreadsheet

    Yes you need to download the POI jars and place them in a directory in your IFS. You will also need to set your CLASSPATH to point to this jar.
    Predictions are usually difficult, especially about the future. ~Yogi Berra

    Vertical Software Systems
    VSS.biz

    Comment


    • #3
      Re: DB2 to Excel spreadsheet

      You can also use good old RPG to write to an XML file with .xls extention (with recent versions of Excel) or to HTML for Excel 97. both which can be opened in Excel.

      example: http://tinyurl.com/q7v9h

      Another option: If you just want to pull off a PF to an Excel file on a regular basis without too much formating , you might install Client Access on a PC server with a PC job scheduler and perform regular batch downloads from PC side.
      Last edited by itp; November 22, 2006, 08:17 PM.

      Comment


      • #4
        Re: DB2 to Excel spreadsheet

        As far as the "best" way - it all depends. Is this a one shot? Does it need to run in batch? How much formatting / summarizing needs to be done ? etc...

        In addition to those mentioned above, you can use Visual basic and query the DB2 database using SQL.

        For simple jobs, you can include a simple VB macro in an Excel sheet that populates the sheet from the DB2 database.

        Another option is CPYTOIMPF and create a CSV file that can opened in Excel.

        Comment


        • #5
          Re: DB2 to Excel spreadsheet

          IMHO, the best way to get data from the i5 database into an Excel spreadsheet is via VBA macro code that connects to the database using the iSeries Access for Windows OLE DB Provider.
          "Time passes, but sometimes it beats the <crap> out of you as it goes."

          Comment


          • #6
            Re: DB2 to Excel spreadsheet

            Give me a couple of days and I will post a simplified version of POI prototyping. We have been using this simplified version in my shop for the past three years and it is extremely simple.
            Predictions are usually difficult, especially about the future. ~Yogi Berra

            Vertical Software Systems
            VSS.biz

            Comment


            • #7
              Re: DB2 to Excel spreadsheet

              Please let me know when you post. I really don't understand POI.

              Thanks,

              DAC

              Comment


              • #8
                Re: DB2 to Excel spreadsheet

                Another way is to use the Excel add-in if you are using Client Access. I thought it was pretty neat anyway

                Here is a link to an article about it:

                http://www.itjungle.com/tfh/tfh020303-story04.html
                Goodbye

                Comment


                • #9
                  Re: DB2 to Excel spreadsheet

                  Hey ken ... nice to see you survived the Holiday
                  All my answers were extracted from the "Big Dummy's Guide to the As400"
                  and I take no responsibility for any of them.

                  www.code400.com

                  Comment

                  Working...
                  X