Skip to content
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

Fix: Add OpenReader options to GetRows #1816

Merged
merged 6 commits into from Feb 15, 2024
Merged

Conversation

vivekkairi
Copy link
Contributor

PR Details

The Options struct passed to OpenReader function is not passed in the GetRows which results in passing the options separately resulting in duplication

Description

Passing Options to OpenReader should automatically pass the same Options in the child function call as it is done initially. Currently the OpenReader options are not used in GetRows function, which causes inconsistency and leads to duplication.

Related Issue

#1815

Motivation and Context

It solves the duplicate need of passing Options if it's already passed in OpenReader

How Has This Been Tested

Tested locally on my machine with multiple excel files and the output it gives satisfies the requirement

Types of changes

  • Docs change / refactoring / dependency upgrade
  • [ X] Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • [X ] I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • [ X] All new and existing tests passed.

@xuri xuri added the size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. label Feb 15, 2024
Copy link
Member

@xuri xuri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently, the OpenReader options are not used in the GetRows function, the GetRows function just uses the same data structure Options as the OpenReader function to specify the RawCellValue. I agree with making the cell value reading functions inherit the Options settings of the OpenReader function, and we need to consider following 2 conditions:

  1. If Options have also been passed when calling the cell value reading functions, its priority should be higher than OpenReader and override its settings, so the code needs to be changed to:
-opts = append(opts, *f.options)
+opts = append([]Options{*rows.f.options}, opts...)
  1. The following cell reading functions also need to inherit the Options settings:

Based on the above two points, to avoid append options duplicated, I suggest changing the getOptions function to support inheriting the Options settings of the OpenReader function, just like this:

-func getOptions(opts ...Options) *Options {
-    options := &Options{}
+func (f *File) getOptions(opts ...Options) *Options {
+    options := f.options
  1. The unit tests covered these changes

@vivekkairi
Copy link
Contributor Author

Currently, the OpenReader options are not used in the GetRows function, the GetRows function just uses the same data structure Options as the OpenReader function to specify the RawCellValue. I agree with making the cell value reading functions inherit the Options settings of the OpenReader function, and we need to consider following 2 conditions:

  1. If Options have also been passed when calling the cell value reading functions, its priority should be higher than OpenReader and override its settings, so the code needs to be changed to:
-opts = append(opts, *f.options)
+opts = append([]Options{*rows.f.options}, opts...)
  1. The following cell reading functions also need to inherit the Options settings:

Based on the above two points, to avoid append options duplicated, I suggest changing the getOptions function to support inheriting the Options settings of the OpenReader function, just like this:

-func getOptions(opts ...Options) *Options {
-    options := &Options{}
+func (f *File) getOptions(opts ...Options) *Options {
+    options := f.options
  1. The unit tests covered these changes

I've done the code changes, the current tests are passing. Could you guide me through the unit tests once?

col.go Outdated Show resolved Hide resolved
rows.go Outdated Show resolved Hide resolved
@vivekkairi
Copy link
Contributor Author

Fixed, also removed multiple times options fetch in CalcCellValue

@xuri xuri added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. and removed size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Feb 15, 2024
Copy link

codecov bot commented Feb 15, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (9cbe3b6) 99.20% compared to head (5bb98ff) 99.20%.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1816   +/-   ##
=======================================
  Coverage   99.20%   99.20%           
=======================================
  Files          32       32           
  Lines       23851    23852    +1     
=======================================
+ Hits        23662    23663    +1     
  Misses        101      101           
  Partials       88       88           
Flag Coverage Δ
unittests 99.20% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@xuri xuri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks for your contribution.

@xuri xuri merged commit ee2ef15 into qax-os:master Feb 15, 2024
29 checks passed
@xuri xuri added this to Features in v2.8.1 Feb 15, 2024
@vivekkairi
Copy link
Contributor Author

Hey @xuri

I am using v2 version of excelize, do I need to send a separate PR for that?

@xuri
Copy link
Member

xuri commented Feb 15, 2024

The next version will be released based on the master branch. You can upgrade to the master branch code by go get -u github.com/xuri/excelize/v2@master before that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size/S Denotes a PR that changes 10-29 lines, ignoring generated files.
Projects
No open projects
v2.8.1
Features
Development

Successfully merging this pull request may close these issues.

None yet

2 participants