0% found this document useful (0 votes)
3 views1 page

Create a Simple ODS File in C

The document is a C program that creates a simple OpenDocument Spreadsheet (.ods) file using the libzip library. It initializes a ZIP archive, adds a required 'mimetype' file, and includes a basic 'content.xml' with a sample spreadsheet containing names and ages. Finally, it closes the archive and confirms the successful creation of the .ods file.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views1 page

Create a Simple ODS File in C

The document is a C program that creates a simple OpenDocument Spreadsheet (.ods) file using the libzip library. It initializes a ZIP archive, adds a required 'mimetype' file, and includes a basic 'content.xml' with a sample spreadsheet containing names and ages. Finally, it closes the archive and confirms the successful creation of the .ods file.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

#include <stdio.

h>
#include <zip.h>

int main() {
struct zip *archive;
struct zip_source *source;
int err = 0;

// Create a new .ods ZIP file


archive = zip_open("[Link]", ZIP_CREATE | ZIP_TRUNCATE, &err);
if (!archive) {
fprintf(stderr, "Failed to create .ods file.\n");
return 1;
}

// Add required "mimetype" file


const char *mimetype = "application/[Link]";
source = zip_source_buffer(archive, mimetype, strlen(mimetype), 0);
zip_file_add(archive, "mimetype", source, ZIP_FL_ENC_UTF_8);

// Add a very basic [Link]


const char *content_xml =
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
"<office:document-content "
"xmlns:office=\"urn:oasis:names:tc:opendocument:xmlns:office:1.0\" "
"xmlns:table=\"urn:oasis:names:tc:opendocument:xmlns:table:1.0\" "
"xmlns:text=\"urn:oasis:names:tc:opendocument:xmlns:text:1.0\">"
"<office:body><office:spreadsheet>"
"<table:table table:name=\"Sheet1\">"
"<table:table-row>"
"<table:table-cell><text:p>Name</text:p></table:table-cell>"
"<table:table-cell><text:p>Age</text:p></table:table-cell>"
"</table:table-row>"
"<table:table-row>"
"<table:table-cell><text:p>Alice</text:p></table:table-cell>"
"<table:table-cell><text:p>25</text:p></table:table-cell>"
"</table:table-row>"
"</table:table>"
"</office:spreadsheet></office:body></office:document-content>";

source = zip_source_buffer(archive, content_xml, strlen(content_xml), 0);


zip_file_add(archive, "[Link]", source, ZIP_FL_ENC_UTF_8);

// Close the archive


zip_close(archive);

printf("ODS file '[Link]' created successfully!\n");


return 0;
}

You might also like