Click here to Skip to main content
15,893,588 members
Please Sign up or sign in to vote.
4.50/5 (2 votes)
See more:
I am writing a program using BasicExcel...I need to access data from an excel file and store it as a variable.

I've been trying to store the data with the following:

char str = cell->GetString();

This returns error C2440: 'initializing' : cannot convert from 'const char *' to 'char'

Here is the BasicExpress code...where do I add an additional function?:
C++
static void example_read_write(char* from, char* to)
{
	cout << "read " << from << endl;
	BasicExcel xls(from);
	XLSFormatManager fmt_mgr(xls);
	BasicExcelWorksheet* sheet = xls.GetWorksheet((size_t)0);
	CellFormat fmt_general(fmt_mgr);
	fmt_general.set_format_string(XLS_FORMAT_GENERAL);
	
	for(int y=0; y<33; ++y) {
		for(int x=1; x<2; ++x) 
		{
			cout << y << "/" << x;		
			BasicExcelCell* cell = sheet->Cell(y, x);        
			CellFormat fmt(fmt_mgr, cell);			
//			cout << " - xf_idx=" << cell->GetXFormatIdx();
			const Workbook::Font& font = fmt_mgr.get_font(fmt);
			string font_name = stringFromSmallString(font.name_);
			cout << "  font name: " << font_name;
			const wstring& fmt_string = fmt.get_format_string();
			cout << "  format: " << narrow_string(fmt_string) << " ";			
			
			cell->SetFormat(fmt_general);
			cout << setw(10) << *(sheet->Cell(y,x)) << endl;						
		}		
	}	
	cout << "write: " << from << endl;
	xls.SaveAs(to);
}

How do I store sheet->Cell(y,x) as variable...
Posted
Updated 7-Oct-10 22:28pm
v2
Comments
perilbrain 8-Oct-10 15:40pm    
char **df=( char**)&reinterpret_cast<const char="" &="">(Cell->GetString());
Are u new to programming???
further more Cell.value2 is the correct thing to retrieve data.

As far as cannot convert from 'const char *' to 'char', you can you static_cast<char>(X) to get rid of the const.
 
Share this answer
 
char str = cell->GetString();


As the message clearly states, you cannot store a character pointer into a character variable. Try:
char* str = cell->GetString();
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900