Created a function to append mandatory fields into custom xls form #289
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description:
This PR introduces a new function
update_xls_form
that updates a custom XLS form by integrating mandatory fields at the start (calculation fields) and appending additional fields (digitization fields) at the end. The function processes all sheets within the provided Excel files, ensuring that any common fields between the custom, mandatory, and append forms are handled correctly.Key Features:
Multiple Sheets Handling:
The function iterates through all sheets in the custom form, updating them with corresponding sheets from the mandatory and append forms.Custom Fields Preservation:
The function ensures that any fields present in the custom form are preserved in their original order, with mandatory fields placed at the beginning and additional fields appended afterward.Common Fields Management:
The function identifies common fields across all three forms, retaining the custom form's version of these fields and excluding them from the mandatory and digitisation forms to prevent duplication.Efficient Memory Usage:
The function returns the updated Excel form directly as a BytesIO object without writing to a file, optimizing memory usage and improving efficiency.