Go Down

Topic: Libxlsxwriter: library for creating Excel XLSX files. (Read 1 time) previous topic - next topic

rtek1000

I've been looking for a library to write an XLS / XLSX file to export data from a datalogger.

I currently need to export the data to CSV and then convert to XLS using a computer.

I saw that a small Time Attendance Clock, which apparently doesn't have that much processing power, can write the XLS file and save it to a USB stick, similar to this:



So I don't believe the Arduino doesn't have a library that writes the XLS / XLSX file yet.

I found this library: Libxlsxwriter

Quote
Libxlsxwriter is a C library that can be used to write text, numbers, formulas and hyperlinks to multiple worksheets in an Excel 2007+ XLSX file.

It supports features such as:

    100% compatible Excel XLSX files.
    Full Excel formatting.
    Merged cells.
    Defined names.
    Autofilters.
    Charts.
    Data validation and drop down lists.
    Worksheet PNG/JPEG images.
    Memory optimization mode for writing large files.
    Source code available on GitHub.
    FreeBSD license.
    ANSI C.
    Works with GCC, Clang, Xcode, MSVC 2015, ICC, TCC, MinGW, MingGW-w64/32.
    Works on Linux, FreeBSD, OpenBSD, OS X, iOS and Windows. Also works on MSYS/MSYS2 and Cygwin.
    Compiles for 32 and 64 bit.
    Compiles and works on big and little endian systems.
    The only dependency is on zlib.

Here is an example that was used to create the spreadsheet shown above:
Code: [Select]

#include "xlsxwriter.h"

int main() {

    /* Create a new workbook and add a worksheet. */
    lxw_workbook  *workbook  = workbook_new("demo.xlsx");
    lxw_worksheet *worksheet = workbook_add_worksheet(workbook, NULL);

    /* Add a format. */
    lxw_format *format = workbook_add_format(workbook);

    /* Set the bold property for the format */
    format_set_bold(format);

    /* Change the column width for clarity. */
    worksheet_set_column(worksheet, 0, 0, 20, NULL);

    /* Write some simple text. */
    worksheet_write_string(worksheet, 0, 0, "Hello", NULL);

    /* Text with formatting. */
    worksheet_write_string(worksheet, 1, 0, "World", format);

    /* Write some numbers. */
    worksheet_write_number(worksheet, 2, 0, 123,     NULL);
    worksheet_write_number(worksheet, 3, 0, 123.456, NULL);

    /* Insert an image. */
    worksheet_insert_image(worksheet, 1, 2, "logo.png");

    workbook_close(workbook);

    return 0;
}


I tried compiling for Arduino but errors occurred (because it is not "C++" and there seem to be some differences between the arduino IDE libraries themselves, such as different ESP32 errors. Arduino DUE and STM32F1 the same errors occur).

After leaving all files in a single folder, and editing the file headers to their new location, it was possible to compile the first line of sample code. But the second line already generates an error:

Quote
c:/arduino ide/arduino-1.8.10-windows-portable/portable/packages/arduino/tools/arm-none-eabi-gcc/4.8.3-2014q1/bin/../lib/gcc/arm-none-eabi/4.8.3/../../../../arm-none-eabi/lib/armv7-m\libc.a(lib_a-openr.o): In function `_open_r':

openr.c:(.text._open_r+0x10): undefined reference to `_open'

c:/arduino ide/arduino-1.8.10-windows-portable/portable/packages/arduino/tools/arm-none-eabi-gcc/4.8.3-2014q1/bin/../lib/gcc/arm-none-eabi/4.8.3/../../../../arm-none-eabi/lib/armv7-m\libc.a(lib_a-unlinkr.o): In function `_unlink_r':

unlinkr.c:(.text._unlink_r+0xc): undefined reference to `_unlink'

collect2.exe: error: ld returned 1 exit status

exit status 1
Error compiling for board Arduino Due (Programming Port).
Could anyone help compile this library with the arduino IDE?
Please avoid private messages, your question may be someone's answer in the future!

ballscrewbob

Take a look at PLX-DAQ.

Maybe not quite what you want but quite versatile in the excel sphere.
There is a whole thread to the topic.

Bob.
It may not be the answer you were looking for but its the one I am giving based on either experience, educated guess, google or the fact that you gave nothing to go with in the first place so I used my wonky crystal ball.

rtek1000

Thanks, I also found libraries for python, and it looks like it might work with a micropython ESP32, maybe it's a more affordable alternative at the moment.
Please avoid private messages, your question may be someone's answer in the future!

Go Up