BasicExcel-如何将单元格数据存储为变量? [英] BasicExcel - How do I store cell data as a variable?
问题描述
我正在使用BasicExcel编写程序...我需要从excel文件访问数据并将其存储为变量.
我一直在尝试使用以下方法存储数据:
char str = cell-> GetString();
这将返回错误C2440:正在初始化":无法从"const char *"转换为"char"
这是BasicExpress代码...在哪里添加其他功能?:
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?:
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);
}
如何将工作表-> Cell(y,x)存储为变量...
How do I store sheet->Cell(y,x) as variable...
推荐答案
"char",您可以static_cast< char>(X)删除常量.
As far as cannot convert from ''const char *'' to ''char'', you can you static_cast<char>(X) to get rid of the const.
char str = cell->GetString();
正如该消息明确指出的那样,您不能将字符指针存储到字符变量中.试试:
As the message clearly states, you cannot store a character pointer into a character variable. Try:
char* str = cell->GetString();
这篇关于BasicExcel-如何将单元格数据存储为变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!