Core API Reference
sql2excel
SQL2Excel — Generate Excel reports with charts from SQL queries and Pandas DataFrames.
Public API
Report
Top-level orchestrator that executes SQL queries and writes Excel workbooks.
QueryConfig
Configuration object pairing a SQL query with Excel/chart parameters.
SQLExecutor
Executes SQL queries via SQLAlchemy and returns pandas DataFrames.
parse_sql_file
Parse an annotated .sql file into a list of QueryConfig objects.
Config
Default configuration constants for charts, formatting, and layout.
ExcelHelper
openpyxl utility layer for cell formatting, chart styling, and layout.
Chart Classes
Chart Base class for all chart types. LineChart Line chart. BarChart Bar chart. PieChart Pie chart with data-label customization. RadarChart Radar (spider) chart. AreaChart Area chart. ScatterChart Scatter plot with flexible data selection. BubbleChart Bubble chart using x, y, and size columns. StackedBarChart Stacked or percent-stacked bar chart. BarLineChart Combined bar and line chart with dual y-axes. SingleAxisBarLineChart Combined bar and line chart on a single y-axis. ImageChart Embed images or matplotlib figures into Excel. LineBasedChart Abstract base class for line and radar charts. TwoAxesChart Abstract base class for charts with two y-axes.
AreaChart(config=None, excel_helper=None)
Bases: Chart
Area chart.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
Config
|
|
None
|
excel_helper
|
ExcelHelper
|
|
None
|
See Also
Chart : Base class for all chart types.
Initialize an area chart.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
Config
|
Configuration overrides. Defaults to |
None
|
excel_helper
|
ExcelHelper
|
Helper instance. Created from config when not provided. |
None
|
Source code in sql2excel/chart.py
1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 | |
BarChart(config=None, excel_helper=None)
Bases: Chart
Bar chart.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
Config
|
|
None
|
excel_helper
|
ExcelHelper
|
|
None
|
See Also
Chart : Base class for all chart types.
Initialize a bar chart.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
Config
|
Configuration overrides. Defaults to |
None
|
excel_helper
|
ExcelHelper
|
Helper instance. Created from config when not provided. |
None
|
Source code in sql2excel/chart.py
1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 | |
BarLineChart(config=None, excel_helper=None)
Bases: TwoAxesChart
Combined bar and line chart with dual y-axes.
The bar chart is rendered on the primary y-axis and the line chart on the secondary y-axis.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
Config
|
|
None
|
excel_helper
|
ExcelHelper
|
|
None
|
Attributes:
| Name | Type | Description |
|---|---|---|
chart |
None or Chart
|
Placeholder for the combined chart object. |
chart1 |
BarChart
|
The bar chart instance (primary axis). |
chart2 |
LineChart
|
The line chart instance (secondary axis). |
See Also
Chart : Base class for all chart types. TwoAxesChart : Parent class.
Initialize a bar-line chart.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
Config
|
Configuration overrides. Defaults to |
None
|
excel_helper
|
ExcelHelper
|
Helper instance. Created from config when not provided. |
None
|
Source code in sql2excel/chart.py
1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 | |
plot(df, ws, **kwargs)
Plot a combined bar-line chart from df into ws.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
Data to plot; first column is the category axis. |
required |
ws
|
Worksheet
|
The target worksheet. |
required |
**kwargs
|
dict
|
Chart customization options (see |
{}
|
Source code in sql2excel/chart.py
1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 | |
BubbleChart(config=None, excel_helper=None)
Bases: Chart
Bubble chart using x, y, and size columns from a DataFrame.
The first three columns of the DataFrame are used as the x-axis, y-axis, and bubble size respectively. Each row is plotted as a separate series.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
Config
|
|
None
|
excel_helper
|
ExcelHelper
|
|
None
|
See Also
Chart : Base class for all chart types.
Initialize a bubble chart.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
Config
|
Configuration overrides. Defaults to |
None
|
excel_helper
|
ExcelHelper
|
Helper instance. Created from config when not provided. |
None
|
Source code in sql2excel/chart.py
1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 | |
Chart(config=None, excel_helper=None)
Base class for all charts in SQL2Excel.
This class provides the methods and attributes for creating, configuring, and rendering charts in Excel workbooks using pandas DataFrames and openpyxl.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
Config
|
|
None
|
excel_helper
|
ExcelHelper
|
|
None
|
Notes
- If Excel-related code fails, a user warning is issued and a default value is used instead of raising an exception. This design choice is to prevent interrupting SQL queries on the failure of Excel-related code.
- Subclasses should override
plotandadd_imageto implement specific charting and image insertion logic.
Initialize the chart with optional configuration and helper.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
Config
|
Configuration overrides. Defaults to |
None
|
excel_helper
|
ExcelHelper
|
Helper object for Excel-specific operations. |
None
|
Source code in sql2excel/chart.py
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 | |
add_image(image_path, ws, df=None, **kwargs)
Adds an image to the given worksheet.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image_path
|
str
|
The file path to the image to be inserted. |
required |
ws
|
object
|
The worksheet object where the image will be added. |
required |
df
|
DataFrame
|
DataFrame that may be written alongside the image (default is None). |
None
|
**kwargs
|
Additional keyword arguments for image customization, such as position, size, or formatting. |
{}
|
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
If the method is not implemented in the subclass. |
Notes
This method should be implemented by subclasses.
Source code in sql2excel/chart.py
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 | |
plot(df, ws, **kwargs)
Plots data from a DataFrame onto a worksheet.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
The DataFrame containing the data to plot. |
required |
ws
|
object
|
The worksheet object where the plot will be rendered. |
required |
**kwargs
|
Additional keyword arguments for customizing the plot. |
{}
|
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
If the method is not implemented. |
Notes
This method should be implemented by subclasses.
Source code in sql2excel/chart.py
464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 | |
write_dataframe(df, ws, **kwargs)
Writes a pandas DataFrame to an Excel worksheet.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
The DataFrame to write to the worksheet. |
required |
ws
|
Worksheet
|
The openpyxl worksheet where the DataFrame will be written. |
required |
**kwargs
|
dict
|
Additional keyword arguments:
section_heading : str, optional
A heading to be written above the DataFrame in the worksheet.
headings : iterable of str, optional
Custom column headings to use instead of DataFrame's columns.
Any other keyword arguments required by |
{}
|
Notes
- The first column is always treated as the x-axis (categories).
- If
headingsis provided, DataFrame's column names are ignored.
Source code in sql2excel/chart.py
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 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 | |
write_dataframes_side_by_side(objs, ws, **kwargs)
Write multiple pandas DataFrames side by side into an Excel worksheet.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
objs
|
Sequence[DataFrame]
|
Sequence of pandas DataFrames to be written to the worksheet. |
required |
ws
|
Worksheet
|
The worksheet where the DataFrames will be written. |
required |
**kwargs
|
dict
|
Additional keyword arguments:
section_heading : str, optional
Title to add above the DataFrames section.
df_headings : list of str, optional
Custom headings for each DataFrame. The length should match the number of DataFrames in |
{}
|
See Also
write_dataframe : Method used to write individual DataFrames.
Notes
- DataFrames are written side by side, separated by a configurable number of columns.
- The method delegates the actual writing of each DataFrame to
write_dataframe.
Source code in sql2excel/chart.py
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 261 262 263 264 265 266 267 268 269 270 271 272 273 274 | |
Config
Default configuration constants for charts, formatting, and layout.
All attributes are class-level constants used throughout the package.
Override by passing a custom Config instance (or subclass) to
Report, Chart, or ExcelHelper.
ExcelHelper(config=None)
Initialize the helper with an optional configuration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
Config
|
Configuration overrides. Defaults to |
None
|
Source code in sql2excel/excel_helper.py
25 26 27 28 29 30 31 32 33 | |
fill(series, color=None, border_line_color=None)
Set solid fill and border line colour for a chart series.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
series
|
Series
|
The openpyxl chart series to modify. |
required |
color
|
str
|
Fill colour as an sRGB hex string. |
None
|
border_line_color
|
str
|
Border line colour as an sRGB hex string. Defaults to color when not provided. |
None
|
Returns:
| Type | Description |
|---|---|
None
|
|
Source code in sql2excel/excel_helper.py
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 | |
fill_data_point(series, series_length)
Assign a distinct colour to each data point in a single-series chart.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
series
|
Series
|
The openpyxl chart series to modify. |
required |
series_length
|
int
|
The number of data points (rows) in the series. |
required |
Source code in sql2excel/excel_helper.py
303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 | |
get_column_letter(col)
Normalize a column reference to an Excel column letter.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
col
|
str, int, or None
|
A column letter ( |
required |
Returns:
| Type | Description |
|---|---|
str
|
The corresponding column letter. Defaults to |
Warns:
| Type | Description |
|---|---|
UserWarning
|
If col is out of the valid range (1–16384). |
Source code in sql2excel/excel_helper.py
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 | |
get_row_start(ws)
Return the next available row index in ws, inserting separator rows when needed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ws
|
Worksheet
|
The worksheet to inspect. |
required |
Returns:
| Type | Description |
|---|---|
int
|
1-based row number where the next content should be written. |
Source code in sql2excel/excel_helper.py
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 | |
get_starting_position(ws, **kwargs)
Resolve the (row, column) start position for writing data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ws
|
Worksheet
|
The target worksheet. |
required |
**kwargs
|
dict
|
Optional overrides: row_start : int, optional
Explicit 1-based row number. Must be >= 1.
column_start : str, int, or None, optional
Column letter, 1-based integer, or |
{}
|
Returns:
| Type | Description |
|---|---|
tuple of (int, int)
|
(row_start, column_start) as 1-based indices. |
Warns:
| Type | Description |
|---|---|
UserWarning
|
If row_start is not a positive integer. |
Source code in sql2excel/excel_helper.py
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 | |
insert_rows_for_chart_height(height, ws, df=None, scale=None)
Add empty rows to account for chart or image height.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
height
|
int or float
|
The chart/image height (in openpyxl units). |
required |
ws
|
Worksheet
|
The worksheet to append rows to. |
required |
df
|
DataFrame
|
If provided, its row count is subtracted from the total rows needed. |
None
|
scale
|
float
|
Multiplier applied to height. Defaults to
|
None
|
Source code in sql2excel/excel_helper.py
163 164 165 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 | |
is_sheet_empty(ws)
Check whether a worksheet contains any data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ws
|
Worksheet
|
The worksheet to inspect. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
|
Source code in sql2excel/excel_helper.py
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | |
reference_column_exists(df)
Check whether the last column of df contains a single unique value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
The DataFrame to inspect. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
|
Source code in sql2excel/excel_helper.py
328 329 330 331 332 333 334 335 336 337 338 339 340 341 | |
rotate_xticks(chart, rotation)
Rotate the x-axis tick labels.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
chart
|
Chart
|
The chart to modify. |
required |
rotation
|
int or float
|
Rotation in degrees (will be multiplied by 60 000 internally
for the openpyxl |
required |
Warns:
| Type | Description |
|---|---|
UserWarning
|
If the rotation cannot be applied. |
Source code in sql2excel/excel_helper.py
507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 | |
set_axis_limit(axis, limit)
Set the minimum and maximum values for an axis.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
axis
|
Axis
|
The axis to configure. |
required |
limit
|
tuple of (int or float, int or float)
|
A (min, max) pair. If min >= max, a warning is issued and the limits are still applied. |
required |
Warns:
| Type | Description |
|---|---|
UserWarning
|
If min >= max. |
Source code in sql2excel/excel_helper.py
548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 | |
set_chart_axis_label_font(chart_, axis, **kwargs)
Apply font styling to an axis title.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
chart_
|
Chart
|
The chart whose axis title is styled. |
required |
axis
|
str
|
|
required |
**kwargs
|
dict
|
Optional overrides: |
{}
|
Source code in sql2excel/excel_helper.py
462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 | |
set_chart_title_font(chart_, **kwargs)
Apply font styling to the chart title.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
chart_
|
Chart
|
The chart whose title is styled. Named chart_ (with
underscore) to avoid collision with the |
required |
**kwargs
|
dict
|
Optional overrides: |
{}
|
Source code in sql2excel/excel_helper.py
417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 | |
set_df_title_font(cell, df_font_name=None, df_bold=None, df_font_size=None, df_font_color=None, **kwargs)
Apply DataFrame title font style to a cell.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cell
|
Cell
|
The target cell. |
required |
df_font_name
|
str
|
Font name. Defaults to |
None
|
df_bold
|
bool
|
Bold flag. Defaults to |
None
|
df_font_size
|
int
|
Font size. Defaults to |
None
|
df_font_color
|
str
|
Font colour hex. Defaults to |
None
|
Source code in sql2excel/excel_helper.py
379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 | |
set_line_graphical_properties(series, width=None, style=None, color=None, smooth=None, nofill=False)
Set graphic properties for a chart series line.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
series
|
Series
|
The openpyxl chart series to modify. |
required |
width
|
float
|
Line width in points (converted to EMU internally). |
None
|
style
|
str
|
Dash style name, e.g. |
None
|
color
|
str
|
Line colour as an sRGB hex string. |
None
|
smooth
|
bool
|
Whether to smooth the line. Ignored for radar charts. |
None
|
nofill
|
bool
|
If |
False
|
Source code in sql2excel/excel_helper.py
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 | |
set_marker_graphical_properties(series, symbol=None, size=None, color=None)
Set marker graphic properties for a chart series.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
series
|
Series
|
The openpyxl chart series to modify. |
required |
symbol
|
str
|
Marker shape, e.g. |
None
|
size
|
int
|
Marker size. Defaults to |
None
|
color
|
str
|
Marker fill colour as an sRGB hex string. |
None
|
Source code in sql2excel/excel_helper.py
238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 | |
set_section_heading_font(cell, sh_font_name=None, sh_bold=None, sh_font_size=None, sh_font_color=None, **kwargs)
Apply section heading font style to a cell.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cell
|
Cell
|
The target cell. |
required |
sh_font_name
|
str
|
Font name. Defaults to |
None
|
sh_bold
|
bool
|
Bold flag. Defaults to |
None
|
sh_font_size
|
int
|
Font size. Defaults to |
None
|
sh_font_color
|
str
|
Font colour hex. Defaults to |
None
|
Source code in sql2excel/excel_helper.py
343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 | |
ImageChart(config=None, excel_helper=None)
Bases: Chart
Chart class for embedding images or matplotlib figures into Excel.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
Config
|
|
None
|
excel_helper
|
ExcelHelper
|
|
None
|
See Also
Chart : Base class for all chart types.
Initialize an image chart.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
Config
|
Configuration overrides. Defaults to |
None
|
excel_helper
|
ExcelHelper
|
Helper instance. Created from config when not provided. |
None
|
Source code in sql2excel/chart.py
837 838 839 840 841 842 843 844 845 846 847 | |
add_image(image_input, ws, df=None, **kwargs)
Add an image or matplotlib figure to the worksheet.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image_input
|
str or Figure
|
A file path (str) or a matplotlib |
required |
ws
|
Worksheet
|
The target worksheet. |
required |
df
|
DataFrame
|
If provided, the DataFrame is written before the image is placed. |
None
|
**kwargs
|
dict
|
Optional overrides: |
{}
|
Source code in sql2excel/chart.py
849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 | |
LineBasedChart(config=None, excel_helper=None)
Bases: Chart
Base class for line-based charts (e.g., line and radar).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
Config
|
|
None
|
excel_helper
|
ExcelHelper
|
|
None
|
See Also
Chart : Base class for all chart types.
Notes
Reference series are always formatted according to configuration.
Initialize a line-based chart.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
Config
|
Configuration overrides. Defaults to |
None
|
excel_helper
|
ExcelHelper
|
Helper instance. Created from config when not provided. |
None
|
Source code in sql2excel/chart.py
728 729 730 731 732 733 734 735 736 737 738 | |
LineChart(config=None, excel_helper=None)
Bases: LineBasedChart
Line chart.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
Config
|
|
None
|
excel_helper
|
ExcelHelper
|
|
None
|
See Also
Chart : Base class for all chart types.
Initialize a line chart.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
Config
|
Configuration overrides. Defaults to |
None
|
excel_helper
|
ExcelHelper
|
Helper instance. Created from config when not provided. |
None
|
Source code in sql2excel/chart.py
1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 | |
plot(df, ws, **kwargs)
Plot a line chart from df into ws.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
Data to plot; first column is the category axis. |
required |
ws
|
Worksheet
|
The target worksheet. |
required |
**kwargs
|
dict
|
Chart customization options (see |
{}
|
Source code in sql2excel/chart.py
1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 | |
PieChart(config=None, excel_helper=None)
Bases: Chart
Pie chart with data-label customization.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
Config
|
|
None
|
excel_helper
|
ExcelHelper
|
|
None
|
See Also
Chart : Base class for all chart types.
Initialize a pie chart.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
Config
|
Configuration overrides. Defaults to |
None
|
excel_helper
|
ExcelHelper
|
Helper instance. Created from config when not provided. |
None
|
Source code in sql2excel/chart.py
1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 | |
QueryConfig(sql=None, sql_params=None, from_sql_script=False, **xl_params)
Initialize the object with SQL query, parameters, and additional Excel parameters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sql
|
str
|
The SQL query to execute. |
None
|
sql_params
|
dict or Sequence
|
Parameters to be passed to the SQL query. |
None
|
from_sql_script
|
bool
|
Whether this query config was read from a SQL script.
Default is |
False
|
**xl_params
|
dict
|
Additional parameters for configuring the Excel chart. The keys can include:
|
{}
|
Source code in sql2excel/sqlexec.py
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 | |
RadarChart(config=None, excel_helper=None)
Bases: LineBasedChart
Radar (spider) chart.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
Config
|
|
None
|
excel_helper
|
ExcelHelper
|
|
None
|
See Also
Chart : Base class for all chart types.
Initialize a radar chart.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
Config
|
Configuration overrides. Defaults to |
None
|
excel_helper
|
ExcelHelper
|
Helper instance. Created from config when not provided. |
None
|
Source code in sql2excel/chart.py
965 966 967 968 969 970 971 972 973 974 975 | |
plot(df, ws, **kwargs)
Plot a radar chart from df into ws.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
Data to plot; first column is the category axis. |
required |
ws
|
Worksheet
|
The target worksheet. |
required |
**kwargs
|
dict
|
Chart customization options (see |
{}
|
Source code in sql2excel/chart.py
977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 | |
Report(conn=None, session=None, engine=None, db_url=None, config=None, silent=False)
Initialize the Report orchestrator.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
conn
|
Connection
|
An existing database connection. |
None
|
session
|
Session
|
An existing SQLAlchemy session. |
None
|
engine
|
Engine
|
An existing SQLAlchemy engine. |
None
|
db_url
|
str
|
A SQLAlchemy database URL used to create a new engine and connection. |
None
|
config
|
Config
|
Configuration overrides. Defaults to |
None
|
silent
|
bool
|
If |
False
|
Source code in sql2excel/report.py
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 | |
close()
Close all open database resources held by the executor.
Source code in sql2excel/report.py
169 170 171 | |
generate(query_config, **kwarg)
Execute queries, render results and charts, and save to an Excel file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query_config
|
QueryConfig or Sequence[QueryConfig]
|
One or more |
required |
**kwarg
|
dict
|
Optional keyword arguments: file_name : str, optional
Output file name. Default is |
{}
|
Source code in sql2excel/report.py
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 164 165 166 167 | |
SQLExecutor(conn=None, session=None, engine=None, db_url=None, silent=False)
Initialize the SQLExecutor with a database connection.
Exactly one of conn, session, engine, or db_url must be provided.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
conn
|
Connection
|
An existing database connection. |
None
|
session
|
Session
|
An existing SQLAlchemy session. |
None
|
engine
|
Engine
|
An existing SQLAlchemy engine; a connection will be created from it. |
None
|
db_url
|
str
|
A SQLAlchemy database URL used to create a new engine and connection. |
None
|
silent
|
bool
|
If |
False
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If none of conn, session, engine, or db_url is provided. |
Source code in sql2excel/sqlexec.py
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 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 | |
close()
Close all open database resources.
Disposes of the connection, session, and engine (whichever are set) and marks the executor as closed.
Source code in sql2excel/sqlexec.py
270 271 272 273 274 275 276 277 278 279 280 281 282 | |
execute(query_config)
Execute the SQL query defined in the QueryConfig object and return a DataFrame.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query_config
|
QueryConfig
|
An instance of QueryConfig containing the SQL query and parameters. |
required |
Returns:
| Type | Description |
|---|---|
DataFrame or None
|
A DataFrame with the query results, or |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Exception
|
Re-raises any database exception when silent is |
Source code in sql2excel/sqlexec.py
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 | |
executeall(query_configs)
Execute a sequence of QueryConfig objects and collect the results.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query_configs
|
Sequence[QueryConfig]
|
A sequence of QueryConfig objects to execute. |
required |
Returns:
| Type | Description |
|---|---|
list of pandas.DataFrame or None
|
One result per query, in the same order. |
Source code in sql2excel/sqlexec.py
252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 | |
ScatterChart(config=None, excel_helper=None)
Bases: Chart
Scatter plot with flexible data selection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
Config
|
|
None
|
excel_helper
|
ExcelHelper
|
|
None
|
See Also
Chart : Base class for all chart types.
Initialize a scatter chart.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
Config
|
Configuration overrides. Defaults to |
None
|
excel_helper
|
ExcelHelper
|
Helper instance. Created from config when not provided. |
None
|
Source code in sql2excel/chart.py
1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 | |
plot(df, ws, **kwargs)
Plot a scatter chart from df into ws.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
Data to plot; first column is the x-axis. |
required |
ws
|
Worksheet
|
The target worksheet. |
required |
**kwargs
|
dict
|
Chart customization options (see |
{}
|
Source code in sql2excel/chart.py
1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 | |
SingleAxisBarLineChart(config=None, excel_helper=None)
Bases: Chart
Combined bar and line chart on a single y-axis.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
Config
|
|
None
|
excel_helper
|
ExcelHelper
|
|
None
|
See Also
Chart : Base class for all chart types.
Initialize a single-axis bar-line chart.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
Config
|
Configuration overrides. Defaults to |
None
|
excel_helper
|
ExcelHelper
|
Helper instance. Created from config when not provided. |
None
|
Source code in sql2excel/chart.py
1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 | |
plot(df, ws, **kwargs)
Plot a single-axis bar-line chart from df into ws.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
Data to plot; first column is the category axis. |
required |
ws
|
Worksheet
|
The target worksheet. |
required |
**kwargs
|
dict
|
Chart customization options including |
{}
|
Source code in sql2excel/chart.py
1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 | |
StackedBarChart(config=None, excel_helper=None)
Bases: Chart
Stacked or percent-stacked bar chart.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
Config
|
|
None
|
excel_helper
|
ExcelHelper
|
|
None
|
See Also
Chart : Base class for all chart types.
Initialize a stacked bar chart.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
Config
|
Configuration overrides. Defaults to |
None
|
excel_helper
|
ExcelHelper
|
Helper instance. Created from config when not provided. |
None
|
Source code in sql2excel/chart.py
1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 | |
TwoAxesChart(config=None, excel_helper=None)
Bases: Chart
Base class for charts with two y-axes (primary and secondary).
The first data column is plotted on the primary y-axis; additional columns are plotted on the secondary y-axis.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
Config
|
|
None
|
excel_helper
|
ExcelHelper
|
|
None
|
Attributes:
| Name | Type | Description |
|---|---|---|
chart |
Chart or None
|
The main chart object (combined chart). |
chart1 |
Chart or None
|
The chart object for the primary y-axis. |
chart2 |
Chart or None
|
The chart object for the secondary y-axis. |
See Also
Chart : Base class for all chart types.
Initialize a two-axes chart.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
Config
|
Configuration overrides. Defaults to |
None
|
excel_helper
|
ExcelHelper
|
Helper instance. Created from config when not provided. |
None
|
Source code in sql2excel/chart.py
1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 | |
plot(df, ws, **kwargs)
Plot a two-axes chart from df into ws.
The first data column is plotted on the primary axis and the
remaining columns on the secondary axis. Subclasses should set
self.chart1 and self.chart2 before calling this method.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
Data to plot. |
required |
ws
|
Worksheet
|
The target worksheet. |
required |
**kwargs
|
dict
|
Chart customization options (see |
{}
|
Source code in sql2excel/chart.py
1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 | |
parse_sql_file(filepath)
Parse an annotated SQL file into a list of QueryConfig objects.
The file is split on semicolons into individual queries. Comment lines
(starting with --) are interpreted as directives that configure
chart type, title, section heading, and other Excel parameters.
Supported directives include chart, title, sheet_param,
query_param, and any other key=value pair consumed by
QueryConfig.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filepath
|
str
|
Path to the |
required |
Returns:
| Type | Description |
|---|---|
list of QueryConfig
|
One |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in sql2excel/parser.py
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 164 165 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 261 262 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 | |