Jump to content
Fórum Script Brasil
  • 0

SAÍDA FORMATADA DE C++ PARA EXCEL


guipborges

Question

Hi everybody.

I have a simple problem. Need send the c++ output to excel(csv->xls or xls direct) in formated data. I can send the data to excel, but i can´t format that like this:

|_ col 1__|___col 2___|___col n____|

row 1......|....2row 1

row 2......|....2row 2

row 3......|... 2row n

What i can´t, is go to begin in col 2. My code put the data in this way.

|_ col 1__|___col 2___|___col n____|

row 1

row 2

row n

2row1

2row2

2rown

I don´t set this pointer to next columns.

If i put the data in the same "for", i can put the data in way i need. Else, i do not.

But, the column 2, have a leght biger then column 1, and I need 2 "for" to put the data.

Follow the code.

C++ Syntax (Toggle Plain Text)
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
#include <cstdlib>
#include <stdlib.h>

using namespace std;


class DATA
{
  public:
    int dados[5];
    int dados2[7];

};

int main()
{

   DATA c;

    for (int i = 0; i < 5; ++i)
    {
        c.dados[i]= i;
    }
   for (int i = 0; i < 7; ++i)
    {
        c.dados2[i]= i;
    }


    ofstream out;
    out.open("data.txt");

     out << "DADOS 1"<<",";

    for (int i = 0; i < 5; ++i)
    {
    out  << c.dados[i] <<",";
    }out<<"\n";

     out << "DADOS 2"<<",";

    for (int i = 0; i < 7; ++i)
    {
    out  <<  c.dados2[i] <<",";
    }out<<"\n";


    system("RELATORIO.xlsx"); //open excel and import a data.txt to format xls


    return EXIT_SUCCESS;
}

this code put the data in rows, like a

|__DATA_1_|__1__|___2__|___3___|__4____|___5____|___N_____|

|__DATA_2_|__1__|___2__|___3___|___4___|___5____|___N_____|

this is the way I found to get my data, but is not the way I want

Any help??

Link to comment
Share on other sites

0 answers to this question

Recommended Posts

There have been no answers to this question yet

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



  • Forum Statistics

    • Total Topics
      152.2k
    • Total Posts
      652k
×
×
  • Create New...