本文へ移動
cccskills
無料GitHub で公開

reportlab-styles

Use reportlab's pre-defined styles from getSampleStyleSheet() correctly

インストール方法を見る

含まれるファイル(2)

  • SKILL.md3.0 KB
  • .skill_id30 B

SKILL.md(原文)

インストールする前に、エージェントに与えられる指示の中身を確認できます。

ReportLab Pre-Defined Styles Reference

Overview

ReportLab's reportlab.lib.styles.getSampleStyleSheet() provides a collection of pre-defined paragraph styles. Use these existing styles rather than redefining them to avoid KeyError exceptions.

Available Pre-Defined Styles

The standard stylesheet includes these commonly-used styles:

Style NamePurpose
NormalDefault body text
TitleDocument title (large, bold)
Heading1Level 1 section heading
Heading2Level 2 section heading
Heading3Level 3 section heading
Heading4Level 4 section heading
Heading5Level 5 section heading
Heading6Level 6 section heading
BulletBulleted list items
DefinitionDefinition list terms
ItalicItalicized text
CodeMonospace code text

Correct Usage Pattern

from reportlab.lib.styles import getSampleStyleSheet
from reportlab.platypus import Paragraph

# Get the stylesheet
styles = getSampleStyleSheet()

# Use existing styles directly (CORRECT)
title = Paragraph("My Document Title", styles['Title'])
heading = Paragraph("Section Header", styles['Heading1'])
body = Paragraph("Regular text content", styles['Normal'])

Common Mistake to Avoid

# WRONG - Don't redefine existing style names
from reportlab.lib.styles import getSampleStyleSheet, ParagraphStyle

styles = getSampleStyleSheet()

# This will cause KeyError when you try to use 'Title' later
styles.add(ParagraphStyle(
    name='Title',  # Overwrites the pre-defined 'Title' style
    fontSize=24,
    # ... incomplete definition
))

# Later code expecting the full 'Title' style will fail
paragraph = Paragraph("Title Text", styles['Title'])  # KeyError!

Best Practices

  1. Use existing styles as-is when they meet your needs
  2. Create new style names for custom styles (e.g., MyCustomTitle, CustomHeading)
  3. Base custom styles on existing ones when you need modifications:
from reportlab.lib.styles import getSampleStyleSheet, ParagraphStyle

styles = getSampleStyleSheet()

# Create a NEW style with a unique name
custom_title = ParagraphStyle(
    name='CustomTitle',  # Unique name, doesn't conflict
    parent=styles['Title'],  # Base it on existing Title
    fontSize=28,
    spaceAfter=30
)
styles.add(custom_title)

# Now both styles are available
styles['Title']       # Original pre-defined style
styles['CustomTitle'] # Your custom variant

Quick Reference Checklist

  • Import getSampleStyleSheet() from reportlab.lib.styles
  • Call styles = getSampleStyleSheet() once at the start
  • Access styles via styles['StyleName'] (case-sensitive)
  • Do NOT add styles with names that already exist in the stylesheet
  • Use unique names for any custom styles you create
  • Common available styles: Normal, Title, Heading1-6, Bullet, Code, Italic

レビュー

まだレビューはありません。使ってみた感想をお寄せください。

同じリポジトリのスキル

概要と使いどころ

Incremental audio production with duration mismatch handling, adaptive stem extension, and pre-mix alignment verification

日本語の概要は準備中です。原文の説明を表示しています。

HKUDS/OpenSpace7,7552026年8月13日 更新

Incremental audio production with duration alignment handling, per-stem verification, and adaptive extension strategies

日本語の概要は準備中です。原文の説明を表示しています。

HKUDS/OpenSpace7,7552026年8月13日 更新

Create serverless API proxy endpoints that hide API keys and provide a unified backend for the dashboard frontend. Designed for Vercel deployment.

日本語の概要は準備中です。原文の説明を表示しています。

HKUDS/OpenSpace7,7552026年8月13日 更新

End-to-end audio production workflow with stems, effects, archiving, and verification

日本語の概要は準備中です。原文の説明を表示しています。

HKUDS/OpenSpace7,7552026年8月13日 更新

Handle cascading data retrieval tool failures by falling back to embedded knowledge generation

日本語の概要は準備中です。原文の説明を表示しています。

HKUDS/OpenSpace7,7552026年8月13日 更新

Fallback pattern for executing Python code when execute_code_sandbox fails

日本語の概要は準備中です。原文の説明を表示しています。

HKUDS/OpenSpace7,7552026年8月13日 更新

HKUDS のスキルをすべて見る

このスキルの問題を報告する