定制 opencat/filter-xlsx 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

opencat/filter-xlsx

Composer 安装命令:

composer require opencat/filter-xlsx

包简介

Excel (.xlsx) file filter for the OpenCAT Framework

README 文档

README

Microsoft Excel XLSX file filter for the CAT Framework.

Installation

composer require catframework/filter-xlsx

Requires ext-dom, ext-libxml, and ext-zip.

Usage

use CatFramework\FilterXlsx\XlsxFilter;

$filter = new XlsxFilter();

// Extract translatable segments
$document = $filter->extract('data.xlsx', 'en', 'fr');

foreach ($document->getSegmentPairs() as $pair) {
    $pair->target = new Segment('seg-t', [$translatedText]);
}

// Write the translated XLSX
$filter->rebuild($document, 'data.fr.xlsx');

What gets extracted

XLSX stores cell text in two places; the filter handles both:

Storage type Location in ZIP Notes
Shared strings xl/sharedStrings.xml Deduplicated across the workbook; only strings actually referenced by cells are extracted
Inline strings xl/worksheets/sheet*.xml (cells with t="inlineStr") Extracted and replaced per cell

Non-translatable strings are skipped automatically: pure numbers, currency values, percentages, and empty strings are detected by a regex heuristic and omitted from extraction.

Rich-text shared strings (multiple <r> runs with different formatting) preserve their formatting as InlineCode pairs on the segment.

On rebuild, xl/calcChain.xml is deleted so Excel recomputes formula dependencies on next open (avoids stale cell reference errors).

Skeleton format

The skeleton is a temporary XLSX file written to the system temp directory at extract time:

['path' => '/tmp/cat-<uniqid>.skl']

The skeleton is a copy of the original XLSX ZIP with translatable cell values replaced by {{SEG:NNN}} tokens. Do not delete it between extract() and rebuild() calls.

Limitations

  • Formula cells: cells containing formulas (=SUM(...)) are not extracted — only their stored text values if present.
  • Number-format strings: strings that look purely numeric (digits, commas, currency symbols, %) are silently skipped. If a string like "1,234 units" should be translatable, it will be skipped due to the numeric heuristic.
  • Worksheet names: tab names are not extracted.
  • Skeleton lifetime: the .skl temp file must survive between extract() and rebuild(). For long-lived workflows, persist $document->skeleton['path'].

统计信息

  • 总下载量: 0
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 9
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-05-09

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固