kernel/write.c
/*
 * Call finalization code and close file.
 */
Call finalization code and close file.
Call finalization code and close file .
lxw_error
workbook_file(xls_resource_write_t *self)
{
    lxw_worksheet *worksheet = NULL;
    lxw_packager *packager = NULL;
    lxw_error error = LXW_NO_ERROR;
    if (!self->workbook->num_sheets)
        workbook_add_worksheet(self->workbook, NULL);
    if (self->workbook->active_sheet == 0) {
        worksheet = STAILQ_FIRST(self->workbook->worksheets);
        worksheet->selected = 1;
        worksheet->hidden = 0;
    }
    STAILQ_FOREACH(worksheet, self->workbook->worksheets, list_pointers) {
        if (worksheet->index == self->workbook->active_sheet)
            worksheet->active = 1;
    }
    _prepare_vml(self->workbook);
    _prepare_defined_names(self->workbook);
    _prepare_drawings(self->workbook);
    _add_chart_cache_data(self->workbook);
    packager = lxw_packager_new(self->workbook->filename, self->workbook->options.tmpdir, self->workbook->options.use_zip64);
    if (packager == NULL) {
        fprintf(stderr, "[ERROR] workbook_close(): "
                "Error creating '%s'. "
                "Error = %s\n", self->workbook->filename, strerror(errno));
        error = LXW_ERROR_CREATING_XLSX_FILE;
        goto mem_error;
    }
    packager->workbook = self->workbook;
    error = lxw_create_package(packager);
    if (error == LXW_ERROR_CREATING_TMPFILE) {
        fprintf(stderr, "[ERROR] workbook_close(): "
                "Error creating tmpfile(s) to assemble '%s'. "
                "Error = %s\n", self->workbook->filename, strerror(errno));
    }
    if (error == LXW_ERROR_ZIP_FILE_OPERATION) {
        fprintf(stderr, "[ERROR] workbook_close(): "
                "Zlib error while creating xlsx file '%s'. "
                "Error = %s\n", self->workbook->filename, strerror(errno));
    }
    if (error == LXW_ERROR_ZIP_PARAMETER_ERROR) {
        fprintf(stderr, "[ERROR] workbook_close(): "
                        "Zip ZIP_PARAMERROR error while creating xlsx file '%s'. "
                        "System error = %s\n", self->workbook->filename, strerror(errno));
    }
    if (error == LXW_ERROR_ZIP_BAD_ZIP_FILE) {
        fprintf(stderr, "[ERROR] workbook_close(): "
                        "Zip ZIP_BADZIPFILE error while creating xlsx file '%s'. "
                        "This may require the use_zip64 option for large files. "
                        "System error = %s\n", self->workbook->filename, strerror(errno));
    }
    if (error == LXW_ERROR_ZIP_INTERNAL_ERROR) {
        fprintf(stderr, "[ERROR] workbook_close(): "
                        "Zip ZIP_INTERNALERROR error while creating xlsx file '%s'. "
                        "System error = %s\n", self->workbook->filename, strerror(errno));
    }
    if (error == LXW_ERROR_ZIP_FILE_ADD) {
        fprintf(stderr, "[ERROR] workbook_close(): "
                        "Zlib error adding file to xlsx file '%s'.\n",
                self->workbook->filename);
    }
    if (error == LXW_ERROR_ZIP_CLOSE) {
        fprintf(stderr, "[ERROR] workbook_close(): "
                "Zlib error closing xlsx file '%s'.\n", self->workbook->filename);
    }
    mem_error:
        lxw_packager_free(packager);
    return error;
}
lxw_error workbook_file ( xls_resource_write_t * self ) { lxw_worksheet * worksheet = NULL ; lxw_packager * packager = NULL ; lxw_error error = LXW_NO_ERROR ; if ( ! self -> workbook -> num_sheets ) workbook_add_worksheet ( self -> workbook , NULL ) ; if ( self -> workbook -> active_sheet == 0 ) { worksheet = STAILQ_FIRST ( self -> workbook -> worksheets ) ; worksheet -> selected = 1 ; worksheet -> hidden = 0 ; } STAILQ_FOREACH ( worksheet , self -> workbook -> worksheets , list_pointers ) { if ( worksheet -> index == self -> workbook -> active_sheet ) worksheet -> active = 1 ; } _prepare_vml ( self -> workbook ) ; _prepare_defined_names ( self -> workbook ) ; _prepare_drawings ( self -> workbook ) ; _add_chart_cache_data ( self -> workbook ) ; packager = lxw_packager_new ( self -> workbook -> filename , self -> workbook -> options . tmpdir , self -> workbook -> options . use_zip64 ) ; if ( packager == NULL ) { fprintf ( stderr , " " " " " \n " , self -> workbook -> filename , strerror ( errno ) ) ; error = LXW_ERROR_CREATING_XLSX_FILE ; goto mem_error ; } packager -> workbook = self -> workbook ; error = lxw_create_package ( packager ) ; if ( error == LXW_ERROR_CREATING_TMPFILE ) { fprintf ( stderr , " " " " " \n " , self -> workbook -> filename , strerror ( errno ) ) ; } if ( error == LXW_ERROR_ZIP_FILE_OPERATION ) { fprintf ( stderr , " " " " " \n " , self -> workbook -> filename , strerror ( errno ) ) ; } if ( error == LXW_ERROR_ZIP_PARAMETER_ERROR ) { fprintf ( stderr , " " " " " \n " , self -> workbook -> filename , strerror ( errno ) ) ; } if ( error == LXW_ERROR_ZIP_BAD_ZIP_FILE ) { fprintf ( stderr , " " " " " " " \n " , self -> workbook -> filename , strerror ( errno ) ) ; } if ( error == LXW_ERROR_ZIP_INTERNAL_ERROR ) { fprintf ( stderr , " " " " " \n " , self -> workbook -> filename , strerror ( errno ) ) ; } if ( error == LXW_ERROR_ZIP_FILE_ADD ) { fprintf ( stderr , " " " \n " , self -> workbook -> filename ) ; } if ( error == LXW_ERROR_ZIP_CLOSE ) { fprintf ( stderr , " " " \n " , self -> workbook -> filename ) ; } mem_error : lxw_packager_free ( packager ) ; return error ; }
Call finalization code and close file.
Call finalization code and close file .
/* Add a default worksheet if non have been added. */ /* Ensure that at least one worksheet has been selected. */ /* Set the active sheet. */ /* Prepare the worksheet VML elements such as comments. */ /* Set the defined names for the worksheets such as Print Titles. */ /* Prepare the drawings, charts and images. */ /* Add cached data to charts. */ /* Create a packager object to assemble sub-elements into a zip file. */ /* If the packager fails it is generally due to a zip permission error. */ /* Set the workbook object in the packager. */ /* Assemble all the sub-files in the xlsx package. */ /* Error and non-error conditions fall through to the cleanup code. */ /* If LXW_ERROR_ZIP_FILE_OPERATION then errno is set by zlib. */ /* If LXW_ERROR_ZIP_PARAMETER_ERROR then errno is set by zip. */ /* If LXW_ERROR_ZIP_BAD_ZIP_FILE then errno is set by zip. */ /* If LXW_ERROR_ZIP_INTERNAL_ERROR then errno is set by zip. */ /* The next 2 error conditions don't set errno. */