2

I'm trying to read a set of data from my Excel file. enter image description here

I am able to read the integers from the first column:

const auto sdf = sheet.cell(fmt::format("A{}", rowIndex)).value().get<int>();

I am also able to read the strings from the second column:

const auto sdf = sheet.cell(fmt::format("B{}", rowIndex)).value().get<std::string>();

but I can't figure out how to read the values in column C into doubles.

I tried:

const auto sdf = sheet.cell(fmt::format("C{}", rowIndex)).value().get<double>();

but that results in termination:

terminate called after throwing an instance of 'OpenXLSX::XLValueTypeError'
  what():  XLCellValue object does not contain the requested type.

Would anybody know what to do? How do I read a float from my file?

Edit

I also check some tests from the OpenXLSX repo. I don't find any differences.

2
  • 2
    You should catch value type exceptions anyway otherwise simple typo in input file will terminate your universe. Perhaps there are integers 1 only formatted as "1.00". Commented May 15, 2024 at 11:01
  • @ÖöTiib Jesus, you are correct. Reading as integers works. The first few rows are really integers, the last few become doubles. I'll have to take care of that separately I guess. Commented May 15, 2024 at 11:05

1 Answer 1

0

Ther's an open issue on GitHub (OpenXLSX repository) with a proposal fix (https://github.com/troldal/OpenXLSX/issues/196).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.