Is it possible from a console application in dev c ++ to create an excel file and enter data?

1

It is possible that in a console application from dev c ++ you can create an excel file with data entered from there, and if possible how it could be done? I understand that you can create txt files and enter data from c ++, which I have already done and I will share the code of this, but from c ++ create an excel file and enter the data from there is possible?

I attach my code to create a txt file and enter data from c ++

#include<iostream>
#include<stdlib.h>
#include<fstream>
using namespace std;

void escribirFrases();

int main(){
escribirFrases();

system("pause");
return 0;
} 

void escribirFrases(){
ofstream archivo;
string nombreArchivo,frase;
char rpt;

cout<<"Digite el nombre del archivo: ";
getline(cin,nombreArchivo);

archivo.open(nombreArchivo.c_str(),ios::out); //Creamos el archivo

if(archivo.fail()){ //Si a ocurrido algun error
    cout<<"No se pudo abrir el archivo";
    exit(1);
}

do{
    fflush(stdin);
    cout<<"Digite una frase: ";
    getline(cin,frase);
    archivo<<frase<<endl;

    cout<<"\nDesea agregar otra frase(S/N): ";
    cin>>rpt;
}while((rpt == 'S') || (rpt == 's'));

archivo.close(); //Cerramos el archivo
}  
    
asked by Kevin Burbano 19.01.2018 в 21:38
source

1 answer

1
  

Is it possible that in a console application from dev c ++ you can create an excel file with data entered from there ?, and if possible, how could it be done?

It will depend on the version of Excel for which you want to make the file, but it can be: it can be done. Just keep in mind that you should write in the format Excel expects; Microsoft has a page dedicated to explain that format (my translation):

  

Understanding the Binary Excel File Format .xls

     

The Specification of Binary File Format Structure [MS- XLS] (.xls) is used by Microsoft Office Excel 2003, Microsoft Excel 2002, Microsoft Escel 2000, and Microsoft Excel 97. The format is organized into sets and subsets. Each tab of the spreadsheet is saved in its subset. All data is contained in records that have headers, which determine the type of the record and its length. The cell records, which contain both the cell itself and the formulas and cell properties, reside in the table of cells. Character string values are not stored in the cell record, but in a table of shared character strings, which are referenced by cell records. Row records have property information for a row and cell locations. Only cells that contain data or individual format are stored in the subset.

In the link to the specification you have all the details of the format. As for how to use it from C ++, you will have to use (as you already use in your example) std::ofstream but configured in binary mode (not text) and follow the specification for what you need.

    
answered by 20.01.2018 в 13:20