MCPcopy
hub / github.com/jmcnamara/XlsxWriter / _write_array_formula

Method _write_array_formula

xlsxwriter/worksheet.py:1105–1157  ·  view source on GitHub ↗
(
        self,
        first_row,
        first_col,
        last_row,
        last_col,
        formula,
        cell_format=None,
        value=0,
        atype="static",
    )

Source from the content-addressed store, hash-verified

1103 # Undecorated version of write_array_formula() and
1104 # write_dynamic_array_formula().
1105 def _write_array_formula(
1106 self,
1107 first_row,
1108 first_col,
1109 last_row,
1110 last_col,
1111 formula,
1112 cell_format=None,
1113 value=0,
1114 atype="static",
1115 ) -> Literal[0, -1]:
1116 # Swap last row/col with first row/col as necessary.
1117 if first_row > last_row:
1118 first_row, last_row = last_row, first_row
1119 if first_col > last_col:
1120 first_col, last_col = last_col, first_col
1121
1122 # Check that row and col are valid and store max and min values.
1123 if self._check_dimensions(first_row, first_col):
1124 return -1
1125 if self._check_dimensions(last_row, last_col):
1126 return -1
1127
1128 # Define array range
1129 if first_row == last_row and first_col == last_col:
1130 cell_range = xl_rowcol_to_cell(first_row, first_col)
1131 else:
1132 cell_range = (
1133 xl_rowcol_to_cell(first_row, first_col)
1134 + ":"
1135 + xl_rowcol_to_cell(last_row, last_col)
1136 )
1137
1138 # Modify the formula string, as needed.
1139 formula = self._prepare_formula(formula)
1140
1141 # Write previous row if in in-line string constant_memory mode.
1142 if self.constant_memory and first_row > self.previous_row:
1143 self._write_single_row(first_row)
1144
1145 # Store the cell data in the worksheet data table.
1146 self.table[first_row][first_col] = CellArrayFormulaTuple(
1147 formula, cell_format, value, cell_range, atype
1148 )
1149
1150 # Pad out the rest of the area with formatted zeroes.
1151 if not self.constant_memory:
1152 for row in range(first_row, last_row + 1):
1153 for col in range(first_col, last_col + 1):
1154 if row != first_row or col != first_col:
1155 self._write_number(row, col, 0, cell_format)
1156
1157 return 0
1158
1159 @convert_cell_args
1160 def write_datetime(

Callers 3

_write_formulaMethod · 0.95
write_array_formulaMethod · 0.95

Calls 5

_check_dimensionsMethod · 0.95
_prepare_formulaMethod · 0.95
_write_single_rowMethod · 0.95
_write_numberMethod · 0.95
xl_rowcol_to_cellFunction · 0.85

Tested by

no test coverage detected