-
Notifications
You must be signed in to change notification settings - Fork 285
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ZCL_EXCEL_WORKSHEET -> CONVERT_TO_TABLE drops initial excel lines #1195
Comments
I recommend using methods, not SHEET_CONTENT directly (alas, for unknown reason, SHEET_CONTENT was not defined as READ-ONLY or private). I have nothing against adding an optional parameter (it has been done so many times to permit improvements). Could you propose a PR please? |
Thanks for immediate reply and your comment on SHEET_CONTENT, was wondering the same (alas, too little explanation and comments in the code for such things). |
Briefly: you have to fork the project to your GitHub account ("fork" button in GitHub), create a new branch, point ZABAPGIT to this branch, do your changes, push to your GitHub fork and then in GitHub you can click on "Create a pull request". |
Add param. IV_EMPTY_ROWS to take care of: abap2xlsx#1195 abap2xlsx#1199
I tried to push my changes to GitHub fork and in GitHub Create a pull request. For unknown reason too many code differences due to different capitalization of keywords (and these are in the unchanged code, not in the code I pretty printed). |
Thank you. I will try to implement your code. Adding here the lines of your DOCX document. 1 ZCL_EXCEL_WORKSHEET meth. CONVERT_TO_TABLE 1.1 New optional param. IV_EMPTY_ROWS TYPE ABAP_BOOL DEFAULT ABAP_FALSE Flag Keep empty rows 1.2 Coding change 1 1.2.1 compare 1.2.2 old *--------------------------------------------------------------------*
* Start of convert content
*--------------------------------------------------------------------*
READ TABLE me->sheet_content TRANSPORTING NO FIELDS WITH KEY cell_row = iv_begin_row.
IF sy-subrc EQ 0.
lv_index = sy-tabix.
ENDIF. 1.2.3 new *--------------------------------------------------------------------*
* Start of convert content
*--------------------------------------------------------------------*
lv_index = lines( me->sheet_content ) + 1. "in case iv_begin_row too big
LOOP AT me->sheet_content ASSIGNING <ls_sheet_content> WHERE cell_row >= iv_begin_row.
"iv_begin_row might be an empty row with no entries in me->sheet_content
lv_index = sy-tabix.
IF iv_empty_rows = abap_true.
DATA(lv_num_rows) = <ls_sheet_content>-cell_row - iv_begin_row.
DO lv_num_rows TIMES.
"add leading empty rows
APPEND INITIAL LINE TO <lt_data> ASSIGNING <ls_data>.
ENDDO.
ENDIF. 1.3 Coding change 2 1.3.2 old IF <ls_data> IS INITIAL. 1.3.3 new IF <ls_data> IS INITIAL AND iv_empty_rows = abap_false. |
Hi sandraros, sorry, but I now see my copying of code into the word doc was incomplete. For 1.2.3 new it should have been:
before the loop extracting the data:
I had for SE80 exactly the pretty printer setting that you quote. When finally (with help from colleague of mine) getting my forked code uploaded to Github, it showed code with mixed case in parts of the class that I did not touch. At that point I quit and too hastily prepared the word doc that I had attached. |
Thanks for checking! |
Without any option to do different, Worksheet method CONVERT_TO_TABLE drops initial excel lines.
I expect that the table gets populated according to values of lv_maxcol, lv_maxrow that are set at beginning of the method.
In my case I am reading a supplied excel that includes empty lines (and columns), want to add data from SAP into it and finally write the enriched excel. For the SAP part of adding data the result of CONVERT_TO_TABLE is much better to use than the SHEET_CONTENT.
For adding the result back into SHEET_CONTENT and the correct excel line, I need to have the lines exactly same in the table returned by CONVERT_TO_TABLE and the excel. (of course, tedious workarounds are possible with current behavior of CONVERT_TO_TABLE)
Think this is easy to change by an additional optional parameter for CONVERT_TO_TABLE. It looks only around lines 249 change is needed:
Furthermore, I find it inconsistent that empty lines are dropped, but empty columns are kept.
Small sample file attached: Github-Issue-CONVERT_TO_TABLE.xlsx
The text was updated successfully, but these errors were encountered: