Skip to content

Commit

Permalink
Merge pull request #54 from level12/xlsx-cell-merge-warning
Browse files Browse the repository at this point in the history
Avoid cell merge warning when a grid's second column has a subtotal
  • Loading branch information
bladams committed Mar 25, 2019
2 parents 8cccb06 + abff6bf commit 05e0663
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 30 deletions.
16 changes: 0 additions & 16 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,6 @@ environment:
CMD_IN_ENV: "cmd /E:ON /V:ON /C .\\appveyor\\run_with_env.cmd"

matrix:
- PYTHON: "C:\\Python27"
PYTHON_ARCH: "32"
TOXENV: py27-{base,i18n}

- PYTHON: "C:\\Python34"
PYTHON_ARCH: "32"
TOXENV: py34-{base,i18n}

- PYTHON: "C:\\Python35"
PYTHON_ARCH: "32"
TOXENV: py35-{base,i18n}
Expand All @@ -26,14 +18,6 @@ environment:
PYTHON_ARCH: "32"
TOXENV: py37-{base,i18n}

- PYTHON: "C:\\Python27-x64"
PYTHON_ARCH: "64"
TOXENV: py27-{base,i18n}

- PYTHON: "C:\\Python34-x64"
PYTHON_ARCH: "64"
TOXENV: py34-{base,i18n}

- PYTHON: "C:\\Python35-x64"
PYTHON_ARCH: "64"
TOXENV: py35-{base,i18n}
Expand Down
2 changes: 0 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@
'Intended Audience :: Developers',
'License :: OSI Approved :: BSD License',
'Operating System :: OS Independent',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[tox]
envlist = py{27,34,35,36,37}-{base,i18n},flake8
envlist = py{35,36,37}-{base,i18n},flake8


[testenv]
Expand Down
22 changes: 13 additions & 9 deletions webgrid/renderers.py
Original file line number Diff line number Diff line change
Expand Up @@ -869,15 +869,19 @@ def totals_row(self, xlh, rownum, record, wb):
numrecords,
's' if numrecords != 1 else '',
)
xlh.ws.merge_range(
xlh.rownum,
xlh.colnum,
xlh.rownum,
xlh.colnum + colspan - 1,
bufferval,
base_style
)
xlh.colnum = xlh.colnum + colspan
if colspan > 1:
xlh.ws.merge_range(
xlh.rownum,
xlh.colnum,
xlh.rownum,
xlh.colnum + colspan - 1,
bufferval,
base_style
)
xlh.colnum = xlh.colnum + colspan
else:
xlh.awrite(bufferval, base_style)

firstcol = False
colspan = 0

Expand Down
30 changes: 28 additions & 2 deletions webgrid/tests/test_rendering.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,16 @@
import csv
import xlsxwriter

from webgrid import Column, LinkColumnBase, YesNoColumn, BoolColumn, row_styler, col_filter, \
col_styler
from webgrid import (
Column,
LinkColumnBase,
YesNoColumn,
BoolColumn,
row_styler,
col_filter,
col_styler,
NumericColumn,
)
from webgrid.filters import TextFilter
from webgrid.renderers import RenderLimitExceeded, HTML, XLS, XLSX, CSV
from webgrid_ta.model.entities import ArrowRecord, Person, Status, Email, db
Expand Down Expand Up @@ -682,6 +690,24 @@ def test_totals(self):
eq_(sheet.nrows, 5)
eq_(sheet.cell_value(4, 0), 'Totals (3 records):')
eq_(sheet.cell_value(4, 8), 6.39)
assert sheet.merged_cells == [(4, 5, 0, 8)]

def test_totals_no_merge(self):
class TestGrid(Grid):
subtotals = 'all'
Column('First Name', Person.firstname)
NumericColumn('Number', Person.numericcol, has_subtotal=True)

g = TestGrid()
wb = g.xlsx()
wb.filename.seek(0)

book = xlrd.open_workbook(file_contents=wb.filename.getvalue())
sheet = book.sheet_by_index(0)

eq_(sheet.nrows, 6)
eq_(sheet.cell_value(5, 0), 'Totals (4 records):')
assert sheet.merged_cells == []

def test_can_render(self):
class FakeCountsGrid(PeopleGrid):
Expand Down

0 comments on commit 05e0663

Please sign in to comment.