How to store strings read from excel cells?

Hi,
i can read and store numbers read from excell cells in 2-dimension matrix but
how can i store strings which i can read?

The concept is: user changes the content of the cells and the program changes the output of the calculations.
For example the location of the unit, from "north" to 'south" (or the output power).
And i want that data saved in order to be used afterwards by the following code.


Part of the code is:

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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
int ia=0;
	int ib=0;
	int ic=0;
	double a[40][2];
	char chr[40];
		
	BasicExcel xls;
	
	if(xls.Load("DAS_input_output_file_v1.0.xls"))
	{
		BasicExcelWorksheet *sheet1=xls.GetWorksheet("ThermalUnitsData");	
	
		double *cellTUD ;
	    cellTUD = (double*)malloc(80*sizeof(double));
		
		if(sheet1)
		{
			for (ib=0 ; ib<2 ; ib++)
			{
				for (ia=0 ; ia<40 ; ia++)
				{
					cellTUD[ia] = sheet1->Cell((ia+1),(ib+4))->GetDouble();
					a[ia][ib] = cellTUD[ia];
					cout << a[ia][ib] << " ";
					
				}	
				cout << endl << "next column";

			}

			cout << endl << "****String****" << endl;

			const char *cellTUDstr;
			for (ia=0 ; ia<40 ; ia++)
			{
				cellTUDstr = sheet1->Cell((ia+1),3)->GetString();
				chr[ia] = cellTUDstr[ia];
				//cout << chr[ia] << " ";
				
				cout << cellTUDstr << " ";
				//cellstr++;
			}
			cout << "Test" << chr[0];
		}
		else 
		{
			cout << "Error loading sheet.";
		}
				
		xls.Save();

		cout << endl << endl << "Data loaded succesfully." << endl <<endl << endl; 

		
		
		
	}
Last edited on
BasicExcel xls;

May I know which library you are using that has a BasicExcel class provided?
anyone?
closed account (DSLq5Di1)
Well, if using c-strings isn't a necessity, just assign the return value to a std::string and Bob's your uncle,

1
2
3
4
5
6
7
#include <string>
std::string chr[40];
...
			for (ia=0 ; ia<40 ; ia++)
			{
				chr[ia] = sheet1->Cell((ia+1),3)->GetString();
			}

Else, you'll need to manage allocating/freeing the memory yourself with strcpy() or strdup().
Thank you very very much!!!
Anything you need tell me!
Topic archived. No new replies allowed.