how to read data in text file, extract and display in tabular manner in excel doc?

Discussion in 'C++' started by maylee21@gmail.com, Jun 20, 2007.

  1. Guest

    hi, anyone can help me figure out how to read data from a text file
    like this:

    10980012907200228082002

    and extract the data according to this kind of format:

    Record type 1
    TY-RECORD PIC (1).
    ID-PARTICIPANT PIC (6).
    DT-START PIC (8).
    DT-END PIC (8).


    i would want the program to extract the data and display them like
    this:

    TY-RECORD ID-PARTICIPANT DT-START DT-END
    1 098001 29072002 28082002

    and to save them in an excel format. I have plenty of record types (0
    - 9) and need to display them in separate tables.

    does anyone has a source code for this? or at least somebody pls guide
    me to figure out ways to create the program.

    many thanks!
     
    , Jun 20, 2007
    #1
    1. Advertising

  2. Ian Collins Guest

    Re: how to read data in text file, extract and display in tabularmanner in excel doc?

    wrote:
    > hi, anyone can help me figure out how to read data from a text file
    > like this:
    >
    > 10980012907200228082002
    >
    > and extract the data according to this kind of format:
    >
    > Record type 1
    > TY-RECORD PIC (1).
    > ID-PARTICIPANT PIC (6).
    > DT-START PIC (8).
    > DT-END PIC (8).
    >
    >
    > i would want the program to extract the data and display them like
    > this:
    >
    > TY-RECORD ID-PARTICIPANT DT-START DT-END
    > 1 098001 29072002 28082002
    >
    > and to save them in an excel format. I have plenty of record types (0
    > - 9) and need to display them in separate tables.
    >

    The reading part is easy, but you'll have to ask in a windows group for
    this bit.

    --
    Ian Collins.
     
    Ian Collins, Jun 20, 2007
    #2
    1. Advertising

  3. Jim Langston Guest

    <> wrote in message
    news:...
    > hi, anyone can help me figure out how to read data from a text file
    > like this:
    >
    > 10980012907200228082002
    >
    > and extract the data according to this kind of format:
    >
    > Record type 1
    > TY-RECORD PIC (1).
    > ID-PARTICIPANT PIC (6).
    > DT-START PIC (8).
    > DT-END PIC (8).
    >
    >
    > i would want the program to extract the data and display them like
    > this:
    >
    > TY-RECORD ID-PARTICIPANT DT-START DT-END
    > 1 098001 29072002 28082002
    >
    > and to save them in an excel format. I have plenty of record types (0
    > - 9) and need to display them in separate tables.
    >
    > does anyone has a source code for this? or at least somebody pls guide
    > me to figure out ways to create the program.
    >
    > many thanks!


    Well, one thing you might want to consider doing is to save the data into a
    CSV (comma seperated variable) file and open that in excel. Then you won't
    have to worry about saving in excel format which can be a pain. But excel
    can open a CSV file. In which case you would want to save the data so it
    looks like this:

    1,098001,29072002,28082002

    You may also wish to put your header file first.
    TY-RECORD,ID-PARTICIPANT,DT-START,DT-END

    1,098001,29072002,28082002
     
    Jim Langston, Jun 20, 2007
    #3
  4. James Kanze Guest

    On Jun 20, 3:38 am, "" <> wrote:
    > hi, anyone can help me figure out how to read data from a text file
    > like this:


    > 10980012907200228082002


    > and extract the data according to this kind of format:


    > Record type 1
    > TY-RECORD PIC (1).
    > ID-PARTICIPANT PIC (6).
    > DT-START PIC (8).
    > DT-END PIC (8).


    > i would want the program to extract the data and display them like
    > this:


    > TY-RECORD ID-PARTICIPANT DT-START DT-END
    > 1 098001 29072002 28082002


    > and to save them in an excel format.


    Does the data have to be converted into numeric types, or is it
    sufficient to keep it as strings. If all you need is strings,
    just read the record into a string, then use string::substr() to
    extract the different fields. If you need to convert, you'll
    have to start like this as well, then use istringstream to
    convert the field to the target type. Because there are no
    separators, you cannot use istream to convert before having
    broken the data up into fields.

    To display, you can just output using <<, but for tabular
    output, something like boost::format might be easier to use,
    once you learn the arcane format syntax. (The ideal would be
    something like Basic's PRINT USING, but I don't know of anything
    similar in C++.)

    For Excel, the simplest would doubtlessly be a CSV format; just
    output each line as sequence of comma separated values (or
    semi-colon separated, if you are outside of the Anglo Saxon
    world).

    > I have plenty of record types (0
    > - 9) and need to display them in separate tables.


    In which case, it wouldn't be too hard to write a small program
    which parses the Cobol record declarations into a simple C++
    class, including a constructor which does the conversions.

    Note that any "USAGE IS COMPUTATIONAL" will be BCD, and if the
    Cobol is running on an IBM mainframe, the text may be EBCDIC.

    You may also want to recognize some naming conventions. (In the
    above, it looks like DT- might be dates, for example.)

    --
    James Kanze (GABI Software, from CAI) email:
    Conseils en informatique orientée objet/
    Beratung in objektorientierter Datenverarbeitung
    9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
     
    James Kanze, Jun 20, 2007
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Edward

    Dynamically sized tabular display

    Edward, Feb 4, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    399
    Wardeaux
    Feb 4, 2004
  2. tolaskram
    Replies:
    1
    Views:
    547
    sloan
    Jan 27, 2006
  3. Matt
    Replies:
    3
    Views:
    509
    Tor Iver Wilhelmsen
    Sep 17, 2004
  4. Replies:
    46
    Views:
    2,696
    Tim Rentsch
    Aug 7, 2010
  5. Replies:
    0
    Views:
    136
Loading...

Share This Page