Here is the code to load the xls/xlsx file:
int main()
{
BookHandle book = xlCreateBook();
if(book)
{
if(xlBookLoad(book, L"Slice.xlsx"))
{
SheetHandle sheet = xlBookGetSheet(book, 0);
if(sheet)
{
double d;
const wchar_t* s = xlSheetReadStr(sheet, 2, 1, 0);
if(s) wprintf(L"%s\n", s);
d = xlSheetReadNum(sheet, 3, 1, 0);
printf("%g\n", d);
}
}
xlBookRelease(book);
}
printf("\nPress any key to exit...");
_getch();
return 0;
}
These are actually the example code. the xlBookLoad()
fails so that the if statement is skipped.
However, if I load its own file example1.xls, it succeeded. Slice.xlsx and example.xls are in the same folder. I am 100% sure the file path is correct. It was the loading functionality that failed.
Now, I don't know why. Was that because the Slice.xlsx is kinda special? or LibXL is not the tool to load it? If so how can I read it?
I am attaching it here. Thanks a lot in advance to anyone that helps.
Slice.xlsx:
From the documentation, it is stated that you should use xlCreateBook
to work with a *.xls file and xlCreateXMLBook
to work with a *.xlsx file. Thus, for Slice.xlsx, use xlCreateXMLBook
in the place of xlCreateBook
. http://www.libxl.com/documentation.html