tfussell / xlnt

:bar_chart: Cross-platform user-friendly xlsx library for C++11+
Other
1.47k stars 414 forks source link

Problem with freeze_panes #395

Closed exferior closed 5 years ago

exferior commented 5 years ago

Creating worksheet using 'freeze_panes' with column 'A' or row 1 (e.g. "A2" or "B1") causes problem. When opening the document, Excel throws an alert with following text:

"We found a problem with some content in 'example.xlsx'. Do you want to recover as much as we can? If you trust the source of this workbook, click Yes".

Clicking yes resolves the problem.

togoff commented 5 years ago

xlnt-master\source\detail\serialization\xlsx_producer.cpp

 if (current_pane.top_left_cell.is_set())
            {
                write_attribute("topLeftCell", current_pane.top_left_cell.get().to_string());
            }

            write_attribute("xSplit", current_pane.x_split.index);
            write_attribute("ySplit", current_pane.y_split);

changes to:

 if (current_pane.top_left_cell.is_set())
            {
                write_attribute("topLeftCell", current_pane.top_left_cell.get().to_string());

                if (current_pane.top_left_cell.get().column_index() != 1)
        {
            write_attribute("xSplit", current_pane.x_split.index);
        }

                if (current_pane.top_left_cell.get().row() != 1)
        {
            write_attribute("ySplit", current_pane.y_split);
        }
            }
tfussell commented 5 years ago

Thanks for reporting the error and providing code to fix it. I actually have already fixed this on the dev branch. This will be merged into master in the next release. Feel free to test out my fix and leave a comment if you have any problems with it.