[GH-ISSUE #74] Worksheet row or column index out of range Error #62

Closed
opened 2026-05-05 11:35:06 -06:00 by gitea-mirror · 8 comments
Owner

Originally created by @aherle on GitHub (Oct 26, 2016).
Original GitHub issue: https://github.com/jmcnamara/libxlsxwriter/issues/74

I am getting Worksheet row or column index out of range when I tried to Write a cell.

  1. - I write cell in 2nd row row and 1st column in 1st iteration of the loop
  2. - When I try to write a cell in the 2nd row row and 2nd column in the 2nd iteration I am getting out of range error.

What is the reason for above mentioned behavour ?
What are cases or possibilities which can result in Worksheet row or column index out of range Error ?

Originally created by @aherle on GitHub (Oct 26, 2016). Original GitHub issue: https://github.com/jmcnamara/libxlsxwriter/issues/74 I am getting `Worksheet row or column index out of range` when I tried to Write a cell. 1. \- I write cell in 2nd row row and 1st column in 1st iteration of the loop 2. \- When I try to write a cell in the 2nd row row and 2nd column in the 2nd iteration I am getting out of range error. What is the reason for above mentioned behavour ? What are cases or possibilities which can result in `Worksheet row or column index out of range Error` ?
Author
Owner

@jmcnamara commented on GitHub (Oct 26, 2016):

Hi Ankith,

Could you add a small, complete, working example that demonstrates the issue.

John

<!-- gh-comment-id:256265852 --> @jmcnamara commented on GitHub (Oct 26, 2016): Hi Ankith, Could you add a small, complete, working example that demonstrates the issue. John
Author
Owner

@aherle commented on GitHub (Oct 26, 2016):

Thanks for replying.
I will update the issue description.

<!-- gh-comment-id:256266002 --> @aherle commented on GitHub (Oct 26, 2016): Thanks for replying. I will update the issue description.
Author
Owner

@aherle commented on GitHub (Oct 26, 2016):

@jmcnamara Updated the issue description, please check.

<!-- gh-comment-id:256266512 --> @aherle commented on GitHub (Oct 26, 2016): @jmcnamara Updated the issue description, please check.
Author
Owner

@jmcnamara commented on GitHub (Oct 26, 2016):

@ankithherle What I really need is a small example program that demostrates the issue.

Like this:

#include <stdio.h>
#include "xlsxwriter.h"

int main() {

    lxw_workbook  *workbook  = workbook_new("bug_report.xlsx");
    lxw_worksheet *worksheet = workbook_add_worksheet(workbook, NULL);

    printf("Libxlsxwriter version = %s\n", LXW_VERSION);

    worksheet_write_string(worksheet, 0, 0, "Hello", NULL);
    worksheet_write_number(worksheet, 1, 0, 123, NULL);

    return workbook_close(workbook);
}

Also, let me know the version printed out from the example on your system.

See also Report Bugs in libxlsxwriter.

<!-- gh-comment-id:256278859 --> @jmcnamara commented on GitHub (Oct 26, 2016): @ankithherle What I really need is a small example program that demostrates the issue. Like this: ``` C #include <stdio.h> #include "xlsxwriter.h" int main() { lxw_workbook *workbook = workbook_new("bug_report.xlsx"); lxw_worksheet *worksheet = workbook_add_worksheet(workbook, NULL); printf("Libxlsxwriter version = %s\n", LXW_VERSION); worksheet_write_string(worksheet, 0, 0, "Hello", NULL); worksheet_write_number(worksheet, 1, 0, 123, NULL); return workbook_close(workbook); } ``` Also, let me know the version printed out from the example on your system. See also [Report Bugs in libxlsxwriter](https://github.com/jmcnamara/libxlsxwriter/blob/master/CONTRIBUTING.md).
Author
Owner

@aherle commented on GitHub (Oct 26, 2016):

@jmcnamara

Sample code from which Error is generated

#include "stdio.h"
#include "xlsxwriter.h"


void write_workbook()
{
    lxw_workbook_options workbook_options = {.constant_memory = 1, .tmpdir = "/tmp"};
    lxw_workbook  *workbook = workbook_new_opt("SAMPLE.xlsx", &workbook_options);
    lxw_worksheet *worksheet_1 = workbook_add_worksheet(workbook, "SHEET 1");
    lxw_worksheet *worksheet_2 = workbook_add_worksheet(workbook, "SHEET 2");

    lxw_format *format = workbook_add_format(workbook);
    format_set_font_color(format, LXW_COLOR_BLACK);
    format_set_align(format, LXW_ALIGN_CENTER);
    format_set_align(format, LXW_ALIGN_VERTICAL_TOP);
    format_set_border(format, LXW_BORDER_THIN);

    worksheet_set_column(worksheet_2, 0, 30, 25, NULL);

    char string[256];

    worksheet_write_blank(worksheet_2, 0, 0, format);
    worksheet_write_blank(worksheet_2, 1, 0, format);

    for (int column = 0; column < 30; column ++) {
        for (int row = 0; row < 100; row++) {
            lxw_error error_ = worksheet_write_string(worksheet_2, row, column, "SAMPLE STIRNG", format);
            if (error_) {
                printf("Error %d - %d = %s\n", row, column, lxw_strerror(error_));
            }
        }
    }

    workbook_close(workbook);
}

int main(int argc, char * argv[])
{
    write_workbook();

    return 0;
}
<!-- gh-comment-id:256288288 --> @aherle commented on GitHub (Oct 26, 2016): @jmcnamara #### Sample code from which Error is generated ``` c #include "stdio.h" #include "xlsxwriter.h" void write_workbook() { lxw_workbook_options workbook_options = {.constant_memory = 1, .tmpdir = "/tmp"}; lxw_workbook *workbook = workbook_new_opt("SAMPLE.xlsx", &workbook_options); lxw_worksheet *worksheet_1 = workbook_add_worksheet(workbook, "SHEET 1"); lxw_worksheet *worksheet_2 = workbook_add_worksheet(workbook, "SHEET 2"); lxw_format *format = workbook_add_format(workbook); format_set_font_color(format, LXW_COLOR_BLACK); format_set_align(format, LXW_ALIGN_CENTER); format_set_align(format, LXW_ALIGN_VERTICAL_TOP); format_set_border(format, LXW_BORDER_THIN); worksheet_set_column(worksheet_2, 0, 30, 25, NULL); char string[256]; worksheet_write_blank(worksheet_2, 0, 0, format); worksheet_write_blank(worksheet_2, 1, 0, format); for (int column = 0; column < 30; column ++) { for (int row = 0; row < 100; row++) { lxw_error error_ = worksheet_write_string(worksheet_2, row, column, "SAMPLE STIRNG", format); if (error_) { printf("Error %d - %d = %s\n", row, column, lxw_strerror(error_)); } } } workbook_close(workbook); } int main(int argc, char * argv[]) { write_workbook(); return 0; } ```
Author
Owner

@aherle commented on GitHub (Oct 26, 2016):

@jmcnamara I am using latest version of libxlsxwriter library.

Link to file which contains output printed on terminal:
Error displayed.txt

Link to Sample xlsx file genrated:
https://drive.google.com/open?id=0B4rT-3u4TZHkZG92OC1kakxjaW8

Look into this.

<!-- gh-comment-id:256290039 --> @aherle commented on GitHub (Oct 26, 2016): @jmcnamara I am using latest version of `libxlsxwriter` library. Link to file which contains output printed on terminal: [Error displayed.txt](https://drive.google.com/open?id=0B4rT-3u4TZHkYVlHMnJraThhb00) Link to Sample xlsx file genrated: https://drive.google.com/open?id=0B4rT-3u4TZHkZG92OC1kakxjaW8 Look into this.
Author
Owner

@jmcnamara commented on GitHub (Oct 26, 2016):

@ankithherle

Thanks for the example. In general output files aren't useful but the programs that generate them are.

The issue here is that you are using constant_memory option and in that mode the cell data must be written in row x column order or else the data will be ignore.

This is explained in the docs in Constant Memory Mode and also in the section on workbook_new_opt().

The solution is to not use constant memory mode or else structure your code so the data is written in row x column order. In your example, switching the order of the for loops will help but you will also have to move the write_blank() calls.

<!-- gh-comment-id:256295628 --> @jmcnamara commented on GitHub (Oct 26, 2016): @ankithherle Thanks for the example. In general output files aren't useful but the programs that generate them are. The issue here is that you are using `constant_memory` option and in that mode the cell data must be written in row x column order or else the data will be ignore. This is explained in the docs in [Constant Memory Mode](https://libxlsxwriter.github.io/working_with_memory.html) and also in the section on [`workbook_new_opt()`](https://libxlsxwriter.github.io/workbook_8h.html#a8ca9bd8c30c618b81ca6180f78b03323). The solution is to not use constant memory mode or else structure your code so the data is written in row x column order. In your example, switching the order of the for loops will help but you will also have to move the `write_blank()` calls.
Author
Owner

@aherle commented on GitHub (Oct 26, 2016):

Issue is resolved after I removed constant_memory. Thank you @jmcnamara .

<!-- gh-comment-id:256298265 --> @aherle commented on GitHub (Oct 26, 2016): Issue is resolved after I removed `constant_memory`. Thank you @jmcnamara .
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: github-starred/libxlsxwriter#62
No description provided.