{"id":7581,"library":"pylightxl","title":"pylightxl","description":"pylightxl is a lightweight, zero-dependency Python library designed for reading and writing Microsoft Excel files (.xlsx, .xlsm) and CSV files. It supports Python 2.7.18 and 3+, focusing on basic cell data manipulation without supporting complex features like formatting, graphs, or macros. The library is actively maintained, with its current version being 1.61, and releases occur regularly to address bugs and add features.","status":"active","version":"1.61","language":"en","source_language":"en","source_url":"https://github.com/PydPiper/pylightxl","tags":["excel","xlsx","xlsm","csv","spreadsheet","read","write","zero-dependency"],"install":[{"cmd":"pip install pylightxl","lang":"bash","label":"Install latest version"}],"dependencies":[],"imports":[{"symbol":"pylightxl","correct":"import pylightxl as xl"}],"quickstart":{"code":"import pylightxl as xl\nimport os\n\n# Create a dummy Excel file for reading example\ndb_write = xl.Database()\ndb_write.add_ws(ws='Sheet1')\ndb_write.ws(ws='Sheet1').update_index(row=1, col=1, val='Header 1')\ndb_write.ws(ws='Sheet1').update_index(row=1, col=2, val='Header 2')\ndb_write.ws(ws='Sheet1').update_index(row=2, col=1, val=100)\ndb_write.ws(ws='Sheet1').update_index(row=2, col=2, val='=A2*2')\n\noutput_file = 'example_output.xlsx'\nxl.writexl(db_write, output_file)\nprint(f\"Created '{output_file}' for reading example.\")\n\n# Read from the Excel file\nif os.path.exists(output_file):\n    db_read = xl.readxl(fn=output_file)\n    print(f\"\\nReading data from '{output_file}':\")\n    \n    # Access data by address\n    cell_a1_val = db_read.ws(ws='Sheet1').address(address='A1')\n    print(f\"Cell A1 (value): {cell_a1_val}\")\n    \n    # Access formula by index\n    cell_b2_formula = db_read.ws(ws='Sheet1').index(row=2, col=2, output='f')\n    print(f\"Cell B2 (formula): {cell_b2_formula}\")\n    \n    # Iterate through rows\n    print(\"\\nAll data in Sheet1:\")\n    for row in db_read.ws(ws='Sheet1').rows:\n        print(row)\nelse:\n    print(f\"Error: '{output_file}' not found.\")\n\n# Clean up the created file\nif os.path.exists(output_file):\n    os.remove(output_file)\n    print(f\"Cleaned up '{output_file}'.\")","lang":"python","description":"This quickstart demonstrates how to create a simple Excel file, write data including a formula, and then read data back from it using cell addresses, indices, and row iteration. It also shows how to access cell formulas."},"warnings":[{"fix":"Update your code to use `output='f'` for formulas, `output='v'` for values, or `output='c'` for comments instead of the `formula` boolean argument.","message":"The `formula` argument in indexing methods (e.g., `db.ws().index(..., formula=True)`) was deprecated in version 1.55. It has been replaced by the `output` argument (e.g., `output='f'`) for greater flexibility.","severity":"deprecated","affected_versions":">=1.55"},{"fix":"Be aware of this limitation and either ensure existing files do not contain complex features you wish to preserve, or back up files before writing.","message":"When writing to an existing Excel workbook using `xl.writexl()`, pylightxl currently only supports writing cell values/formulas/strings. Any existing macros, buttons, graphs, formatting, or other customizations in the original file will be removed.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Convert `.xls` files to a supported format like `.xlsx` or `.xlsm` before attempting to read them with pylightxl.","message":"pylightxl does not support reading or writing `.xls` files (Microsoft Excel 97-2003 format). It primarily supports `.xlsx` and `.xlsm` for reading, and `.xlsx` for writing.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Inform users that they need to open and save the Excel file to see calculated results for formulas. If immediate calculation is needed, consider pre-calculating values in Python or using a library that supports formula evaluation.","message":"Formulas written into an Excel file by pylightxl will not be calculated until the user opens the file in Excel. pylightxl itself does not perform formula calculations.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Double-check the exact spelling and case of the worksheet name. You can list available sheets using `db.ws_names`. If the file is an `.xls` file, convert it to `.xlsx` or `.xlsm` format first.","cause":"The specified worksheet name does not exist in the Excel file, or there is a typo in the sheet name. This can also occur if attempting to read an unsupported file format like `.xls` which pylightxl cannot parse.","error":"KeyError: 'Sheet1' (or any other sheet name)"},{"fix":"Ensure that `xl.readxl()` successfully returns a `pylightxl.Database` object by assigning its result to a variable (e.g., `db = xl.readxl(fn='your_file.xlsx')`) and verifying the file exists and is valid. The `fn` argument should be the file path string or a `Pathlib.Path` object.","cause":"This error typically occurs when `xl.readxl()` returns a file path string (perhaps due to an error during reading or incorrect usage) instead of a `pylightxl.Database` object, and a worksheet method like `.ws()` is then called on that string.","error":"AttributeError: 'str' object has no attribute 'ws'"},{"fix":"Update pylightxl to version 1.57 or newer. This issue was specifically addressed to improve support for non-standard sheet IDs. If the issue persists with the latest version, the Excel file might be corrupt or severely malformed.","cause":"In older versions of pylightxl (prior to v1.57), this could occur when parsing Excel files with non-standard sheet IDs or malformed XML tags, where the library attempts to convert a non-integer string into an integer.","error":"ValueError: invalid literal for int() with base 10: 'some_text'"}]}