Archived
1
Fork 0
This repository has been archived on 2025-04-08. You can view files and clone it, but cannot push or open issues or pull requests.
libxiv/src/exhparser.cpp
Joshua Goins fa8fa9093a Add support for excel sheets with subrows
This also fixes strings not loading past another string
column
2022-04-12 14:39:33 -04:00

50 lines
No EOL
1.3 KiB
C++

#include "exhparser.h"
#include "utility.h"
#include <cstdio>
#include <stdexcept>
#include <vector>
#include <algorithm>
#include <string>
EXH readEXH(const std::string_view path) {
EXH exh;
FILE* file = fopen(path.data(), "rb");
if(file == nullptr) {
throw std::runtime_error("Failed to open exh file " + std::string(path));
}
fread(&exh.header, sizeof(ExhHeader), 1, file);
fseek(file, 0x20, SEEK_SET);
endianSwap(&exh.header.dataOffset);
endianSwap(&exh.header.columnCount);
endianSwap(&exh.header.pageCount);
endianSwap(&exh.header.languageCount);
endianSwap(&exh.header.rowCount);
exh.columnDefinitions.resize(exh.header.columnCount);
fread(exh.columnDefinitions.data(), sizeof(ExcelColumnDefinition) * exh.header.columnCount, 1, file);
exh.pages.resize(exh.header.pageCount);
fread(exh.pages.data(), sizeof(ExcelDataPagination) * exh.header.pageCount, 1, file);
exh.language.resize(exh.header.languageCount);
fread(exh.language.data(), sizeof(Language) * exh.header.languageCount, 1, file);
for(auto& columnDef : exh.columnDefinitions) {
endianSwap(&columnDef.offset);
endianSwap(&columnDef.type);
}
for(auto& page : exh.pages) {
endianSwap(&page.rowCount);
endianSwap(&page.startId);
}
return exh;
}