I am trying to read different cell values from a excel worksheet using the xlnt library for C++ provided at: https://github.com/tfussell/xlnt . The code that i am using is as follows:
double d = cell;//this does not work
//std::string s = cell.to_string() //this works
}
}
My problem is that i am unable to store the printed cell value in a local variable. For example the cell "A1" in my excel sheet contains a date and if i try to store that date in a double using double d = cell. Also the cell "A2" contains an interger and again when i try int i = cell; it doesn't work. I know by looking at the examples in the documentation that if any cell in the excel sheet contains a string then i can use std::string s = cell.to_string() to store that string value. How can i do this for numbers like 23 or 43 and dates like 21/02/2021. I know that in excel dates are stored as numbers. I need this because different columns in my excel sheet have different types of data. For example column A contains all dates, column B contains all time like 12 or 10 oe 24 etc. And column C contain all strings and so on. What i am doing is that going through each cell in the sheet and after checking the type using xlnt::cell::data_type i want to store that particular cell value in a local variable. I know how to check the type of the cell using xlnt but i don't know that after the type is checked and lets say the cell type is date then how can i store that date in a double type variable so that i can use it for later. Similarly after checking the data_type of the cell to be a number i want to store that number in a local varible like int x. How can i do that?
does this work?
int x = stoi(cell.to_str());
or
double d = stod(cell.to_str());
if so, it would seem that you interact with a cell via text mode, or at least that is one way to do it. I took a quick drive by and could not find any place where he reads from a cell into anything other than a string, however he SETS cells when writing to a sheet via cell.value(4) etc so you may not need to stringify going into the sheets, only coming out. There may be some way to get at the value without going through a string, but I don't see how right now.