January 27, 2012

KillGabio KillGabio
Ant Farmer
41 posts

CSV format!

 

Hi developers..
i have the following code

  1. void ExportData::on_exportar_clicked()
  2. {
  3.     if (this->ui->table_agregados->rowCount () != 0){
  4.         this->habilitar_botones (false);
  5.         Dialogcheckeo * get_file_path = new Dialogcheckeo (this, 3);
  6.         connect (get_file_path, SIGNAL(enviar_texto(QString)), this, SLOT (recibir_texto (QString)));
  7.         get_file_path->exec ();
  8.         QFile remito (QDir::homePath ()+"/Escritorio/"+filename+".csv");
  9.         int progress= 0;
  10.         double avance = 100/ this->ui->table_agregados->rowCount ();
  11.         if (remito.open (QFile::WriteOnly | QFile::Truncate)){
  12.             QTextStream data( &remito );
  13.             QStringList strList;
  14.             for (int row = 0; row < this->ui->table_agregados->rowCount (); row++){
  15.                 for (int col = 0; col < this->ui->table_agregados->columnCount (); col++){
  16.                     strList << this->ui->table_agregados->item (row, col)->text ();
  17.                 }
  18.                 data << strList.join (",")+"\n";
  19.                 strList.clear ();
  20.                 progress+= avance;
  21.                 this->ui->progressBar->setValue (progress);
  22.             }
  23.         }else remito.errorString ();
  24.         this->ui->progressBar->setValue (100);
  25.         remito.close ();
  26.         this->habilitar_botones(true);
  27.     }
  28. }

i can open this file with Excel and Open but what i want is to set the columns name and width (maybe change the font also if its possible lol) how can i accomplish that with Qt? how should i store that information?

I`ve seen something like this:

Col1, col 2, col 3
data1, data2, data3
data4, data5, data6

but this doesnt work, cols are inserted as cell`s not as column names :(

i just need to know the format of csv so that i can play with that, not just simple values separated by a comma

hope anyone can help me…thanks a lot!

3 replies

January 27, 2012

GentooXativa GentooXativa
Ant Farmer
67 posts

The CSV standard is only with separators (, or ;) you cant define a style inside.

http://en.wikipedia.org/wiki/Comma-separated_values

 Signature 

Jose Vicente Giner Sanchez - Senior Mobile Developer

www.gigigo.com

C/ Dr. Zamenhof 36bis, 1ºA 28027 Madrid
T: +34 917431436

January 27, 2012

Andre Andre
Mad Scientist
4034 posts

If you are looking for a more complex format for spreadsheets, take a look at the ODS format (open document standard for spreadsheet). It is a zipped XML format. Qt does not have a build-in way to generate them using high-level primitives, but you should be able to create it using XML and then zipping that XML.

 Signature 

Nokia Certified Qt Specialist.
Interested in Qt consultancy and job opportunities.

January 27, 2012

KillGabio KillGabio
Ant Farmer
41 posts

will do, thanks both of you guys!

Greetings!

 
  ‹‹ How to insert many items into QListView without making the app freeze?      Restrict QGraphicsLineItem movement ››

You must log in to post a reply. Not a member yet? Register here!