Md To Office

作者 claude-office-skills9c4c7d5cd281MIT499 個星標收錄於 2026年10月8日更新於 2026年10月8日儲存庫8 個月前更新

>

僅含說明Documents & Office
AI 產生的概覽

使用 Pandoc 將 Markdown 檔案轉換為 Word、PowerPoint、PDF 等辦公格式。

功能
此技能提供使用 Pandoc 將 Markdown 轉換為 .docx、.pptx、.pdf、.html、.tex 與 .epub 等辦公格式的說明與指令範例。內容涵蓋參考範本、目錄、YAML 中介資料、投影片結構,以及 Python 或 pypandoc 封裝。也包含批次轉換與報告產生模式。
適用情境
當你已有 Markdown 內容,並需要產生 Word 文件、投影片、PDF 或類似辦公檔案時使用。適合將 README、筆記或結構化報告轉為可套用企業範本的成品檔案。
執行需求
需要安裝 Pandoc;產生 PDF 還需 LaTeX 或 wkhtmltopdf。Python 範例使用 subprocess,可選用 pypandoc。此技能不附帶指令碼,僅為說明文件。

Markdown to Office Skill

Overview

This skill enables conversion from Markdown to various Office formats using Pandoc - the universal document converter. Convert your Markdown files to professional Word documents, PowerPoint presentations, PDFs, and more while preserving formatting and structure.

How to Use

  1. Provide the Markdown content or file
  2. Specify the target format (docx, pptx, pdf, etc.)
  3. Optionally provide a reference template for styling
  4. I'll convert using Pandoc with optimal settings

Example prompts:

  • "Convert this README.md to a professional Word document"
  • "Turn my markdown notes into a PowerPoint presentation"
  • "Generate a PDF from this markdown with custom styling"
  • "Create a Word doc from this markdown using company template"

Domain Knowledge

Pandoc Fundamentals

bash
# Basic conversionpandoc input.md -o output.docxpandoc input.md -o output.pdfpandoc input.md -o output.pptx
# With templatepandoc input.md --reference-doc=template.docx -o output.docx
# Multiple inputspandoc ch1.md ch2.md ch3.md -o book.docx

Supported Conversions

FromToCommand
MarkdownWordpandoc in.md -o out.docx
MarkdownPDFpandoc in.md -o out.pdf
MarkdownPowerPointpandoc in.md -o out.pptx
MarkdownHTMLpandoc in.md -o out.html
MarkdownLaTeXpandoc in.md -o out.tex
MarkdownEPUBpandoc in.md -o out.epub

Markdown to Word (.docx)

Basic Conversion
bash
pandoc document.md -o document.docx
With Template (Reference Doc)
bash
# First create a template by converting samplepandoc sample.md -o reference.docx
# Edit reference.docx styles in Word, then use itpandoc input.md --reference-doc=reference.docx -o output.docx
With Table of Contents
bash
pandoc document.md --toc --toc-depth=3 -o document.docx
With Metadata
bash
pandoc document.md \  --metadata title="My Report" \  --metadata author="John Doe" \  --metadata date="2024-01-15" \  -o document.docx

Markdown to PDF

Via LaTeX (Best Quality)
bash
# Requires LaTeX installationpandoc document.md -o document.pdf
# With custom settingspandoc document.md \  --pdf-engine=xelatex \  -V geometry:margin=1in \  -V fontsize=12pt \  -o document.pdf
Via HTML/wkhtmltopdf
bash
pandoc document.md \  --pdf-engine=wkhtmltopdf \  --css=style.css \  -o document.pdf
PDF Options
bash
pandoc document.md \  -V papersize:a4 \  -V geometry:margin=2cm \  -V fontfamily:libertinus \  -V colorlinks:true \  --toc \  -o document.pdf

Markdown to PowerPoint (.pptx)

Basic Conversion
bash
pandoc slides.md -o presentation.pptx
Markdown Structure for Slides
markdown
---title: Presentation Titleauthor: Author Namedate: January 2024---
# Section Header (creates section divider)
## Slide Title
- Bullet point 1- Bullet point 2  - Sub-bullet
## Another Slide
Content here
::: notesSpeaker notes go here (not visible in slides):::
## Slide with Image
![Description](image.png){width=80%}
## Two Column Slide
:::::::::::::: {.columns}::: {.column width="50%"}Left column content:::
::: {.column width="50%"}Right column content:::::::::::::::::
With Template
bash
# Use corporate PowerPoint templatepandoc slides.md --reference-doc=template.pptx -o presentation.pptx

YAML Frontmatter

Add metadata at the top of your Markdown:

yaml
---title: "Document Title"author: "Author Name"date: "2024-01-15"abstract: "Brief description"toc: truetoc-depth: 2numbersections: truegeometry: margin=1infontsize: 11ptdocumentclass: report---
# First Chapter...

Python Integration

python
import subprocessimport os
def md_to_docx(input_path, output_path, template=None):    """Convert Markdown to Word document."""    cmd = ['pandoc', input_path, '-o', output_path]        if template:        cmd.extend(['--reference-doc', template])        subprocess.run(cmd, check=True)    return output_path
def md_to_pdf(input_path, output_path, **options):    """Convert Markdown to PDF with options."""    cmd = ['pandoc', input_path, '-o', output_path]        if options.get('toc'):        cmd.append('--toc')        if options.get('margin'):        cmd.extend(['-V', f"geometry:margin={options['margin']}"])        subprocess.run(cmd, check=True)    return output_path
def md_to_pptx(input_path, output_path, template=None):    """Convert Markdown to PowerPoint."""    cmd = ['pandoc', input_path, '-o', output_path]        if template:        cmd.extend(['--reference-doc', template])        subprocess.run(cmd, check=True)    return output_path

pypandoc (Python Wrapper)

python
import pypandoc
# Simple conversionoutput = pypandoc.convert_file('input.md', 'docx', outputfile='output.docx')
# With optionsoutput = pypandoc.convert_file(    'input.md',     'docx',    outputfile='output.docx',    extra_args=['--toc', '--reference-doc=template.docx'])
# From stringmd_content = "# Hello\n\nThis is markdown."output = pypandoc.convert_text(md_content, 'docx', format='md', outputfile='output.docx')

Best Practices

  1. Use Templates: Create a reference document for consistent branding
  2. Structure Headers: Use consistent heading levels (## for slides, # for sections)
  3. Test Incrementally: Convert small sections first to verify formatting
  4. Include Metadata: Use YAML frontmatter for document properties
  5. Handle Images: Use relative paths and specify dimensions

Common Patterns

Batch Conversion

python
import subprocessfrom pathlib import Path
def batch_convert(input_dir, output_format, output_dir=None):    """Convert all markdown files in a directory."""    input_path = Path(input_dir)    output_path = Path(output_dir) if output_dir else input_path        for md_file in input_path.glob('*.md'):        output_file = output_path / md_file.with_suffix(f'.{output_format}').name        subprocess.run([            'pandoc', str(md_file), '-o', str(output_file)        ], check=True)        print(f"Converted: {md_file.name} -> {output_file.name}")
batch_convert('./docs', 'docx', './output')

Report Generator

python
def generate_report(title, sections, output_path, template=None):    """Generate Word report from structured data."""        # Build markdown    md_content = f"""---title: "{title}"date: "{datetime.now().strftime('%B %d, %Y')}"---
"""    for section_title, content in sections.items():        md_content += f"# {section_title}\n\n{content}\n\n"        # Write temp file    with open('temp_report.md', 'w') as f:        f.write(md_content)        # Convert    cmd = ['pandoc', 'temp_report.md', '-o', output_path, '--toc']    if template:        cmd.extend(['--reference-doc', template])        subprocess.run(cmd, check=True)    os.remove('temp_report.md')

Examples

Example 1: Technical Documentation

python
import subprocess
# Create comprehensive markdowndoc = """---title: "API Documentation"author: "Dev Team"date: "2024-01-15"toc: truetoc-depth: 2---
# Introduction
This document describes the REST API for our service.
## Authentication
All API requests require an API key in the header:

Authorization: Bearer YOUR_API_KEY


## Endpoints
### GET /users
Retrieve all users.
**Response:**
| Field | Type | Description ||-------|------|-------------|| id | integer | User ID || name | string | Full name || email | string | Email address |
### POST /users
Create a new user.
**Request Body:**
```json{  "name": "John Doe",  "email": "[email protected]"}

Error Codes

CodeMeaning
400Bad Request
401Unauthorized
404Not Found
500Server Error
"""

Save markdown

with open('api_docs.md', 'w') as f: f.write(doc)

Convert to Word

subprocess.run([ 'pandoc', 'api_docs.md', '-o', 'api_documentation.docx', '--toc', '--reference-doc', 'company_template.docx' ], check=True)

Convert to PDF

subprocess.run([ 'pandoc', 'api_docs.md', '-o', 'api_documentation.pdf', '--toc', '-V', 'geometry:margin=1in', '-V', 'fontsize=11pt' ], check=True)


### Example 2: Presentation from Markdown```pythonslides_md = """---title: "Q4 Business Review"author: "Sales Team"date: "January 2024"---
# Overview
## Agenda
- Q4 Performance Summary- Regional Highlights- 2024 Outlook- Q&A
# Q4 Performance
## Key Metrics
- Revenue: $12.5M (+15% YoY)- New Customers: 250- Retention Rate: 94%
## Regional Performance
:::::::::::::: {.columns}::: {.column width="50%"}**North America**
- Revenue: $6.2M- Growth: +18%:::
::: {.column width="50%"}**Europe**
- Revenue: $4.1M- Growth: +12%:::::::::::::::::
# 2024 Outlook
## Strategic Priorities
1. Expand APAC presence2. Launch new product line3. Improve customer onboarding
## Revenue Targets
| Quarter | Target ||---------|--------|| Q1 | $13M || Q2 | $14M || Q3 | $15M || Q4 | $16M |
# Thank You
## Questions?
Contact: [email protected]"""
with open('presentation.md', 'w') as f:    f.write(slides_md)
subprocess.run([    'pandoc', 'presentation.md',    '-o', 'q4_review.pptx',    '--reference-doc', 'company_slides.pptx'], check=True)

Limitations

  • Complex Word formatting may not convert perfectly
  • PDF conversion requires LaTeX or wkhtmltopdf
  • PowerPoint animations not supported
  • Some advanced tables may need manual adjustment
  • Image positioning can be tricky

Installation

bash
# macOSbrew install pandoc
# Ubuntu/Debiansudo apt-get install pandoc
# Windowschoco install pandoc
# Python wrapperpip install pypandoc

Resources

來源與署名

來源:claude-office-skills/skills位於md-to-office提交9c4c7d5

授權條款: MIT

內容歸原作者所有。SourceWeft 從公開儲存庫中收錄這些內容。

檢舉或申請下架