Editing a .xlsx file (via converting to .csv)

Hi,

I am wondering if it might be appropriate to edit a .xlsx file using C++. I currently have two worksheets that I would like to combine using an ID column. In the first worksheet there I have information ordered by date where there are roughy 250 entries on each day from different weather stations. Each weather station has an ID with information that is given in the second worksheet.

Thanks in advance!
Last edited on

Ok. So I have no converted my .xlsx into 2 .csv files (with , delimiters), one for each worksheet.

I am now looking at ways of reading these in and then using the first column to match up the ID's in the different files and output a new file that is a combination of the two.

My first step I think is to read in the first .csv file and I am currently looking at doing it like this

1
2
3
4
5
6
7
8
9
#include <iostream>
#include <fstream>
using namespace std;

int main()
{
    ofstream myfile;
    myfile.open("/Users/MyName/Desktop/Weather_test.csv")
    return 0;


but am now getting a bit stuck.

Btw my data from the first worksheet that I want to read in is in this format

30020,01/01/2005,5.3,7.1,3.1,992.2,89,3.05,14.8,29.4,46.5,0,0,0,0,0
30030,01/01/2005,6.6,8,5,0,87,0,10.8,31.1,38.9,0,0,0,0,0
30050,01/01/2005,5.1,6.6,0,992.6,83,10.16,24.1,38.7,53.5,87,0,0,0,0
30064,01/01/2005,0,0,0,0,0,0,0,0,0,0,0,0,0,0
30080,01/01/2005,6.2,7.6,4.9,993.2,79,5.08,23.3,40.6,50,0,0,0,0,0
30100,01/01/2005,6.2,7.9,3.3,994.3,85,0,0,39.1,61.1,0,0,0,0,0
30110,01/01/2005,5.8,7.5,2.5,993.7,79,0,0,55.7,94.3,0,0,0,0,0
30170,01/01/2005,0,0,0,0,0,0,0,0,0,0,0,0,0,0

Last edited on

I have now edited my code to this (and added an error if the file does not open).

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include <iostream>
#include <fstream>
using namespace std;

string Weather_ID;
string Date;
double Temperature;
double Maximum_Temperature;
double Minimum_Temperature;
double Sea_Level_Pressure;
double Humidity;
double PP;
double Vertical_Visibility;
double V;
double VM;
double VG;
double Rain;
double Snow;
double Thunder_Storm;
double Fog;

int main()
{
    ifstream Weather_test;
    Weather_test.open("/Users/MyName/Desktop/Weather_test.csv");
    
    if(!Weather_test)
    {
        cout << "The file did not open correctly";
    }
    
    return 0;
}
Last edited on
I currently have two worksheets that I would like to combine using an ID column.
What do the two CSV files look like?
So the first worksheet gives the .csv file with the data above, like this

30020,01/01/2005,5.3,7.1,3.1,992.2,89,3.05,14.8,29.4,46.5,0,0,0,0,0
30030,01/01/2005,6.6,8,5,0,87,0,10.8,31.1,38.9,0,0,0,0,0
30050,01/01/2005,5.1,6.6,0,992.6,83,10.16,24.1,38.7,53.5,87,0,0,0,0
30064,01/01/2005,0,0,0,0,0,0,0,0,0,0,0,0,0,0
30080,01/01/2005,6.2,7.6,4.9,993.2,79,5.08,23.3,40.6,50,0,0,0,0,0
30100,01/01/2005,6.2,7.9,3.3,994.3,85,0,0,39.1,61.1,0,0,0,0,0
30110,01/01/2005,5.8,7.5,2.5,993.7,79,0,0,55.7,94.3,0,0,0,0,0
30170,01/01/2005,0,0,0,0,0,0,0,0,0,0,0,0,0,0


And the second one looks like this

30020,BALTASOUND NO.2,/en/Climate/BALTASOUND_NO_2/30020.htm,60.75,-0.85,15,Scotland
30030,Sumburgh Cape,/en/Climate/Sumburgh_Cape/30030.htm,59.88,-1.3,5,Scotland
30050,LERWICK,/en/Climate/LERWICK/30050.htm,60.13,-1.18,84,Scotland
30064,Scatsa / Shetland Island,/en/Climate/Scatsa_Shetland_Island/30064.htm,60.43,-1.3,22,Scotland
30080,FAIR ISLE,/en/Climate/FAIR_ISLE/30080.htm,59.53,-1.63,57,Scotland
30100,SULE SKERRY,/en/Climate/SULE_SKERRY/30100.htm,59.08,-4.4,12,Scotland
30110,NORTH RONA,/en/Climate/NORTH_RONA/30110.htm,59.11,-5.81,103,Scotland
30140,FOULA,/en/Climate/FOULA/30140.htm,60.11,-2.06,13,Scotland


As you can see, the first columns are both an ID. What I would like to do is to combine these into one file using the second worksheet as a reference
I know this is cplusplus.com, but IMO a higher-level language would be much easier/faster to implement this in. But no matter what language you go with, I'd google libraries that edit "Office Open XML" documents so you don't even have to convert to a CSV sheet. I know there are some good libraries for Python, and I'd bet there are incredible libraries for C as well. Just a different view here.
Topic archived. No new replies allowed.