[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M6KG4WXHDYVWVATGNCPM3AXK":3,"skill-same:01M6KG4WXHDYVWVATGNCPM3AXK":74},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":26,"publishedAt":41,"linkOnly":42,"markdownContent":43,"markdownBody":44,"frontMatter":45,"refName":46,"commitSha":47,"skillDirectory":48,"forksCount":14,"repositoryHtmlUrl":49,"repositoryHomepageUrl":6,"ownerHtmlUrl":50,"ownerBlogUrl":51,"ownerDescription":52,"updatedAt":53,"install":54,"resources":67},"01M6KG4WXHDYVWVATGNCPM3AXK","document-python-direct-exec",null,"Use direct Python execution for reliable spreadsheet and document\u002FPDF generation operations","xyliu-cs\u002FOpenSpace-GDPval","xyliu-cs","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F89236536?v=4","01M6KF8Z1V4TXS86CKSH48BY8T","xy","01M6KF8Z67443W0SHXM85JEF0B",0,"MIT","https:\u002F\u002Fgithub.com\u002Fxyliu-cs\u002FOpenSpace-GDPval\u002Fblob\u002Fmain\u002Fgdpval_bench\u002Fskills\u002Fspreadsheet-direct-python-merged-343937\u002FSKILL.md",[18,23],{"categoryNo":19,"categoryName":20,"taxonomyType":21,"taxonomyTypeDesc":22},"01JBSEEDCAT000000000000002","文档处理","SCENARIO","使用场景",{"categoryNo":24,"categoryName":25,"taxonomyType":21,"taxonomyTypeDesc":22},"01JBSEEDCAT000000000000004","电子表格",[27,28,29,30,31,32,33,34,35,36,37,38,39,40],"python","direct","document","exec","document python direct exec","document python direct","PDF","execution","spreadsheet","operations","use","generation","pdf generation","for","2026-11-10 10:12:30",false,"---\nname: document-python-direct-exec\ndescription: Use direct Python execution for reliable spreadsheet and document\u002FPDF generation operations\n---\n\n# Direct Python Execution for Spreadsheet and Document Tasks\n\n## When to Use This Skill\n\nUse direct `run_shell` with Python scripts for structured document operations when:\n\n- **Spreadsheets**: Reading or writing complex Excel files with multiple sheets, applying formulas, formatting, or data transformations\n- **PDFs**: Generating PDF checklists, reports, invoices, or forms with precise layout control\n- **Documents**: Creating Word documents, HTML reports, or other structured output formats\n- **Complex Operations**: The task involves multiple steps that could exceed agent step limits\n- **Precision Needed**: You need precise control over error handling, debugging, and library imports\n\n## Why Direct Execution?\n\nThe `shell_agent` tool can:\n\n- Hit maximum step limits on complex multi-step operations\n- Produce unexplained errors on formatting operations\n- Fail on intricate reads\u002Fwrites due to iterative parsing\n- Fail to parse heredoc syntax correctly, causing 'unknown error' failures\n\nDirect `run_shell` with Python is more reliable because it:\n\n- Executes in a single step with no iteration limits\n- Provides clearer, immediate error messages\n- Handles complex operations without step constraints\n- Gives full control over library imports and execution flow\n- Writing scripts to `.py` files first avoids shell_agent parsing issues with heredocs\n\n## How to Use\n\n### Recommended Pattern: Write Script to File First\n\nFor complex multi-line scripts, especially when using shell_agent as executor:\n\n```bash\n# Step 1: Write the Python script to a file\ncat > process_document.py \u003C\u003C 'EOF'\n# Your document\u002Fspreadsheet code here\nEOF\n\n# Step 2: Execute the script\npython3 process_document.py\n```\n\n### Alternative Pattern: Inline Heredoc (Simple Scripts Only)\n\nFor short, simple scripts when NOT using shell_agent as the executor:\n\n```bash\npython3 \u003C\u003C 'EOF'\n# Your code here\nEOF\n```\n\n## Spreadsheet Examples\n\n### Example 1: Read and Transform Excel Data\n\n```python\nimport pandas as pd\n\n# Load data from specific sheet\ndf = pd.read_excel('input.xlsx', sheet_name='Revenue')\n\n# Apply transformations\ndf['Net_Revenue'] = df['Gross_Revenue'] * (1 - df['Tax_Rate'])\n\n# Save results\ndf.to_excel('output.xlsx', index=False, sheet_name='Processed')\n```\n\n### Example 2: Multi-Sheet Operations with openpyxl\n\n```python\nfrom openpyxl import load_workbook\n\nwb = load_workbook('tour_data.xlsx')\n\n# Iterate through sheets\nfor sheet_name in wb.sheetnames:\n    ws = wb[sheet_name]\n    # Apply formatting or calculations\n    for row in ws.iter_rows(min_row=2, max_col=5):\n        # Process cells\n        pass\n\nwb.save('tour_data_processed.xlsx')\n```\n\n### Example 3: Complex Formatting Operations\n\n```python\nfrom openpyxl import load_workbook\nfrom openpyxl.styles import Font, PatternFill, Alignment\n\nwb = load_workbook('report.xlsx')\nws = wb.active\n\n# Apply header styling\nheader_fill = PatternFill(start_color='4472C4', fill_type='solid')\nheader_font = Font(bold=True, color='FFFFFF')\n\nfor cell in ws[1]:\n    cell.fill = header_fill\n    cell.font = header_font\n    cell.alignment = Alignment(horizontal='center')\n\nwb.save('report_formatted.xlsx')\n```\n\n## PDF Generation Examples\n\n### Example 4: Generate PDF Checklist with ReportLab\n\n```python\nfrom reportlab.lib.pagesizes import letter\nfrom reportlab.pdfgen import canvas\nfrom reportlab.lib.units import inch\n\ndef create_checklist(pdf_path, items):\n    c = canvas.Canvas(pdf_path, pagesize=letter)\n    width, height = letter\n    \n    # Title\n    c.setFont(\"Helvetica-Bold\", 16)\n    c.drawString(1*inch, height - 1*inch, \"Safety Checklist\")\n    \n    # Checklist items\n    c.setFont(\"Helvetica\", 12)\n    y_position = height - 1.5*inch\n    \n    for i, item in enumerate(items, 1):\n        checkbox_x = 1*inch\n        text_x = 1.3*inch\n        c.drawString(checkbox_x, y_position, \"☐\")  # Empty checkbox\n        c.drawString(text_x, y_position, f\"{i}. {item}\")\n        y_position -= 0.3*inch\n        \n        # New page if needed\n        if y_position \u003C 1*inch:\n            c.showPage()\n            y_position = height - 1*inch\n    \n    c.save()\n    print(f\"Created checklist: {pdf_path}\")\n\n# Usage\nitems = [\n    \"Verify equipment is powered off\",\n    \"Check safety gear is available\",\n    \"Inspect work area for hazards\",\n    \"Confirm emergency contacts are posted\"\n]\ncreate_checklist('safety_checklist.pdf', items)\n```\n\n### Example 5: Generate PDF Report with Tables\n\n```python\nfrom reportlab.lib import colors\nfrom reportlab.lib.pagesizes import letter\nfrom reportlab.platypus import SimpleDocTemplate, Table, TableStyle, Paragraph, Spacer\nfrom reportlab.lib.styles import getSampleStyleSheet, ParagraphStyle\nfrom reportlab.lib.units import inch\n\ndef create_report(pdf_path, title, data, column_headers):\n    doc = SimpleDocTemplate(pdf_path, pagesize=letter,\n                           rightMargin=0.75*inch, leftMargin=0.75*inch,\n                           topMargin=0.75*inch, bottomMargin=0.75*inch)\n    \n    elements = []\n    styles = getSampleStyleSheet()\n    \n    # Title\n    title_style = ParagraphStyle('CustomTitle', parent=styles['Heading1'],\n                                 fontSize=18, spaceAfter=30, alignment=1)\n    elements.append(Paragraph(title, title_style))\n    elements.append(Spacer(1, 0.25*inch))\n    \n    # Table\n    table_data = [column_headers] + data\n    table = Table(table_data, colWidths=[2*inch, 1.5*inch, 1.5*inch])\n    \n    # Table styling\n    table.setStyle(TableStyle([\n        ('BACKGROUND', (0, 0), (-1, 0), colors.HexColor('#4472C4')),\n        ('TEXTCOLOR', (0, 0), (-1, 0), colors.whitesmoke),\n        ('ALIGN', (0, 0), (-1, -1), 'CENTER'),\n        ('FONTNAME', (0, 0), (-1, 0), 'Helvetica-Bold'),\n        ('FONTSIZE', (0, 0), (-1, 0), 12),\n        ('BOTTOMPADDING', (0, 0), (-1, 0), 12),\n        ('ROWBACKGROUNDS', (0, 1), (-1, -1), [colors.white, colors.HexColor('#D6DCE4')]),\n        ('GRID', (0, 0), (-1, -1), 0.5, colors.grey),\n    ]))\n    \n    elements.append(table)\n    doc.build(elements)\n    print(f\"Created report: {pdf_path}\")\n\n# Usage\nheaders = ['Item', 'Quantity', 'Status']\ndata = [\n    ['Widget A', '150', 'Complete'],\n    ['Widget B', '200', 'In Progress'],\n    ['Widget C', '75', 'Pending']\n]\ncreate_report('status_report.pdf', 'Weekly Status Report', data, headers)\n```\n\n### Example 6: PDF with Images and Text (FPDF Alternative)\n\n```python\nfrom fpdf import FPDF\n\nclass PDF(FPDF):\n    def header(self):\n        self.set_font('Arial', 'B', 15)\n        self.cell(0, 10, 'Project Documentation', 0, 1, 'C')\n        self.ln(10)\n    \n    def footer(self):\n        self.set_y(-15)\n        self.set_font('Arial', 'I', 8)\n        self.cell(0, 10, f'Page {self.page_no()}', 0, 0, 'C')\n\ndef create_document(pdf_path, title, sections):\n    pdf = PDF()\n    pdf.add_page()\n    pdf.set_font('Arial', 'B', 16)\n    pdf.cell(0, 10, title, 0, 1, 'L')\n    pdf.ln(5)\n    \n    pdf.set_font('Arial', '', 12)\n    for section in sections:\n        pdf.set_font('Arial', 'B', 14)\n        pdf.cell(0, 10, section['title'], 0, 1)\n        pdf.set_font('Arial', '', 12)\n        pdf.multi_cell(0, 6, section['content'])\n        pdf.ln(5)\n    \n    pdf.output(pdf_path)\n    print(f\"Created document: {pdf_path}\")\n\n# Usage\nsections = [\n    {'title': 'Overview', 'content': 'This document provides...'},\n    {'title': 'Requirements', 'content': 'The following requirements...'},\n    {'title': 'Timeline', 'content': 'Project phases are...'}\n]\ncreate_document('project_doc.pdf', 'Project Alpha', sections)\n```\n\n## Error Handling Pattern\n\n```python\nimport sys\nfrom reportlab.lib.pagesizes import letter\nfrom reportlab.pdfgen import canvas\n\ntry:\n    c = canvas.Canvas('output.pdf', pagesize=letter)\n    \n    # Your document operations here\n    c.drawString(100, 750, \"Document content\")\n    \n    c.save()\n    print(\"Success: PDF created\")\n    \nexcept Exception as e:\n    print(f\"Error: {str(e)}\", file=sys.stderr)\n    sys.exit(1)\n```\n\n## Best Practices\n\n1. **Prefer file-based execution** for complex scripts: write to `.py` file first, then execute via `run_shell`\n2. **Import only needed libraries** to reduce execution time and avoid dependency conflicts\n3. **Print clear success\u002Ferror messages** for debugging\n4. **Save intermediate results** for complex multi-step transformations\n5. **Test with small data** before scaling to large documents or spreadsheets\n6. **Use appropriate libraries for the task**: pandas\u002Fopenpyxl for spreadsheets, reportlab\u002Ffpdf for PDFs\n7. **Clean up temporary script files** after execution if they won't be reused\n8. **Use absolute paths or verify working directory** to avoid file not found errors\n9. **For PDFs**: Build content in memory first, then write to file atomically\n\n## When NOT to Use This Skill\n\n- Simple single-cell reads\u002Fwrites (use shell_agent or basic commands)\n- Operations that require interactive user input\n- Tasks where you need the agent to iteratively refine the approach\n- When the target format has a simpler CLI tool available (e.g., `pandoc` for document conversion)\n\n## Common Libraries\n\n| Library | Best For |\n|---------|----------|\n| `openpyxl` | Reading\u002Fwriting .xlsx files, formatting, formulas |\n| `pandas` | Data manipulation, analysis, merging datasets |\n| `xlrd` | Reading older .xls files (read-only) |\n| `xlsxwriter` | Creating new .xlsx files with advanced formatting |\n| `reportlab` | Professional PDF generation with precise layout control |\n| `fpdf` | Simple PDF creation, easier learning curve |\n| `python-docx` | Creating and editing Word documents |\n| `weasyprint` | HTML\u002FCSS to PDF conversion |\n\n## Troubleshooting\n\n**Issue**: Heredoc syntax fails with 'unknown error' when using shell_agent\n- **Solution**: Write the Python script to a `.py` file first, then execute it with `python3 script.py`. This pattern is significantly more reliable than inline heredoc execution when shell_agent is the executor.\n\n**Issue**: FileNotFoundError\n- **Solution**: Verify the file path is absolute or relative to the working directory. Use `os.getcwd()` to confirm current directory if needed.\n\n**Issue**: PermissionError\n- **Solution**: Ensure the file is not open in another application. On Linux\u002FMac, check file permissions with `ls -la`.\n\n**Issue**: ModuleNotFoundError\n- **Solution**: Install required libraries first: `pip install reportlab openpyxl pandas`. Some environments may need `pip3` instead.\n\n**Issue**: MemoryError on large files\n- **Solution**: Process data in chunks using pandas `chunksize` parameter. For PDFs, create multi-page documents instead of single massive pages.\n\n**Issue**: Formatting not applying (spreadsheets)\n- **Solution**: Ensure you're modifying cell styles before saving, and use `.copy()` for style objects to avoid reference issues.\n\n**Issue**: PDF text rendering incorrectly\n- **Solution**: Check font encoding. For special characters, use Unicode-compatible fonts or escape special characters. ReportLab supports UTF-8 with proper font configuration.\n\n**Issue**: PDF layout breaks across pages\n- **Solution**: Use ReportLab's flowable elements (Paragraph, Spacer) which handle page breaks automatically, or manually check y-position and call `showPage()` when needed.\n\n## Quick Reference: PDF vs Spreadsheet Choice\n\n| Need | Recommended Library |\n|------|---------------------|\n| Data analysis, calculations | `pandas` + Excel output |\n| Complex cell formatting | `openpyxl` |\n| Professional reports with tables | `reportlab` (PDF) |\n| Simple checklists, forms | `fpdf` or `reportlab` |\n| Word document output | `python-docx` |\n| HTML to PDF | `weasyprint` |\n| Both data + formatted output | Generate data with pandas, format with reportlab |\n","# Direct Python Execution for Spreadsheet and Document Tasks\n\n## When to Use This Skill\n\nUse direct `run_shell` with Python scripts for structured document operations when:\n\n- **Spreadsheets**: Reading or writing complex Excel files with multiple sheets, applying formulas, formatting, or data transformations\n- **PDFs**: Generating PDF checklists, reports, invoices, or forms with precise layout control\n- **Documents**: Creating Word documents, HTML reports, or other structured output formats\n- **Complex Operations**: The task involves multiple steps that could exceed agent step limits\n- **Precision Needed**: You need precise control over error handling, debugging, and library imports\n\n## Why Direct Execution?\n\nThe `shell_agent` tool can:\n\n- Hit maximum step limits on complex multi-step operations\n- Produce unexplained errors on formatting operations\n- Fail on intricate reads\u002Fwrites due to iterative parsing\n- Fail to parse heredoc syntax correctly, causing 'unknown error' failures\n\nDirect `run_shell` with Python is more reliable because it:\n\n- Executes in a single step with no iteration limits\n- Provides clearer, immediate error messages\n- Handles complex operations without step constraints\n- Gives full control over library imports and execution flow\n- Writing scripts to `.py` files first avoids shell_agent parsing issues with heredocs\n\n## How to Use\n\n### Recommended Pattern: Write Script to File First\n\nFor complex multi-line scripts, especially when using shell_agent as executor:\n\n```bash\n# Step 1: Write the Python script to a file\ncat > process_document.py \u003C\u003C 'EOF'\n# Your document\u002Fspreadsheet code here\nEOF\n\n# Step 2: Execute the script\npython3 process_document.py\n```\n\n### Alternative Pattern: Inline Heredoc (Simple Scripts Only)\n\nFor short, simple scripts when NOT using shell_agent as the executor:\n\n```bash\npython3 \u003C\u003C 'EOF'\n# Your code here\nEOF\n```\n\n## Spreadsheet Examples\n\n### Example 1: Read and Transform Excel Data\n\n```python\nimport pandas as pd\n\n# Load data from specific sheet\ndf = pd.read_excel('input.xlsx', sheet_name='Revenue')\n\n# Apply transformations\ndf['Net_Revenue'] = df['Gross_Revenue'] * (1 - df['Tax_Rate'])\n\n# Save results\ndf.to_excel('output.xlsx', index=False, sheet_name='Processed')\n```\n\n### Example 2: Multi-Sheet Operations with openpyxl\n\n```python\nfrom openpyxl import load_workbook\n\nwb = load_workbook('tour_data.xlsx')\n\n# Iterate through sheets\nfor sheet_name in wb.sheetnames:\n    ws = wb[sheet_name]\n    # Apply formatting or calculations\n    for row in ws.iter_rows(min_row=2, max_col=5):\n        # Process cells\n        pass\n\nwb.save('tour_data_processed.xlsx')\n```\n\n### Example 3: Complex Formatting Operations\n\n```python\nfrom openpyxl import load_workbook\nfrom openpyxl.styles import Font, PatternFill, Alignment\n\nwb = load_workbook('report.xlsx')\nws = wb.active\n\n# Apply header styling\nheader_fill = PatternFill(start_color='4472C4', fill_type='solid')\nheader_font = Font(bold=True, color='FFFFFF')\n\nfor cell in ws[1]:\n    cell.fill = header_fill\n    cell.font = header_font\n    cell.alignment = Alignment(horizontal='center')\n\nwb.save('report_formatted.xlsx')\n```\n\n## PDF Generation Examples\n\n### Example 4: Generate PDF Checklist with ReportLab\n\n```python\nfrom reportlab.lib.pagesizes import letter\nfrom reportlab.pdfgen import canvas\nfrom reportlab.lib.units import inch\n\ndef create_checklist(pdf_path, items):\n    c = canvas.Canvas(pdf_path, pagesize=letter)\n    width, height = letter\n    \n    # Title\n    c.setFont(\"Helvetica-Bold\", 16)\n    c.drawString(1*inch, height - 1*inch, \"Safety Checklist\")\n    \n    # Checklist items\n    c.setFont(\"Helvetica\", 12)\n    y_position = height - 1.5*inch\n    \n    for i, item in enumerate(items, 1):\n        checkbox_x = 1*inch\n        text_x = 1.3*inch\n        c.drawString(checkbox_x, y_position, \"☐\")  # Empty checkbox\n        c.drawString(text_x, y_position, f\"{i}. {item}\")\n        y_position -= 0.3*inch\n        \n        # New page if needed\n        if y_position \u003C 1*inch:\n            c.showPage()\n            y_position = height - 1*inch\n    \n    c.save()\n    print(f\"Created checklist: {pdf_path}\")\n\n# Usage\nitems = [\n    \"Verify equipment is powered off\",\n    \"Check safety gear is available\",\n    \"Inspect work area for hazards\",\n    \"Confirm emergency contacts are posted\"\n]\ncreate_checklist('safety_checklist.pdf', items)\n```\n\n### Example 5: Generate PDF Report with Tables\n\n```python\nfrom reportlab.lib import colors\nfrom reportlab.lib.pagesizes import letter\nfrom reportlab.platypus import SimpleDocTemplate, Table, TableStyle, Paragraph, Spacer\nfrom reportlab.lib.styles import getSampleStyleSheet, ParagraphStyle\nfrom reportlab.lib.units import inch\n\ndef create_report(pdf_path, title, data, column_headers):\n    doc = SimpleDocTemplate(pdf_path, pagesize=letter,\n                           rightMargin=0.75*inch, leftMargin=0.75*inch,\n                           topMargin=0.75*inch, bottomMargin=0.75*inch)\n    \n    elements = []\n    styles = getSampleStyleSheet()\n    \n    # Title\n    title_style = ParagraphStyle('CustomTitle', parent=styles['Heading1'],\n                                 fontSize=18, spaceAfter=30, alignment=1)\n    elements.append(Paragraph(title, title_style))\n    elements.append(Spacer(1, 0.25*inch))\n    \n    # Table\n    table_data = [column_headers] + data\n    table = Table(table_data, colWidths=[2*inch, 1.5*inch, 1.5*inch])\n    \n    # Table styling\n    table.setStyle(TableStyle([\n        ('BACKGROUND', (0, 0), (-1, 0), colors.HexColor('#4472C4')),\n        ('TEXTCOLOR', (0, 0), (-1, 0), colors.whitesmoke),\n        ('ALIGN', (0, 0), (-1, -1), 'CENTER'),\n        ('FONTNAME', (0, 0), (-1, 0), 'Helvetica-Bold'),\n        ('FONTSIZE', (0, 0), (-1, 0), 12),\n        ('BOTTOMPADDING', (0, 0), (-1, 0), 12),\n        ('ROWBACKGROUNDS', (0, 1), (-1, -1), [colors.white, colors.HexColor('#D6DCE4')]),\n        ('GRID', (0, 0), (-1, -1), 0.5, colors.grey),\n    ]))\n    \n    elements.append(table)\n    doc.build(elements)\n    print(f\"Created report: {pdf_path}\")\n\n# Usage\nheaders = ['Item', 'Quantity', 'Status']\ndata = [\n    ['Widget A', '150', 'Complete'],\n    ['Widget B', '200', 'In Progress'],\n    ['Widget C', '75', 'Pending']\n]\ncreate_report('status_report.pdf', 'Weekly Status Report', data, headers)\n```\n\n### Example 6: PDF with Images and Text (FPDF Alternative)\n\n```python\nfrom fpdf import FPDF\n\nclass PDF(FPDF):\n    def header(self):\n        self.set_font('Arial', 'B', 15)\n        self.cell(0, 10, 'Project Documentation', 0, 1, 'C')\n        self.ln(10)\n    \n    def footer(self):\n        self.set_y(-15)\n        self.set_font('Arial', 'I', 8)\n        self.cell(0, 10, f'Page {self.page_no()}', 0, 0, 'C')\n\ndef create_document(pdf_path, title, sections):\n    pdf = PDF()\n    pdf.add_page()\n    pdf.set_font('Arial', 'B', 16)\n    pdf.cell(0, 10, title, 0, 1, 'L')\n    pdf.ln(5)\n    \n    pdf.set_font('Arial', '', 12)\n    for section in sections:\n        pdf.set_font('Arial', 'B', 14)\n        pdf.cell(0, 10, section['title'], 0, 1)\n        pdf.set_font('Arial', '', 12)\n        pdf.multi_cell(0, 6, section['content'])\n        pdf.ln(5)\n    \n    pdf.output(pdf_path)\n    print(f\"Created document: {pdf_path}\")\n\n# Usage\nsections = [\n    {'title': 'Overview', 'content': 'This document provides...'},\n    {'title': 'Requirements', 'content': 'The following requirements...'},\n    {'title': 'Timeline', 'content': 'Project phases are...'}\n]\ncreate_document('project_doc.pdf', 'Project Alpha', sections)\n```\n\n## Error Handling Pattern\n\n```python\nimport sys\nfrom reportlab.lib.pagesizes import letter\nfrom reportlab.pdfgen import canvas\n\ntry:\n    c = canvas.Canvas('output.pdf', pagesize=letter)\n    \n    # Your document operations here\n    c.drawString(100, 750, \"Document content\")\n    \n    c.save()\n    print(\"Success: PDF created\")\n    \nexcept Exception as e:\n    print(f\"Error: {str(e)}\", file=sys.stderr)\n    sys.exit(1)\n```\n\n## Best Practices\n\n1. **Prefer file-based execution** for complex scripts: write to `.py` file first, then execute via `run_shell`\n2. **Import only needed libraries** to reduce execution time and avoid dependency conflicts\n3. **Print clear success\u002Ferror messages** for debugging\n4. **Save intermediate results** for complex multi-step transformations\n5. **Test with small data** before scaling to large documents or spreadsheets\n6. **Use appropriate libraries for the task**: pandas\u002Fopenpyxl for spreadsheets, reportlab\u002Ffpdf for PDFs\n7. **Clean up temporary script files** after execution if they won't be reused\n8. **Use absolute paths or verify working directory** to avoid file not found errors\n9. **For PDFs**: Build content in memory first, then write to file atomically\n\n## When NOT to Use This Skill\n\n- Simple single-cell reads\u002Fwrites (use shell_agent or basic commands)\n- Operations that require interactive user input\n- Tasks where you need the agent to iteratively refine the approach\n- When the target format has a simpler CLI tool available (e.g., `pandoc` for document conversion)\n\n## Common Libraries\n\n| Library | Best For |\n|---------|----------|\n| `openpyxl` | Reading\u002Fwriting .xlsx files, formatting, formulas |\n| `pandas` | Data manipulation, analysis, merging datasets |\n| `xlrd` | Reading older .xls files (read-only) |\n| `xlsxwriter` | Creating new .xlsx files with advanced formatting |\n| `reportlab` | Professional PDF generation with precise layout control |\n| `fpdf` | Simple PDF creation, easier learning curve |\n| `python-docx` | Creating and editing Word documents |\n| `weasyprint` | HTML\u002FCSS to PDF conversion |\n\n## Troubleshooting\n\n**Issue**: Heredoc syntax fails with 'unknown error' when using shell_agent\n- **Solution**: Write the Python script to a `.py` file first, then execute it with `python3 script.py`. This pattern is significantly more reliable than inline heredoc execution when shell_agent is the executor.\n\n**Issue**: FileNotFoundError\n- **Solution**: Verify the file path is absolute or relative to the working directory. Use `os.getcwd()` to confirm current directory if needed.\n\n**Issue**: PermissionError\n- **Solution**: Ensure the file is not open in another application. On Linux\u002FMac, check file permissions with `ls -la`.\n\n**Issue**: ModuleNotFoundError\n- **Solution**: Install required libraries first: `pip install reportlab openpyxl pandas`. Some environments may need `pip3` instead.\n\n**Issue**: MemoryError on large files\n- **Solution**: Process data in chunks using pandas `chunksize` parameter. For PDFs, create multi-page documents instead of single massive pages.\n\n**Issue**: Formatting not applying (spreadsheets)\n- **Solution**: Ensure you're modifying cell styles before saving, and use `.copy()` for style objects to avoid reference issues.\n\n**Issue**: PDF text rendering incorrectly\n- **Solution**: Check font encoding. For special characters, use Unicode-compatible fonts or escape special characters. ReportLab supports UTF-8 with proper font configuration.\n\n**Issue**: PDF layout breaks across pages\n- **Solution**: Use ReportLab's flowable elements (Paragraph, Spacer) which handle page breaks automatically, or manually check y-position and call `showPage()` when needed.\n\n## Quick Reference: PDF vs Spreadsheet Choice\n\n| Need | Recommended Library |\n|------|---------------------|\n| Data analysis, calculations | `pandas` + Excel output |\n| Complex cell formatting | `openpyxl` |\n| Professional reports with tables | `reportlab` (PDF) |\n| Simple checklists, forms | `fpdf` or `reportlab` |\n| Word document output | `python-docx` |\n| HTML to PDF | `weasyprint` |\n| Both data + formatted output | Generate data with pandas, format with reportlab |\n",{"name":5,"description":7},"main","af1b40a42167d09c30b3a63000aa14ace4c1e229","gdpval_bench\u002Fskills\u002Fspreadsheet-direct-python-merged-343937","https:\u002F\u002Fgithub.com\u002Fxyliu-cs\u002FOpenSpace-GDPval","https:\u002F\u002Fgithub.com\u002Fxyliu-cs","https:\u002F\u002Fxyliu-cs.github.io","PhD Student in CS, CUHK-Shenzhen.","2026-04-06 20:32:15",{"source":8,"skillName":5,"commands":55,"prompt":65,"zipAvailable":66},[56,59,62],{"tool":57,"command":58},"npx","npx skills add xyliu-cs\u002FOpenSpace-GDPval --skill document-python-direct-exec",{"tool":60,"command":61},"bunx","bunx skills add xyliu-cs\u002FOpenSpace-GDPval --skill document-python-direct-exec",{"tool":63,"command":64},"pnpm","pnpm dlx skills add xyliu-cs\u002FOpenSpace-GDPval --skill document-python-direct-exec","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Fxyliu-cs\u002FOpenSpace-GDPval\u002Fblob\u002Fmain\u002Fgdpval_bench\u002Fskills\u002Fspreadsheet-direct-python-merged-343937\u002FSKILL.md",true,[68],{"path":69,"resourceType":70,"resourceTypeDesc":71,"sizeBytes":72,"sourceHtmlUrl":73},".skill_id","OTHER","其他",53,"https:\u002F\u002Fgithub.com\u002Fxyliu-cs\u002FOpenSpace-GDPval\u002Fblob\u002Fmain\u002Fgdpval_bench\u002Fskills\u002Fspreadsheet-direct-python-merged-343937\u002F.skill_id",[75,88,96,111,137,156],{"skillNo":76,"name":77,"nameZh":6,"description":78,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":79,"categories":80,"keywords":81,"publishedAt":41},"01M6KG8MF1S664SWBDENYRSCK8","zip-export-deliverable","Ensures codebase deliverables are properly exported as ZIP archives through a dedicated finalization step","https:\u002F\u002Fgithub.com\u002Fxyliu-cs\u002FOpenSpace-GDPval\u002Fblob\u002Fmain\u002Fgdpval_bench\u002Fskills\u002Fzip-export-deliverable\u002FSKILL.md",[],[82,83,84,85,86,87],"zip export deliverable","zip","export","deliverables","codebase","as",{"skillNo":89,"name":90,"nameZh":6,"description":91,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":92,"categories":93,"keywords":94,"publishedAt":41},"01M6KG8GAZWHHEK7VNJDW0ME21","zip-deliverable-finalization","Ensure codebase deliverables are properly packaged as ZIP exports in a dedicated final step","https:\u002F\u002Fgithub.com\u002Fxyliu-cs\u002FOpenSpace-GDPval\u002Fblob\u002Fmain\u002Fgdpval_bench\u002Fskills\u002Fzip-deliverable-finalization\u002FSKILL.md",[],[95,83,85,86,87],"zip deliverable finalization",{"skillNo":97,"name":98,"nameZh":6,"description":99,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":100,"categories":101,"keywords":102,"publishedAt":41},"01M6KG8CMQQ1PYMNTSRZ9VS1MD","zero-iteration-failure-analysis","Identify and handle agent failures with 0 iterations as pre-execution system issues","https:\u002F\u002Fgithub.com\u002Fxyliu-cs\u002FOpenSpace-GDPval\u002Fblob\u002Fmain\u002Fgdpval_bench\u002Fskills\u002Fzero-iteration-failure-analysis\u002FSKILL.md",[],[103,104,105,106,107,108,109,34,87,110],"failure analysis","ZeRO","analysis","iteration","zero iteration failure analysis","with","issues","system",{"skillNo":112,"name":113,"nameZh":6,"description":114,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":115,"categories":116,"keywords":122,"publishedAt":41},"01M6KG86W3PA07FT9W58YHHERM","write-file-fallback-report","Generate professional documents using write_file when primary data sources fail, leveraging embedded domain knowledge instead of external retrieval","https:\u002F\u002Fgithub.com\u002Fxyliu-cs\u002FOpenSpace-GDPval\u002Fblob\u002Fmain\u002Fgdpval_bench\u002Fskills\u002Fwrite-file-fallback-report\u002FSKILL.md",[117],{"categoryNo":118,"categoryName":119,"taxonomyType":120,"taxonomyTypeDesc":121},"01JBSEEDCAT000000000000034","行政与办公人员","PROFESSION","适用职业",[123,124,125,126,127,128,129,130,131,132,133,134,135,136],"fallback","write","file","report","write file fallback report","domain","professional","sources","retrieval","generate","embedded","documents","data","knowledge",{"skillNo":138,"name":139,"nameZh":6,"description":140,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":141,"categories":142,"keywords":146,"publishedAt":41},"01M6KG82GAEY3GG77CMGCK1C2T","fallback-doc-with-delegation","Generate professional documents after tool failures using shell_agent for complex formats or write_file for simple text\u002Fmarkdown","https:\u002F\u002Fgithub.com\u002Fxyliu-cs\u002FOpenSpace-GDPval\u002Fblob\u002Fmain\u002Fgdpval_bench\u002Fskills\u002Fwrite-file-fallback-report-enhanced\u002FSKILL.md",[143],{"categoryNo":144,"categoryName":145,"taxonomyType":21,"taxonomyTypeDesc":22},"01JBSEEDCAT000000000000023","Skill与智能体开发",[147,108,123,148,149,150,134,132,125,151,152,153,124,154,129,155,40],"fallback doc with delegation","doc","delegation","shell","markdown","tool","text","simple","formats",{"skillNo":157,"name":158,"nameZh":6,"description":159,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":160,"categories":161,"keywords":163,"publishedAt":41},"01M6KG7WT7GX5NYCGEFHW22NV7","context-anchored-fallback-report","Generate documents with write_file when retrieval tools fail, with explicit guardrails against task context drift","https:\u002F\u002Fgithub.com\u002Fxyliu-cs\u002FOpenSpace-GDPval\u002Fblob\u002Fmain\u002Fgdpval_bench\u002Fskills\u002Fwrite-file-fallback-report-enhanced-4bc5c2\u002FSKILL.md",[162],{"categoryNo":118,"categoryName":119,"taxonomyType":120,"taxonomyTypeDesc":121},[123,126,164,165,132,125,166,167,124,168,169,131,108,170,134],"context","context anchored fallback report","Guardrails","Tools","task","drift","context drift"]