minexcel
parse_block(block, tmpl)
Parses a structured data block into a DataFrame using a template definition.
This function processes a DataFrame according to a template specification that defines: - Table-level metadata locations - Row metadata ranges - Column metadata ranges - Data value locations The parsed result combines metadata with data values in long format.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
block
|
DataFrame
|
Input DataFrame containing structured data to be parsed. Expected shape: (tmpl['block_nrow'], tmpl['block_ncol']) |
required |
tmpl
|
Dict[str, Any]
|
Template dictionary defining the block structure. Expected keys: 'block_nrow': Expected number of rows in block 'block_ncol': Expected number of columns in block 'tablemeta': Dict of {metadata_key: (row, col)} positions 'rowmeta': Dict of {metadata_key: {'col': col_index, 'start': start_row, 'end': end_row}} 'colmeta': Dict of {metadata_key: {'row': row_index, 'start': start_col, 'end': end_col}} 'data_rows_list': List of row indices containing data values 'data_cols_list': List of column indices containing data values |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
pd.DataFrame: DataFrame containing: - 'row_index': Original row index in full valid contents (after skip rows and cols) - 'col_index': Original column index in full valid contents - 'value': Data value from the block - Columns for each tablemeta key with corresponding values - Columns for each rowmeta key with row-level metadata - Columns for each colmeta key with column-level metadata |
Raises:
| Type | Description |
|---|---|
AssertionError
|
If input block dimensions don't match template specifications |
Source code in src/minexcel/block.py
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 | |
parse_template(template_file)
Parses an Excel template file to extract metadata information about its structure.
This function analyzes an Excel template and returns a dictionary containing: - Dimensions of the entire template and data blocks - Positions of row and column metadata markers - Table-level metadata positions - Validation checks for template structure
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
template_file
|
str
|
Path to the Excel template file (.xlsx) to be parsed |
required |
Returns:
| Type | Description |
|---|---|
Dict[str, Any]
|
A dictionary with the following structure: |
Dict[str, Any]
|
|
Dict[str, Any]
|
|
Dict[str, Any]
|
|
Dict[str, Any]
|
|
Dict[str, Any]
|
|
Dict[str, Any]
|
|
Dict[str, Any]
|
|
Dict[str, Any]
|
|
Dict[str, Any]
|
|
Raises:
| Type | Description |
|---|---|
AssertionError
|
If the template structure doesn't meet requirements:
|
Source code in src/minexcel/block.py
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 | |
read_block_excel(path, tmpl, sheetname=None, skipheader=0, skipfooter=0, skipleft=0, skipright=0, intervalrows=0, intervalcols=0)
Reads structured Excel data blocks from a file and parses them according to a template.
This function processes an Excel file containing multiple structured data blocks separated by specified intervals. Each block is parsed using the provided template definition to extract data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
Path to the Excel file |
required |
tmpl
|
Dict[str, Any]
|
Template dictionary defining block structure |
required |
sheetname
|
Optional[str]
|
Name of the sheet to read. If None, the active sheet is used |
None
|
skipheader
|
int
|
Number of rows to skip at top of sheet |
0
|
skipfooter
|
int
|
Number of rows to skip at bottom of sheet |
0
|
skipleft
|
int
|
Number of columns to skip at left of sheet |
0
|
skipright
|
int
|
Number of columns to skip at right of sheet |
0
|
intervalrows
|
int
|
Number of separator rows between vertical blocks |
0
|
intervalcols
|
int
|
Number of separator columns between horizontal blocks |
0
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
pd.DataFrame: Concatenated DataFrame containing all parsed blocks in long format |
Raises:
| Type | Description |
|---|---|
AssertionError
|
If sheet dimensions don't fit specified block structure |
Source code in src/minexcel/block.py
263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 | |
read_excel_with_merged_cell(path, sheetname=None)
Reads an Excel file and processes merged cells by filling the merged area with the top-left cell's value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
Path to the Excel file |
required |
sheetname
|
Optional[str]
|
Name of the sheet to read. If None, the active sheet is used |
None
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
DataFrame containing the data from the Excel sheet with merged cells processed |
Raises:
| Type | Description |
|---|---|
AssertionError
|
If the provided sheetname is not in the workbook |
Source code in src/minexcel/utils.py
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | |