Style Format

Scott Klement's open source interface to the POI HSSF/XSSF Spreadsheet Project for RPG Programmers. http://www.scottklement.com/poi/
Scott Klement
Site Admin
Posts: 257
Joined: Sun Jul 04, 2021 5:12 am

Re: Style Format

Post by Scott Klement »

Thank you for posting the code like that, it made this much easier to work with! I really appreciate it!

I debugged the program and I noticed that you are setting all of the cells with ss_text, which tells Excel that the data is text data. Therefore, it is not applying any number or date formats to it.

I was able to solve the problem on my system by rewriting your "setColumn" subprocedure as follows:

Code: Select all

     P*****************************************************************
     P*
     P* setColumn: Set data into cells for each row in a worksheet
     P*   for a workbook based on the passed in parameters.
     P*
     P*****************************************************************
     P*
     P*  Incoming:
     P*    Incolumn       Column Number   (10I:0)
     P*    Instring       String Data     (1024A)
     P*    Instyle        String Style    (10A)
     P*
     P*  Outgoing:
     P*    None
     P*
     P*  Returns:
     P*    None
     P*
     P*****************************************************************
     P setColumn       B                   Export

     D setColumn       PI
     D   Incolumn                    10I 0 Const
     D   Instring                  1024A   Const Varying
     D   Instyle                     10A   Const

     D style           S                   Like(SSCellStyle)

      /Free

        Select;
        When Instyle = 'Text';
          ss_text( row: Incolumn: %Trim(Instring): Text);
        When Instyle = 'Dates';
          ss_date( row: Incolumn: %date(Instring): Dates);
        When Instyle = 'Numeric';
          ss_num( row: Incolumn: %float(Instring): Numeric);
        EndSl;


      /End-Free

     P                 E
wdwisser
Posts: 14
Joined: Tue Feb 15, 2022 5:12 pm

Re: Style Format

Post by wdwisser »

Scott,
Thanks for looking into this. I would think the "style" that I assigned from the global variables would have overwritten the type of data coming in but I guess that is not the case. Interesting. I also noticed that I had a typo on the setHeadings procedure within the service program. I will update the listing on the current post.

Bill
Scott Klement
Site Admin
Posts: 257
Joined: Sun Jul 04, 2021 5:12 am

Re: Style Format

Post by Scott Klement »

wdwisser wrote: Tue May 03, 2022 8:42 pm I would think the "style" that I assigned from the global variables would have overwritten the type of data coming in but I guess that is not the case.
No, that's not the case. Many cell styles apply to any type of cell (for example, font, bold, underline, color can apply to anything.) So there's no way to determine the type of data from the style of the cell. There are a few cell styles (such as number format) That are specific to a particular data type. If you try to assign them to a cell that's a different type, it'll simply ignore that aspect of the cell style.
Post Reply