Skip to content

alchaincyf/huashu-skills / huashu-data-pro

huashu-data-pro

Verified

数据分析与办公提效全能助手。覆盖数据处理、分析洞察、报告撰写、PPT制作、数据可视化的端到端工作流。 始终从专家视角出发,帮用户多想一步。遇到不确定的问题主动与用户确认。 支持:Excel数据分析、投放数据复盘、ROI测算、数据可视化、报告生成、PPT制作、公式生成。 当用户提到"分析数据"、"做报告"、"做PPT"、"Excel"、"投放分析"、"ROI"、"复盘"、 "周报"、"月报"、"数据处理"、"图表"、"可视化"、"汇报"、"表格"、"公式"时使用此技能。

FileKindSize
SKILL.mdskill md6.9 KB
references/ad-analytics.mdmarkdown1.4 KB
references/html-templates.mdmarkdown16.4 KB
references/report-style-gallery.mdmarkdown9.5 KB
references/visual-design-system.mdmarkdown18.1 KB
references/workflows.mdmarkdown6.6 KB
scripts/build_pptx.jsscript6.9 KB
scripts/html2pptx.jsexecutablescript33.7 KB
scripts/read_excel.pyscript3.8 KB
scripts/read_pptx.pyscript7.4 KB

scripts/build_pptx.js

View on GitHub
#!/usr/bin/env node
/**
 * build_pptx.js — 将多个 HTML 幻灯片文件构建为一个 PPTX 文件
 *
 * 用法:
 *   node build_pptx.js --slides slide1.html slide2.html --output report.pptx
 *   node build_pptx.js --dir ./slides/ --output report.pptx
 *   node build_pptx.js --slides slide1.html --output report.pptx --chart 0:bar:data.json
 *
 * 参数:
 *   --slides    指定 HTML 文件列表(按顺序)
 *   --dir       指定包含 HTML 文件的目录(按文件名排序)
 *   --output    输出 PPTX 文件名(默认:output.pptx)
 *   --chart     在指定幻灯片的 placeholder 中插入图表
 *               格式:幻灯片序号:图表类型:数据JSON文件
 *               例:0:bar:chart_data.json
 *
 * 依赖安装(自动检测,缺失时提示):
 *   npm install pptxgenjs playwright sharp
 *
 * HTML 文件规范:
 *   - body 尺寸必须是 width: 720pt; height: 405pt(16:9)
 *   - 所有文字必须在 <p>/<h1>-<h6>/<ul>/<ol> 标签内
 *   - 图表预留区域用 <div class="placeholder" id="chart-1"></div>
 *   - 不支持 CSS 渐变(需预渲染为 PNG)
 *   - 颜色使用 hex 格式
 */

const path = require('path');
const fs = require('fs');

// 检查依赖
function checkDependencies() {
  const missing = [];
  for (const dep of ['pptxgenjs', 'playwright', 'sharp']) {
    try {
      require.resolve(dep);
    } catch {
      missing.push(dep);
    }
  }
  if (missing.length > 0) {
    console.error(`缺少依赖: ${missing.join(', ')}`);
    console.error(`请运行: npm install ${missing.join(' ')}`);
    process.exit(1);
  }
}

checkDependencies();

const pptxgen = require('pptxgenjs');
const html2pptx = require('./html2pptx.js');

// 解析命令行参数
function parseArgs() {
  const args = process.argv.slice(2);
  const config = { slides: [], output: 'output.pptx', charts: [] };

  for (let i = 0; i < args.length; i++) {
    switch (args[i]) {
      case '--slides':
        while (i + 1 < args.length && !args[i + 1].startsWith('--')) {
          config.slides.push(args[++i]);
        }
        break;
      case '--dir':
        const dir = args[++i];
        if (!fs.existsSync(dir)) {
          console.error(`目录不存在: ${dir}`);
          process.exit(1);
        }
        config.slides = fs.readdirSync(dir)
          .filter(f => f.endsWith('.html'))
          .sort()
          .map(f => path.join(dir, f));
        break;
      case '--output':
        config.output = args[++i];
        break;
      case '--chart':
        // 格式: slideIndex:chartType:dataFile
        const parts = args[++i].split(':');
        config.charts.push({
          slideIndex: parseInt(parts[0]),
          chartType: parts[1],
          dataFile: parts[2]
        });
        break;
      case '--help':
        console.log(`
用法:node build_pptx.js [选项]

选项:
  --slides file1.html file2.html   指定HTML幻灯片文件
  --dir ./slides/                  从目录加载所有HTML文件
  --output report.pptx             输出文件名
  --chart 0:bar:data.json          插入图表到指定幻灯片
  --help                           显示帮助
        `);
        process.exit(0);
    }
  }

  if (config.slides.length === 0) {
    console.error('请指定至少一个HTML文件。使用 --help 查看帮助。');
    process.exit(1);
  }

  return config;
}

// 图表类型映射
function getChartType(pptx, typeName) {
  const map = {
    'bar': pptx.charts.BAR,
    'col': pptx.charts.BAR,
    'line': pptx.charts.LINE,
    'pie': pptx.charts.PIE,
    'scatter': pptx.charts.SCATTER,
    'doughnut': pptx.charts.DOUGHNUT
  };
  return map[typeName.toLowerCase()] || pptx.charts.BAR;
}

// 默认图表配色(不带 # 前缀!PptxGenJS 规则)
const CHART_COLORS = ['E17055', '45B7AA', '5B8C5A', 'FFD700', '9B7EDE'];

async function build() {
  const config = parseArgs();

  console.log(`构建 PPTX: ${config.slides.length} 页幻灯片`);

  const pptx = new pptxgen();
  pptx.layout = 'LAYOUT_16x9';

  // 存储每页的 placeholders 以便后续插入图表
  const slideResults = [];

  for (let i = 0; i < config.slides.length; i++) {
    const htmlFile = config.slides[i];
    const absPath = path.isAbsolute(htmlFile) ? htmlFile : path.join(process.cwd(), htmlFile);

    if (!fs.existsSync(absPath)) {
      console.error(`文件不存在: ${absPath}`);
      process.exit(1);
    }

    console.log(`  [${i + 1}/${config.slides.length}] ${path.basename(htmlFile)}`);

    try {
      const result = await html2pptx(absPath, pptx);
      slideResults.push(result);
    } catch (error) {
      console.error(`  ❌ 转换失败: ${error.message}`);
      process.exit(1);
    }
  }

  // 插入图表
  for (const chartConfig of config.charts) {
    const { slideIndex, chartType, dataFile } = chartConfig;

    if (slideIndex >= slideResults.length) {
      console.error(`图表配置错误: 幻灯片 ${slideIndex} 不存在(共 ${slideResults.length} 页)`);
      continue;
    }

    const { slide, placeholders } = slideResults[slideIndex];
    if (placeholders.length === 0) {
      console.error(`幻灯片 ${slideIndex} 没有 placeholder 区域`);
      continue;
    }

    const dataPath = path.isAbsolute(dataFile) ? dataFile : path.join(process.cwd(), dataFile);
    if (!fs.existsSync(dataPath)) {
      console.error(`图表数据文件不存在: ${dataPath}`);
      continue;
    }

    const chartData = JSON.parse(fs.readFileSync(dataPath, 'utf-8'));
    const type = getChartType(pptx, chartType);

    // 使用第一个 placeholder 的位置
    const pos = placeholders[0];
    const chartOptions = {
      x: pos.x,
      y: pos.y,
      w: pos.w,
      h: pos.h,
      chartColors: chartData.colors || CHART_COLORS,
      showTitle: !!chartData.title,
      title: chartData.title || '',
      showCatAxisTitle: !!chartData.catAxisTitle,
      catAxisTitle: chartData.catAxisTitle || '',
      showValAxisTitle: !!chartData.valAxisTitle,
      valAxisTitle: chartData.valAxisTitle || ''
    };

    // 柱状图特有配置
    if (chartType === 'col') chartOptions.barDir = 'col';
    if (chartType === 'bar') chartOptions.barDir = 'bar';

    // 折线图特有配置
    if (chartType === 'line') {
      chartOptions.lineSize = 3;
      chartOptions.lineSmooth = true;
    }

    // 饼图特有配置
    if (chartType === 'pie' || chartType === 'doughnut') {
      chartOptions.showPercent = true;
      chartOptions.showLegend = true;
      chartOptions.legendPos = 'r';
    }

    slide.addChart(type, chartData.series, chartOptions);
    console.log(`  📊 已插入图表到幻灯片 ${slideIndex}`);
  }

  // 输出文件
  const outputPath = path.isAbsolute(config.output) ? config.output : path.join(process.cwd(), config.output);
  await pptx.writeFile({ fileName: outputPath });
  console.log(`\n✅ 已生成: ${outputPath}`);
}

build().catch(err => {
  console.error('构建失败:', err.message);
  process.exit(1);
});
canvas-designanthropics/skillsCreate beautiful visual art in .png and .pdf documents using design philosophy. You should use this skill when the user asks to create a poster, piece of art, design, or other static piece. Create original visual designs, never copying existing artists' work to avoid copyright violations.Stars: 198kUpdated Claude CodeCodexVerifiedInstall
docxanthropics/skillsUse this skill whenever the user wants to create, read, edit, or manipulate Word documents (.docx files) or Word templates (.dotx files). Triggers include: any mention of 'Word doc', 'word document', '.docx', '.dotx', or requests to produce professional documents with formatting like tables of contents, headings, page numbers, or letterheads. Also use when extracting or reorganizing content from .docx or .dotx files, inserting or replacing images in documents, performing find-and-replace in Word files, working with tracked changes or comments, or converting content into a polished Word document. If the user asks for a 'report', 'memo', 'letter', 'template', or similar deliverable as a Word or .docx file, use this skill. Do NOT use for PDFs, spreadsheets, Google Docs, or general coding tasks unrelated to document generation.Stars: 198kUpdated Claude CodeCodexVerifiedInstall
pdfanthropics/skillsUse this skill whenever the user wants to do anything with PDF files. This includes reading or extracting text/tables from PDFs, combining or merging multiple PDFs into one, splitting PDFs apart, rotating pages, adding watermarks, creating new PDFs, filling PDF forms, encrypting/decrypting PDFs, extracting images, and OCR on scanned PDFs to make them searchable. If the user mentions a .pdf file or asks to produce one, use this skill.Stars: 198kUpdated Claude CodeCodexVerifiedInstall
pptxanthropics/skillsUse this skill any time a .pptx or .potx file is involved in any way — as input, output, or both. This includes: creating slide decks, pitch decks, or presentations; reading, parsing, or extracting text from any .pptx or .potx file (even if the extracted content will be used elsewhere, like in an email or summary); editing, modifying, or updating existing presentations; combining or splitting slide files; working with templates (.potx), layouts, speaker notes, or comments. Trigger whenever the user mentions "deck," "slides," "presentation," or references a .pptx or .potx filename, regardless of what they plan to do with the content afterward. If a .pptx or .potx file needs to be opened, created, or touched, use this skill.Stars: 198kUpdated Claude CodeCodexVerifiedInstall