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

Special Case permitting single row to referenced in Range() #12

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion xltable/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@

.. autoclass:: ArrayExpression

.. autoclass:: ArrayConstant

.. autoclass:: Cell

.. autoclass:: Column
Expand All @@ -118,7 +120,7 @@
.. autoclass:: Value

"""
from .expression import Column, Index, Cell, Range, Formula, ConstExpr, Expression, ArrayExpression
from .expression import Column, Index, Cell, Range, Formula, ConstExpr, Expression, ArrayExpression, ArrayConstant
from .style import CellStyle, TableStyle
from .table import Table, Value, ArrayFormula
from .chart import Chart
Expand All @@ -143,4 +145,5 @@
"Formula",
"ArrayExpression",
"ConstExpr",
"ArrayConstant"
]
19 changes: 18 additions & 1 deletion xltable/expression.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ class Range(Expression):
:param left_col: Left most column label this refers to.
:param right_col: Right most column label this refers to.
:param top_row: Top most row label, or None to select from the top of the table.
:param bottom_row: Bottom most row label, or None to select to the bottom of the table.
:param bottom_row: Bottom most row label, or None to select to the bottom of the table, or False to select single row
:param include_header: Include table header in the range.
:param table: Name of table the column is in, if not in the same table this expression is in.
Use "%s!%s" % (worksheet.name, table.name) if refering to a table in another worksheet
Expand Down Expand Up @@ -247,6 +247,8 @@ def resolve(self, workbook, row, col):

if self.__bottom is None:
bottom_row_offset = table.height - 1
elif self.__bottom is False:
bottom_row_offset = top_row_offset
else:
bottom_row_offset = table.get_row_offset(self.__bottom)

Expand Down Expand Up @@ -355,6 +357,21 @@ def resolve(self, workbook, row, col):
return str(self.__value)


class ArrayConstant(Expression):
"""
An evaluated array, an "Array Constant". Can increase performance and/or
reduce dependencies
"""
def __init__(self, array, **kwargs):
super(ArrayConstant, self).__init__(**kwargs)
self.value = array
self.__value = array

def resolve(self, workbook, row, col):
arr_str = ";".join(",".join(map(str,row)) for row in self.__value)
return "{%s}" % arr_str


def _to_addr(worksheet, row, col, row_fixed=False, col_fixed=False):
"""converts a (0,0) based coordinate to an excel address"""
addr = ""
Expand Down