본문으로 건너뛰기
cccskills
무료GitHub에 공개

large-file-conditional-formatting

Analyze a selected entity’s time series in Excel, calculate its average, and export a formatted report showing differences from that average. Rows below the average are highlighted in green for easy comparison.

한국어 요약은 준비 중입니다. 영어 요약을 표시하고 있습니다.

원문원문 설명 보기

根据Excel总行数自动切换Parquet加速读取,计算特定维度的时间序列平均值,并使用openpyxl输出带有条件格式(如低于均值标绿)和自定义样式的分析报告。

연동 도구Excel
설치 방법 보기

이럴 때 유용합니다

  • Highlight periods with values below the average
  • Report a selected entity’s time series
  • Check the total row count across Excel sheets
  • Create a formatted Excel analysis report

포함된 파일(1)

  • SKILL.md4.3 KB

SKILL.md(원문)

설치하기 전에 에이전트에게 전달되는 지시 내용을 확인할 수 있습니다.

Skill Steps

Note: This sub-skill covers one step of the Excel analysis workflow. For the full pipeline (file reading, row counting, large-file optimization, export), see the parent workflow SKILL.md.

Step1 读取文件并统计所有 sheet 的行数,汇总后打印总行数,用于判断是否需要大文件加速。

import pandas as pd
import openpyxl

file_path = "input_data.xlsx"

# 获取所有sheet名称
wb = openpyxl.load_workbook(file_path, read_only=True)
sheet_names = wb.sheetnames
print("Sheet列表:", sheet_names)
print("Sheet数量:", len(sheet_names))

# 统计每个sheet的行数
total_rows = 0
for name in sheet_names:
    df_temp = pd.read_excel(file_path, sheet_name=name, header=None)
    rows = len(df_temp)
    total_rows += rows
    print(f"Sheet '{name}': {rows} 行")

print(f"\n总行数 = {total_rows}")

Step2 提取目标实体的时间序列数据,计算平均值,并构建包含比较结果的结构化 DataFrame。

target_entity = 'Target_Entity' # 占位示例,如 'US'

# 提取目标行数据 (假设第0列为实体名称)
target_row = df[df[0] == target_entity]

# 提取时间标签和对应数值 (假设第6行为表头,1:10列为数据)
time_labels = df.iloc[6, 1:10].tolist()
target_values = target_row.iloc[0, 1:10].tolist()
target_values_numeric = [float(v) for v in target_values]

# 计算平均值
avg_value = sum(target_values_numeric) / len(target_values_numeric)

# 构建结果 DataFrame
result_data = {
    '时间维度': time_labels,
    '指标数值': target_values_numeric,
    '是否低于平均值': [v < avg_value for v in target_values_numeric]
}
result_df = pd.DataFrame(result_data)

Step3 使用 openpyxl 将分析结果保存为 Excel 文件,应用精细的样式控制(加粗标题、边框、居中对齐),并对低于平均值的行进行条件格式填充(标绿)。

from openpyxl import Workbook
from openpyxl.styles import PatternFill, Font, Alignment, Border, Side

wb = Workbook()
ws = wb.active
ws.title = "指标分析报告"

# 定义样式
green_fill = PatternFill(start_color="92D050", end_color="92D050", fill_type="solid")
header_fill = PatternFill(start_color="4472C4", end_color="4472C4", fill_type="solid")
header_font = Font(bold=True, color="FFFFFF")
thin_border = Border(
    left=Side(style='thin'), right=Side(style='thin'),
    top=Side(style='thin'), bottom=Side(style='thin')
)

# 设置主标题
ws.merge_cells('A1:D1')
ws['A1'] = f"目标实体指标分析 - 平均值: {avg_value:.2f}"
ws['A1'].font = Font(bold=True, size=14)
ws['A1'].alignment = Alignment(horizontal='center')

# 设置表头
headers = ['时间维度', '指标数值', '与平均值比较', '是否标绿']
for col, header in enumerate(headers, 1):
    cell = ws.cell(row=3, column=col, value=header)
    cell.fill = header_fill
    cell.font = header_font
    cell.alignment = Alignment(horizontal='center')
    cell.border = thin_border

# 写入数据并应用条件格式
for i, row_data in result_df.iterrows():
    row_num = i + 4
    time_label = row_data['时间维度']
    value = row_data['指标数值']
    below_avg = row_data['是否低于平均值']
    
    # 写入各列数据
    ws.cell(row=row_num, column=1, value=time_label).alignment = Alignment(horizontal='center')
    ws.cell(row=row_num, column=2, value=value).alignment = Alignment(horizontal='center')
    
    diff = value - avg_value
    ws.cell(row=row_num, column=3, value=f"{diff:+.2f}").alignment = Alignment(horizontal='center')
    ws.cell(row=row_num, column=4, value="是" if below_avg else "否").alignment = Alignment(horizontal='center')
    
    # 添加边框并根据条件标绿整行
    for col in range(1, 5):
        cell = ws.cell(row=row_num, column=col)
        cell.border = thin_border
        if below_avg:
            cell.fill = green_fill

# 调整列宽
ws.column_dimensions['A'].width = 15
ws.column_dimensions['B'].width = 20
ws.column_dimensions['C'].width = 18
ws.column_dimensions['D'].width = 12

output_path = "output_report.xlsx"
wb.save(output_path)
print(f"分析报告已保存至: {output_path}")

리뷰

아직 리뷰가 없습니다. 사용해 본 소감을 남겨 주세요.

댓글

로그인 없이 쓸 수 있습니다. 사용 후기, 질문, 작동하지 않은 환경 등을 편하게 남겨 주세요.

아직 댓글이 없습니다. 첫 댓글을 남겨 보세요.

보내면 바로 공개됩니다. 이메일 주소나 전화번호 같은 개인 정보는 쓰지 마세요. URL은 2개까지입니다.

0 / 1,000자

이 양식은 reCAPTCHA로 보호되며 Google 개인정보처리방침 및 서비스 약관이 적용됩니다.

같은 저장소의 스킬

Compare counts and shares for two categories in Excel data. The skill cleans the selected columns, calculates differences and percentages, and produces a summary spreadsheet plus bar and pie charts.

한국어 요약은 준비 중입니다. 영어 요약을 표시하고 있습니다.

  • Comparing counts for two categories
  • Visualizing category shares
  • Cleaning merged-cell data before counting
OpenSenseNova/SenseNova-Skills5.8천2026년 10월 9일 업데이트

Analyze Excel data using custom categories, count distributions, and compare groups with charts. Score text using its length, technical terms, numbers, and selected complex concepts, then visualize difficulty levels and the relationship between text length and scores.

한국어 요약은 준비 중입니다. 영어 요약을 표시하고 있습니다.

  • Summarize Excel records using custom categories
  • Compare category distributions across groups
  • Score and grade text using adjustable rules
OpenSenseNova/SenseNova-Skills5.8천2026년 10월 9일 업데이트

Count categories in a chosen data column after removing missing values and placeholder labels. Calculate each category’s share and create high-resolution charts combining counts, percentages, pie charts, and horizontal bars for distribution reports.

한국어 요약은 준비 중입니다. 영어 요약을 표시하고 있습니다.

  • Compare record counts across categories
  • Show category shares with pie and bar charts
  • Exclude placeholder labels before counting
OpenSenseNova/SenseNova-Skills5.8천2026년 10월 9일 업데이트

Clean category and numeric fields in structured data, compare groups with counts and cross-tabulations, and produce charts, Excel results, and a Markdown report. Export visuals as high-resolution PNG and SVG files for use in reports.

한국어 요약은 준비 중입니다. 영어 요약을 표시하고 있습니다.

  • Compare category distributions across groups
  • Clean category labels and fill merged-cell gaps
  • Export analysis results to Excel
OpenSenseNova/SenseNova-Skills5.8천2026년 10월 9일 업데이트

Filter Excel data using candidate column names, RGB color values, text prefixes, and regular expressions, which match text patterns. Calculate totals and averages, then export results to Excel with highlighted rows and a download link.

한국어 요약은 준비 중입니다. 영어 요약을 표시하고 있습니다.

  • Filtering rows by RGB values or identifier prefixes
  • Converting text to numbers and calculating totals or averages
  • Extracting matching commands with their identifiers and descriptions
OpenSenseNova/SenseNova-Skills5.8천2026년 10월 9일 업데이트

Filter rows from Excel or previously converted Parquet files, a format designed for efficient data storage. Summarize matching records by group with counts, percentages, and totals, then export the summary to Excel.

한국어 요약은 준비 중입니다. 영어 요약을 표시하고 있습니다.

  • Count records containing a specified risk level by work category
  • Calculate group shares among matching records
  • Summarize large datasets already converted to Parquet
OpenSenseNova/SenseNova-Skills5.8천2026년 10월 9일 업데이트

OpenSenseNova의 스킬 모두 보기

이 스킬의 문제 신고