---
name: Add Line By Type
slug: add-line-by-type
category: Automation
description: Adds code lines to files based on file type. Use for batch inserting lines, type-based additions, or automatic import handling.
github: "https://github.com/CoderWanFeng/python-office/tree/develop/skills/file/add_line_by_type"
language: Python
stars: 1331
forks: 297
install: "git clone https://github.com/CoderWanFeng/python-office"
added: 2026-07-20T06:48:42.268Z
last_synced: 2026-07-28T07:00:49.559Z
canonical_url: "https://dirskills.com/skills/add-line-by-type"
---

# Add Line By Type

Adds code lines to files based on file type. Use for batch inserting lines, type-based additions, or automatic import handling.

**Install:** `git clone https://github.com/CoderWanFeng/python-office`

## README

# add_line_by_type Skill

> 根据类型添加行

## 功能描述

根据文件类型，向指定文件中添加对应的代码行。

> ⚠️ TODO: 该功能为历史功能，行为待测试。

## 所属分类

`office/skills/file/add_line_by_type/`

## 调用方式

```python
from office.skills.file import add_line_by_type

add_line_by_type(
    add_line_dict={'import': 'import os'},
    file_path='./test.py',
    file_type='.py',
    output_path='add_line'
)
```

## 参数说明

| 参数 | 类型 | 必填 | 默认值 | 说明 |
|------|------|------|--------|------|
| `add_line_dict` | dict | 是 | - | 添加行的字典 |
| `file_path` | str | 是 | - | 文件路径 |
| `file_type` | str | 否 | `'.py'` | 文件类型 |
| `output_path` | str | 否 | `'add_line'` | 输出路径 |

## 返回值

`None`

## 原始函数

`office.api.file.add_line_by_type`
