2022-11-10 13:15:28 +04:00
|
|
|
/*
|
2022-11-12 18:03:22 +00:00
|
|
|
* Example of using libxlsxwriter to write a workbook file to a memory buffer.
|
2022-11-10 13:15:28 +04:00
|
|
|
*
|
2025-02-11 00:03:36 +00:00
|
|
|
* Copyright 2014-2025, John McNamara, jmcnamara@cpan.org
|
2022-11-10 13:15:28 +04:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include "xlsxwriter.h"
|
|
|
|
|
|
|
|
int main() {
|
2023-09-24 20:40:07 +01:00
|
|
|
const char *output_buffer;
|
2022-11-10 13:15:28 +04:00
|
|
|
size_t output_buffer_size;
|
|
|
|
|
|
|
|
/* Set the worksheet options. */
|
|
|
|
lxw_workbook_options options = {.output_buffer = &output_buffer,
|
|
|
|
.output_buffer_size = &output_buffer_size,
|
|
|
|
.constant_memory = LXW_FALSE,
|
|
|
|
.tmpdir = NULL,
|
|
|
|
.use_zip64 = LXW_FALSE};
|
|
|
|
|
|
|
|
/* Create a new workbook with options. */
|
|
|
|
lxw_workbook *workbook = workbook_new_opt(NULL, &options);
|
|
|
|
lxw_worksheet *worksheet = workbook_add_worksheet(workbook, NULL);
|
|
|
|
|
|
|
|
worksheet_write_string(worksheet, 0, 0, "Hello", NULL);
|
|
|
|
worksheet_write_number(worksheet, 1, 0, 123, NULL);
|
|
|
|
|
|
|
|
lxw_error error = workbook_close(workbook);
|
|
|
|
|
|
|
|
if (error)
|
|
|
|
return error;
|
|
|
|
|
|
|
|
/* Do something with the XLSX data in the output buffer. */
|
|
|
|
FILE *file = fopen("output_buffer.xlsx", "wb");
|
|
|
|
fwrite(output_buffer, output_buffer_size, 1, file);
|
|
|
|
fclose(file);
|
2023-09-24 20:40:07 +01:00
|
|
|
free((void *)output_buffer);
|
2022-11-10 13:15:28 +04:00
|
|
|
|
|
|
|
return ferror(stdout);
|
|
|
|
}
|