O
O
oleg0xff2016-01-25 18:53:37
linux
oleg0xff, 2016-01-25 18:53:37

Need an example of working with GSF to create MS Structured Storage under Linux. Where to find?

I need an example for the GSF library ( https://developer.gnome.org/gsf/1.14
) how to write an MS Structured Storage format file under Linux (Raspbian) with the help of it in order to subsequently read it from under MS Windows using standard MS Windows tools . I didn’t find any documentation describing this process more or less understandably, but I found a program in which this library is used for the same purposes: https://github.com/GNOME/gnumeric . I looked at how they do it and made it like the same for myself:

#include <iostream>
extern "C" {
#include <gsf/gsf.h>
#include<glib-object.h>
}

int main()
{
    gsf_init();

    const char * out_file_name = "storage.bin";
    GError *err;

    FILE *file = fopen(out_file_name, "wr");

    if (!file) {
        std::cout << "file open fail" << std::endl;
        exit(0);
    }

   GsfOutput *output = gsf_output_stdio_new_FILE (out_file_name, file, false);

   GsfOutfile *output_file_ole2 = gsf_outfile_msole_new(output);

   GsfOutput *output2 = gsf_outfile_new_child(output_file_ole2, "5555tteesstt",  false);
   int ret;

   GsfDocMetaData *docMetaData = gsf_doc_meta_data_new();
   GValue x = G_VALUE_INIT;

   g_value_init(&x, G_TYPE_STRING);
   g_value_set_string(&x, "Ttteeesssttt");
   gsf_doc_meta_data_insert(docMetaData, "zzzzz", &x);
   gsf_doc_meta_dump(docMetaData);

   ret = gsf_doc_meta_data_write_to_msole(docMetaData, output2, true);
   std::cout << "gsf_doc_meta_data_write_to_msole ret=" << ret << std::endl;

   ret = gsf_output_close(output2);
   g_object_unref(output2);
   std::cout << "ret=" << ret << std::endl;

   ret = gsf_output_close(output);
   g_object_unref(output);
   std::cout << "ret=" << ret << std::endl;

    return 0;
}

But this code doesn't create the correct file: I can't then open it with a program like SSViewer ( www.mitec.cz/ssv.html ). Moreover, the data written to output2 does not end up in the file at all, the output2 buffer is separate from output and is not transferred anywhere. I can write the output2 buffer to output using the gsf_output_write function, physically the data appears in the file, but it still won't open under MS Windows.
I would be grateful if someone can tell me where to get an example or more detailed documentation than the link that I gave.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
O
oleg0xff, 2016-01-28
@oleg0xff

I figured it out, here is an example of code that writes a file in MS Structured Storage format:

#include <iostream>
extern "C" {
#include <gsf/gsf.h>
#include<glib-object.h>
}

int main()
{
    gsf_init();

    const char *out_file_name = "storage.bin";

    FILE *file = fopen(out_file_name, "wr");

    if (!file) {
        std::cout << "file open fail" << std::endl;
        exit(0);
    }

    GsfOutput *output = gsf_output_stdio_new_FILE(out_file_name, file, true);

    GsfOutfile *output_file_ole2 = gsf_outfile_msole_new(output);

    GsfOutput *output2 = gsf_outfile_new_child(output_file_ole2, "5555tteesstt", false);
    gsf_output_puts(output2, "The quick brown fox is afraid of the cats.\n");


    ret = gsf_output_close(output2);
    g_object_unref(G_OBJECT(output2));

    gsf_output_close(GSF_OUTPUT(output_file_ole2));
    g_object_unref(G_OBJECT(output_file_ole2));

    ret = gsf_output_close(output);
    g_object_unref(G_OBJECT(output));

    gsf_shutdown();

    return 0;
}

A
Alexey Cheremisin, 2016-01-25
@leahch

I'm not sure if this is exactly what you need, but look at https://poi.apache.org/
True, this is Java, but at least I prepared excel documents on it and not only.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question