BUG: TypeError with to_html(sparsify=False) and max_cols < len(columns)
State: closed

- [x] closes #22887
- [x] closes #11060
- [x] tests added / passed
- [x] passes `git diff upstream/master -u -- "*.py" | flake8 --diff`
- [x] whatsnew entry


Labels:
name: Bug
name: IO HTML
description: read_html, to_html, Styler.apply, Styler.applymap

Comments:
looks good can you add a whatsnew note
# [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/24572?src=pr&el=h1) Report
> Merging [#24572](https://codecov.io/gh/pandas-dev/pandas/pull/24572?src=pr&el=desc) into [master](https://codecov.io/gh/pandas-dev/pandas/commit/588b558cfa6b57c23e81202046b9f4add0e9e4f0?src=pr&el=desc) will **increase** coverage by `<.01%`.
> The diff coverage is `100%`.

[![Impacted file tree graph](https://codecov.io/gh/pandas-dev/pandas/pull/24572/graphs/tree.svg?width=650&token=eZ4WkYLtcO&height=150&src=pr)](https://codecov.io/gh/pandas-dev/pandas/pull/24572?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master   #24572      +/-   ##
==========================================
+ Coverage   92.31%   92.31%   +<.01%     
==========================================
  Files         166      166              
  Lines       52556    52559       +3     
==========================================
+ Hits        48518    48522       +4     
+ Misses       4038     4037       -1
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `90.74% <100%> (ø)` | :arrow_up: |
| #single | `43.06% <0%> (-0.01%)` | :arrow_down: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/24572?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/io/formats/html.py](https://codecov.io/gh/pandas-dev/pandas/pull/24572/diff?src=pr&el=tree#diff-cGFuZGFzL2lvL2Zvcm1hdHMvaHRtbC5weQ==) | `99.36% <100%> (+0.32%)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/24572?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/24572?src=pr&el=footer). Last update [588b558...65213f9](https://codecov.io/gh/pandas-dev/pandas/pull/24572?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

# [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/24572?src=pr&el=h1) Report
> Merging [#24572](https://codecov.io/gh/pandas-dev/pandas/pull/24572?src=pr&el=desc) into [master](https://codecov.io/gh/pandas-dev/pandas/commit/588b558cfa6b57c23e81202046b9f4add0e9e4f0?src=pr&el=desc) will **increase** coverage by `<.01%`.
> The diff coverage is `100%`.

[![Impacted file tree graph](https://codecov.io/gh/pandas-dev/pandas/pull/24572/graphs/tree.svg?width=650&token=eZ4WkYLtcO&height=150&src=pr)](https://codecov.io/gh/pandas-dev/pandas/pull/24572?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master   #24572      +/-   ##
==========================================
+ Coverage   92.31%   92.32%   +<.01%     
==========================================
  Files         166      166              
  Lines       52556    52559       +3     
==========================================
+ Hits        48518    48523       +5     
+ Misses       4038     4036       -2
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `90.74% <100%> (ø)` | :arrow_up: |
| #single | `43.05% <0%> (-0.01%)` | :arrow_down: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/24572?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/io/formats/html.py](https://codecov.io/gh/pandas-dev/pandas/pull/24572/diff?src=pr&el=tree#diff-cGFuZGFzL2lvL2Zvcm1hdHMvaHRtbC5weQ==) | `99.36% <100%> (+0.32%)` | :arrow_up: |
| [pandas/util/testing.py](https://codecov.io/gh/pandas-dev/pandas/pull/24572/diff?src=pr&el=tree#diff-cGFuZGFzL3V0aWwvdGVzdGluZy5weQ==) | `87.71% <0%> (+0.09%)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/24572?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/24572?src=pr&el=footer). Last update [588b558...56b4aae](https://codecov.io/gh/pandas-dev/pandas/pull/24572?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

thanks!