File xlsx_exporter.cpp
File List > benchmark > exporter > xlsx_exporter.cpp
Go to the documentation of this file
#include "xlsx_exporter.h"
#include "formatter.h"
#include "workbook.h"
#include <cstdlib>
#include <iostream>
#include <xlsxwriter.h>
namespace Argos {
XLSXExporter::XLSXExporter(ExcelFormatter &formatter) : formatter(formatter) {}
void XLSXExporter::Export(const BenchmarkResult &result,
std::ostream &out) const {
const char *output_buffer = nullptr;
size_t output_buffer_size = 0;
lxw_workbook_options options = {};
options.output_buffer = &output_buffer;
options.output_buffer_size = &output_buffer_size;
lxw_workbook *workbook = workbook_new_opt(NULL, &options);
formatter.Fill(workbook, result);
lxw_error error = workbook_close(workbook);
if (error) {
std::cerr << "Error creating Excel file : " << lxw_strerror(error) << "\n";
return;
}
if (output_buffer && output_buffer_size > 0) {
out.write(output_buffer, output_buffer_size);
if (!out) {
std::cerr << "Failed to write Excel data to the output stream.\n";
}
}
free(const_cast<char *>(output_buffer));
}
} // namespace Argos