XLSX File Handling
The klyn.io.xlsx package reads and writes XLSX workbook files with worksheets,
cells, column widths, simple formats, and charts.
Format and Trademark Note
XLSX refers here to the Office Open XML spreadsheet package format. Product names such as Microsoft Excel are trademarks of their respective owners. Klyn's XLSX support targets the file format and does not imply endorsement, certification, or affiliation with those owners.
Imports
import klyn.io.xlsx
Create a Workbook
Open a workbook in create mode, add worksheets, write cells with A1-style references, and let
the try resource block save and close the file.
import klyn.io.xlsx
try workbook = Workbook("report.xlsx", WorkbookMode.CREATE | WorkbookMode.OVERWRITE):
sheet = workbook.addWorksheet("Data")
sheet.setColumn("A:A", 22)
sheet.setColumn("B:B", 14)
header = workbook.addFormat({
"bg_color": "gray",
"font_color": "white",
"bold": true
})
sheet.write("A1", "Name", header)
sheet.write("B1", "Score", header)
sheet.write("A2", "Ada")
sheet.write("B2", 42)
Read a Workbook
The default mode is WorkbookMode.READ. Access worksheets by name or index, then
read cell values from A1-style references.
import klyn.io.xlsx
try workbook = Workbook("report.xlsx"):
sheet = workbook.worksheet("Data")
print(sheet.read("A1"))
print(sheet.read("B2"))
Columns and Charts
Worksheet.writeColumn writes a vertical range from a starting cell. A workbook can
create a chart and insert it into a worksheet.
import klyn.io.xlsx
try workbook = Workbook("scores.xlsx", WorkbookMode.CREATE | WorkbookMode.OVERWRITE):
sheet = workbook.addWorksheet("Scores")
sheet.writeColumn("A1", [10, 40, 50, 20, 10, 50])
chart = workbook.addChart({"type": "line"})
chart.addSeries({"values": "=Scores!$A$1:$A$6"})
sheet.insertChart("C1", chart)
Runnable Sample
The distribution includes a complete XLSX export sample in samples/io. It writes a
workbook with a people directory, a monthly activity sheet, and a line chart built from the
second sheet.
klyn samples/io/ExportXLSX.kn
Practical Limits
The API is designed for deterministic exports and lightweight reads. Keep generated workbooks simple: explicit worksheets, explicit cells, predictable formatting, and typed values. For very large tabular exports, measure memory and startup cost before choosing XLSX over CSV.