{"id":4860,"library":"xlutils","title":"xlutils","description":"xlutils is a Python package offering various utilities for working with Excel files, specifically those compatible with `xlrd` and `xlwt`. It provides functionalities like copying `xlrd.Book` objects to `xlwt.Workbook` objects (xlutils.copy), displaying information, filtering, finding data margins, saving, and handling styles. The current version is 2.0.0. The library, along with its core dependencies `xlrd` and `xlwt`, is considered to be in maintenance mode or archived, with infrequent updates.","status":"maintenance","version":"2.0.0","language":"en","source_language":"en","source_url":"https://github.com/python-excel/xlutils","tags":["excel","xls","xlrd","xlwt","spreadsheet","utilities","legacy"],"install":[{"cmd":"pip install xlutils","lang":"bash","label":"Install stable version"}],"dependencies":[{"reason":"Required for reading Excel files. Version 0.6.1a1 or later.","package":"xlrd","optional":false},{"reason":"Required for writing Excel files. Version 0.7.0 or later.","package":"xlwt","optional":false},{"reason":"Required only if using xlutils.filter.ErrorFilter.","package":"errorhandler","optional":true}],"imports":[{"note":"The primary utility for copying xlrd.Book objects to xlwt.Workbook objects for modification.","symbol":"copy","correct":"from xlutils.copy import copy"},{"note":"Used in conjunction with `XLWTWriter` and `process` for advanced filtering and style preservation.","symbol":"XLRDReader","correct":"from xlutils.filter import process, XLRDReader, XLWTWriter"}],"quickstart":{"code":"import xlrd\nimport xlwt\nfrom xlutils.copy import copy\n\n# Create a dummy .xls file first for demonstration\nwb_initial = xlwt.Workbook()\nws_initial = wb_initial.add_sheet('Sheet1')\nws_initial.write(0, 0, 'Hello')\nws_initial.write(0, 1, 'World')\nws_initial.write(1, 0, 'Original Value')\nwb_initial.save('example_input.xls')\n\n# Open the existing workbook with xlrd\nrb = xlrd.open_workbook('example_input.xls', formatting_info=True)\n\n# Make a writable copy of the workbook using xlutils.copy\nwb = copy(rb)\n\n# Get the first sheet from the copied workbook\nws = wb.get_sheet(0)\n\n# Write a new value to a cell (e.g., cell B2)\nws.write(1, 1, 'Modified Value')\n\n# Save the modified workbook to a new .xls file\nwb.save('example_output.xls')\n\nprint(\"Modified workbook saved as 'example_output.xls'\")\n\n# Clean up dummy file (optional)\nimport os\nos.remove('example_input.xls')\nos.remove('example_output.xls')\n","lang":"python","description":"This quickstart demonstrates how to use `xlutils.copy` to open an existing Excel file (in `.xls` format), make modifications to a cell, and save the changes to a new file. It first creates a dummy `.xls` file to ensure the example is runnable. `formatting_info=True` is crucial for attempting to preserve styles during the copy operation."},"warnings":[{"fix":"Ensure input files are in `.xls` format. For `.xlsx` files, consider migrating to `openpyxl`.","message":"xlrd version 2.0.0 and later no longer supports `.xlsx` files due to security vulnerabilities related to parsing. Since `xlutils` relies on `xlrd` for reading, it is effectively limited to `.xls` files for input. Attempting to open an `.xlsx` file will result in an error.","severity":"breaking","affected_versions":"xlrd >= 2.0.0 (and thus xlutils using this version or later)"},{"fix":"For new projects, prefer `openpyxl`. For existing projects using `xlutils` and requiring `.xlsx` support, consider migrating.","message":"xlutils, xlrd, and xlwt are largely unmaintained or in archive status on GitHub. `xlrd` itself advises users to use `openpyxl` for modern Excel file formats (`.xlsx`). It is recommended to use `openpyxl` for new projects or when working with `.xlsx` files.","severity":"deprecated","affected_versions":"All versions"},{"fix":"For precise style preservation or modification, refer to `xlutils.filter` documentation or community solutions, often involving `XLRDReader` and `XLWTWriter`.","message":"Directly copying cell style information from an `xlrd.Book` object to an `xlwt.Workbook` object is complex. `xlrd` and `xlwt` use different internal representations for cell formatting (`XF` objects). While `xlutils.copy` attempts to preserve basic formatting, detailed style manipulation often requires using `xlutils.filter` with custom logic or a specific workaround.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Ensure column indices are within the valid range (0-255). If more columns are needed, consider using a library like `openpyxl` that supports newer `.xlsx` formats with larger sheet dimensions.","message":"When writing to an Excel sheet using `xlwt` (and by extension `xlutils.copy`), column indices are limited to a range of 0-255 (corresponding to columns A through IV in Excel 2003 `.xls` format). Attempting to write to a column index outside this range will raise a `ValueError`.","severity":"gotcha","affected_versions":"All versions (due to underlying xlwt limitations)"}],"env_vars":null,"last_verified":"2026-04-12T00:00:00.000Z","next_check":"2026-07-11T00:00:00.000Z"}