0

When I export my calculations via ofstream in C++ to an ODS (Apache OpenOffice) file, the numbers are correctly shown there, however I cannot make any calculations in that specific ODS file.

For example, when I try to add, say 0.9191 on A1, and 0.5757 on A2, the =SUM(A1:A2) returns zero.

I tried to solve this thru formatting cells, but none worked so far. Any suggestions? Thank you.

Edit: The portion of code that does the exporting job.

string datafolder; datafolder = "c:/Users/cousinvinnie/Desktop/Code Vault/ArmaTut3/" + Jvalue;
string graph_path = datafolder + "/Graphavgs.ods"; ofstream graphavgs; graphavgs.open(graph_path);

for(int ctr = 0; ctr<cycledata; ctr++){

    cyclepoints = (howmanyDC + 1) * (ctr + 1);
    graphavgs<<(ctr + 1)<<" ";
    calcguy = sum((wholedata.row(cyclepoints))) / nextgenpop;
        secondbiggiesavg(ctr) = -log(calcguy);
        graphavgs<<secondbiggiesavg(ctr)<<" ";
    calcguy = sum((thirdbiggest.row(cyclepoints))) / nextgenpop;
        thirdbiggiesavg(ctr)  = -log(calcguy);
        graphavgs<<thirdbiggiesavg(ctr)<<" ";
    calcguy = sum((matrixavgs.row(cyclepoints))) / nextgenpop;
        avgmatrixdata(ctr)    = -log(calcguy);
        graphavgs<<avgmatrixdata(ctr)<<" "<<endl;
}
graphavgs.close();

This code creates the Graphavgs.ods file. In that file I have

   1    0.111753    0.182331    0.358724
   2    0.147015    0.259202    0.48334
   3    0.195855    0.362397    0.648719
   4    0.25348     0.476696    0.839261
   5    0.314722    0.618828    1.0633
   6    0.420704    0.857286    1.37501
   7    0.536699    1.1179      1.69503
   8    0.76933     1.56382     2.13464
   9    0.90525     1.89921     2.42443
   10   1.15678     2.41533     2.82584

Now these numbers are not treated as numbers. When I try to work a function on them, like =SUM(A1:A2) the return is zero.

When I do =LN(A1), the return is #VALUE!

SOLVED: Find & Replace all dots with commas.

  • 1
    And how do you do the "export"? If you haven't done it yet, please [read about how to ask good questions](http://stackoverflow.com/help/how-to-ask), and learn how to create a [Minimal, Complete, and Verifiable Example](http://stackoverflow.com/help/mcve). – Some programmer dude Sep 15 '16 at 10:37
  • Ok, let me add an example. – Bora Atalay Sep 15 '16 at 10:38
  • What you write is not really an ODS file but a [CSV file](https://en.wikipedia.org/wiki/Comma-separated_values) with the separator being a single space. I don't know if you can open it properly in Excel, or if you have to import it. – Some programmer dude Sep 15 '16 at 10:50
  • I don't have Excel, so I use Apache OpenOffice. I tried to save the file as .csv as well. Do I really have to use MS Excel to do the job? Formatting cells didn't help either. – Bora Atalay Sep 15 '16 at 10:53
  • 1
    No you can use OpenOffice (or LibreOffice or any other tool that can read CSV files). But if you dont use Excel, why did you add that tag? Anyway, the problem (I think) is that you attempt to load it as an ODS file, which it isn't. All the OpenDocument formats are XML-based. This seems to be more of a problem with you not using the correct way to load or import the document, so less of a programing problem and more of a usage problem, and therefore off-topic here on Stack Overflow. – Some programmer dude Sep 15 '16 at 10:55
  • Thank you for your time, and I understand the elaboration to keep the community as productive and tidy as possible. I realized that C++ writes the file with DOTS in between, as 0.1878. I have just changed the dot to comma, as in 0,1878, and it worked. Now I need to find how to save my data with commas, and not dots. Lastly, I used Excel tag because I thought it is a Cell Format question, and maybe someone with Excel experience would help me out. – Bora Atalay Sep 15 '16 at 11:04
  • Workaround answer: Find & Replace all dots with commas. – Bora Atalay Sep 15 '16 at 11:15
  • Ah yes of course. However this is very language-dependent (not programming language, "real" language). If the office suite should use comma or dot depends on the users locale and nationality settings. Sending your file with commas to someone in the US, for example, will cause problems for the recipient. For it to work on *your* system you need to make sure the locale settings are correct, and you might have to set the correct locale on the file stream as well. How to do that is subject for another question though. – Some programmer dude Sep 15 '16 at 11:23

1 Answers1

0

You are making a confusion between the CSV file format, the ODS file format and the representation of both in OpenOffice or LibreOffice.

What you build is a CSV file, that means purely text file that only contains a textual representation of values. By default, your C++ program generates floating values with a dot as a decimal separator.

An ODS file is in fact a ZIP file containing meta-data (name of creator, date of creation, date of last print, etc.), actual data and formatting informations. That way an ODS file is directly opened by LibreOffice or OpenOffice.

What you open a CSV file in LibreOffice or OpenOffice, you actually import it. That means that the program makes some assumptions on the data separator, the decimal separator and if appropriate on the date format to translate the textual values into numeric (or date) ones. Those assumptions are based on your system locale. The formatting in normally the default one. Depending on the version you use, a dialog box with import option may be displayed always or only if you explicitely import the file (menu File/Import). That dialog box allows you to specify the separators and decimal separators that the CSV file contains.

Once you have correctly loaded a CSV file, it is recommended to save it in ODS format to make sure that you will no longer have that import problem again.

Serge Ballesta
  • 143,923
  • 11
  • 122
  • 252
  • Thanks for your response. I did the quick workaround by changing all dots with commas. Then changing the language settings to English completely eliminated the problem. – Bora Atalay Sep 15 '16 at 12:43