fast-excel 1.0.0

通用 Excel 导入导出工具:流式读写(百万级)、动态表头适配、多 sheet、单元格图片、批量落库(纯 Rust,对标 EasyExcel)
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
//! 工作表级附加信息:合并区域 / 超链接 / 批注
//!
//! `<mergeCells>` 与 `<hyperlinks>` 都在 `<sheetData>` **之后**,流式读取时行早已产出,
//! 因此这里用一次独立预扫描把它们收集好;批注存在独立的 `comments*.xml` 部件里,
//! 通过工作表 rels 定位。

use std::collections::HashMap;
use std::io::BufReader;

use quick_xml::Reader;
use quick_xml::events::{BytesStart, Event};

use crate::error::Result;
use crate::read::images::{file_name, normalize_path, parse_rels};
use crate::read::merges::{MergeRange, parse_range, parse_ref};
use crate::read::source::ZipSource;

/// 单元格超链接
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Hyperlink {
    /// 所在行(1 基)
    pub row: u32,
    /// 所在列(0 基)
    pub col: u16,
    /// 外部目标(URL / 文件路径),来自工作表 rels
    pub target: Option<String>,
    /// 内部位置(如 `Sheet2!A1`)
    pub location: Option<String>,
    /// 显示文本
    pub display: Option<String>,
}

impl Hyperlink {
    pub fn contains(&self, row: u32, col: u16) -> bool {
        self.row == row && self.col == col
    }

    /// 链接地址(优先外部目标,其次内部位置)
    pub fn href(&self) -> Option<&str> {
        self.target.as_deref().or(self.location.as_deref())
    }
}

/// 单元格批注
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Comment {
    /// 所在行(1 基)
    pub row: u32,
    /// 所在列(0 基)
    pub col: u16,
    pub text: String,
    pub author: Option<String>,
}

/// 数据验证(下拉 / 数值区间等)
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct DataValidation {
    /// 类型:`list` / `whole` / `decimal` / `date` / `textLength` / `custom` …
    pub kind: String,
    /// 生效区域(`sqref`,可能多段)
    pub ranges: Vec<MergeRange>,
    /// 原始来源(`formula1`,下拉列表可能形如 `"A,B,C"` 或区域引用)
    pub formula: Option<String>,
    /// 下拉选项(`kind == "list"` 且为内联列表时解析)
    pub items: Vec<String>,
    pub prompt: Option<String>,
    pub prompt_title: Option<String>,
    pub allow_blank: bool,
}

impl DataValidation {
    pub fn is_list(&self) -> bool {
        self.kind == "list"
    }

    /// 某单元格是否落在该验证区域内
    pub fn contains(&self, row: u32, col: u16) -> bool {
        self.ranges.iter().any(|r| r.contains(row, col))
    }
}

/// 一条条件格式规则
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct CfRule {
    /// `cellIs` / `expression` / `colorScale` / `dataBar` / `iconSet` / `top10` / `containsText` …
    pub kind: String,
    /// 比较运算符(`cellIs` 时有效,如 `greaterThan`)
    pub operator: Option<String>,
    /// 规则公式 / 阈值(可能多条)
    pub formulas: Vec<String>,
    /// 差异格式索引(`dxfId`,具体颜色需查 `dxfs`)
    pub dxf_id: Option<u32>,
    pub priority: Option<u32>,
}

/// 条件格式(一个 `sqref` 区域 + 若干规则)
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ConditionalFormat {
    /// 生效区域(`sqref`)
    pub ranges: Vec<MergeRange>,
    pub rules: Vec<CfRule>,
}

impl ConditionalFormat {
    pub fn is_empty(&self) -> bool {
        self.rules.is_empty()
    }

    /// 某单元格是否落在该条件格式区域内
    pub fn contains(&self, row: u32, col: u16) -> bool {
        self.ranges.iter().any(|r| r.contains(row, col))
    }
}

/// 一次预扫描需要哪些信息
#[derive(Debug, Clone, Copy, Default)]
pub(crate) struct MetaWants {
    pub merges: bool,
    pub hyperlinks: bool,
    pub validations: bool,
    pub conditional_formats: bool,
}

/// 一次预扫描得到的附加信息
#[derive(Debug, Default)]
pub(crate) struct SheetMeta {
    pub merges: Vec<MergeRange>,
    pub hyperlinks: Vec<Hyperlink>,
    pub validations: Vec<DataValidation>,
    pub conditional_formats: Vec<ConditionalFormat>,
}

/// 扫描 `<mergeCells>` / `<hyperlinks>` / `<dataValidations>`(一趟遍历)
pub(crate) fn load_sheet_meta(
    source: &ZipSource,
    sheet_path: &str,
    wants: MetaWants,
) -> Result<SheetMeta> {
    let mut meta = SheetMeta::default();
    if !wants.merges
        && !wants.hyperlinks
        && !wants.validations
        && !wants.conditional_formats
    {
        return Ok(meta);
    }

    let entry = source.entry_reader(sheet_path)?;
    let mut xml = Reader::from_reader(BufReader::with_capacity(64 * 1024, entry));
    xml.config_mut().trim_text(true);
    let mut buf = Vec::with_capacity(8 * 1024);
    let mut raw_links: Vec<RawLink> = Vec::new();
    let mut cur_dv: Option<DvBuilder> = None;
    let mut capturing_formula = false;
    let mut cur_cf: Option<CfBuilder> = None;
    let mut cur_rule: Option<CfRule> = None;
    let mut capturing_cf_formula = false;

    loop {
        match xml.read_event_into(&mut buf) {
            Ok(Event::Eof) => break,
            Err(e) => return Err(e.into()),
            Ok(Event::Start(e)) => match e.local_name().as_ref() {
                b"mergeCell" if wants.merges => {
                    if let Some(r) = attr(&e, b"ref").as_deref().and_then(parse_range) {
                        meta.merges.push(r);
                    }
                }
                b"hyperlink" if wants.hyperlinks => raw_links.push(raw_link(&e)),
                b"dataValidation" if wants.validations => cur_dv = Some(DvBuilder::from(&e)),
                b"formula1" if cur_dv.is_some() => capturing_formula = true,
                b"conditionalFormatting" if wants.conditional_formats => {
                    cur_cf = Some(CfBuilder::from(&e))
                }
                b"cfRule" if cur_cf.is_some() => cur_rule = Some(CfRule::from(&e)),
                b"formula" if cur_rule.is_some() => {
                    if let Some(rule) = cur_rule.as_mut() {
                        rule.formulas.push(String::new());
                    }
                    capturing_cf_formula = true;
                }
                _ => {}
            },
            Ok(Event::Empty(e)) => match e.local_name().as_ref() {
                b"mergeCell" if wants.merges => {
                    if let Some(r) = attr(&e, b"ref").as_deref().and_then(parse_range) {
                        meta.merges.push(r);
                    }
                }
                b"hyperlink" if wants.hyperlinks => raw_links.push(raw_link(&e)),
                b"dataValidation" if wants.validations => {
                    meta.validations.push(DvBuilder::from(&e).finish())
                }
                b"cfRule" if cur_cf.is_some() => {
                    if let Some(cf) = cur_cf.as_mut() {
                        cf.rules.push(CfRule::from(&e));
                    }
                }
                _ => {}
            },
            Ok(Event::Text(t)) if capturing_formula => {
                if let Some(dv) = cur_dv.as_mut() {
                    dv.formula
                        .get_or_insert_with(String::new)
                        .push_str(&String::from_utf8_lossy(t.as_ref()));
                }
            }
            Ok(Event::Text(t)) if capturing_cf_formula => {
                if let Some(rule) = cur_rule.as_mut() {
                    if let Some(last) = rule.formulas.last_mut() {
                        last.push_str(&String::from_utf8_lossy(t.as_ref()));
                    }
                }
            }
            Ok(Event::End(e)) => match e.local_name().as_ref() {
                b"formula1" => capturing_formula = false,
                b"formula" => capturing_cf_formula = false,
                b"cfRule" => {
                    if let (Some(cf), Some(rule)) = (cur_cf.as_mut(), cur_rule.take()) {
                        cf.rules.push(rule);
                    }
                }
                b"conditionalFormatting" => {
                    if let Some(cf) = cur_cf.take() {
                        if !cf.rules.is_empty() {
                            meta.conditional_formats.push(cf.finish());
                        }
                    }
                }
                b"dataValidation" => {
                    if let Some(dv) = cur_dv.take() {
                        meta.validations.push(dv.finish());
                    }
                }
                _ => {}
            },
            _ => {}
        }
        buf.clear();
    }

    meta.merges.sort_by_key(|r| (r.first_row, r.first_col));

    let rels = if raw_links.iter().any(|l| l.rid.is_some()) {
        load_sheet_rels(source, sheet_path)
    } else {
        HashMap::new()
    };
    meta.hyperlinks = raw_links
        .into_iter()
        .filter_map(|l| {
            let (row, col) = l.cell?;
            Some(Hyperlink {
                row,
                col,
                target: l.rid.and_then(|id| rels.get(&id).cloned()),
                location: l.location,
                display: l.display,
            })
        })
        .collect();

    Ok(meta)
}

/// 扫描到的原始超链接(`r:id` 待解析成 target)
struct RawLink {
    cell: Option<(u32, u16)>,
    rid: Option<String>,
    location: Option<String>,
    display: Option<String>,
}

fn raw_link(e: &BytesStart<'_>) -> RawLink {
    RawLink {
        cell: attr(e, b"ref")
            .as_deref()
            .and_then(parse_ref)
            .map(|(col, row)| (row, col)),
        rid: attr(e, b"r:id").or_else(|| attr(e, b"id")),
        location: attr(e, b"location"),
        display: attr(e, b"display"),
    }
}

/// `dataValidation` 的暂存(`formula1` 文本在子元素里)
struct DvBuilder {
    kind: String,
    sqref: String,
    formula: Option<String>,
    prompt: Option<String>,
    prompt_title: Option<String>,
    allow_blank: bool,
}

impl From<&BytesStart<'_>> for DvBuilder {
    fn from(e: &BytesStart<'_>) -> Self {
        Self {
            kind: attr(e, b"type").unwrap_or_else(|| "none".to_string()),
            sqref: attr(e, b"sqref").unwrap_or_default(),
            formula: None,
            prompt: attr(e, b"prompt"),
            prompt_title: attr(e, b"promptTitle"),
            allow_blank: attr(e, b"allowBlank").as_deref() == Some("1"),
        }
    }
}

impl DvBuilder {
    fn finish(self) -> DataValidation {
        let ranges: Vec<MergeRange> = self
            .sqref
            .split_whitespace()
            .filter_map(parse_range)
            .collect();
        let items = if self.kind == "list" {
            self.formula.as_deref().map(parse_list_items).unwrap_or_default()
        } else {
            Vec::new()
        };
        DataValidation {
            kind: self.kind,
            ranges,
            formula: self.formula,
            items,
            prompt: self.prompt,
            prompt_title: self.prompt_title,
            allow_blank: self.allow_blank,
        }
    }
}

/// `conditionalFormatting` 的暂存(`sqref` + 规则)
struct CfBuilder {
    sqref: String,
    rules: Vec<CfRule>,
}

impl From<&BytesStart<'_>> for CfBuilder {
    fn from(e: &BytesStart<'_>) -> Self {
        Self {
            sqref: attr(e, b"sqref").unwrap_or_default(),
            rules: Vec::new(),
        }
    }
}

impl CfBuilder {
    fn finish(self) -> ConditionalFormat {
        ConditionalFormat {
            ranges: self.sqref.split_whitespace().filter_map(parse_range).collect(),
            rules: self.rules,
        }
    }
}

impl From<&BytesStart<'_>> for CfRule {
    fn from(e: &BytesStart<'_>) -> Self {
        Self {
            kind: attr(e, b"type").unwrap_or_else(|| "expression".to_string()),
            operator: attr(e, b"operator"),
            formulas: Vec::new(),
            dxf_id: attr(e, b"dxfId").and_then(|v| v.parse().ok()),
            priority: attr(e, b"priority").and_then(|v| v.parse().ok()),
        }
    }
}

/// 解析内联下拉列表 `"A,B,C"` → `["A","B","C"]`
fn parse_list_items(formula: &str) -> Vec<String> {
    let t = formula.trim();
    let t = t
        .strip_prefix('"')
        .and_then(|x| x.strip_suffix('"'))
        .unwrap_or(t);
    t.split(',')
        .map(|s| s.trim().to_string())
        .filter(|s| !s.is_empty())
        .collect()
}

/// 读取某工作表的所有批注:经典批注(`comments*.xml`)+ 线程批注(`threadedComments`)
///
/// 线程批注只收「根批注」(带 `ref` 的条目);回复(只有 `parentId`)暂不展开。
pub(crate) fn load_comments(source: &ZipSource, sheet_path: &str) -> Result<Vec<Comment>> {
    let rels = load_sheet_rels(source, sheet_path);
    let mut out = Vec::new();
    let persons = load_persons(source);
    for target in rels.values() {
        if target.contains("threadedComment") {
            let path = normalize_path(&format!("xl/worksheets/{target}"));
            if let Ok(xml) = source.read_entry(&path) {
                out.extend(parse_threaded_comments(&xml, &persons));
            }
        } else if target.contains("comments") {
            let path = normalize_path(&format!("xl/worksheets/{target}"));
            if let Ok(xml) = source.read_entry(&path) {
                out.extend(parse_comments(&xml)?);
            }
        }
    }
    out.sort_by_key(|c| (c.row, c.col));
    Ok(out)
}

/// 读取 `persons`(线程批注作者表):`personId → displayName`
fn load_persons(source: &ZipSource) -> HashMap<String, String> {
    let Ok(rels_xml) = source.read_entry("xl/_rels/workbook.xml.rels") else {
        return HashMap::new();
    };
    let rels = parse_rels(&rels_xml);
    let Some(target) = rels.values().find(|t| t.contains("person")) else {
        return HashMap::new();
    };
    let path = normalize_path(&format!("xl/{target}"));
    let Ok(xml) = source.read_entry(&path) else {
        return HashMap::new();
    };

    let mut reader = Reader::from_reader(xml.as_slice());
    reader.config_mut().trim_text(true);
    let mut buf = Vec::with_capacity(4 * 1024);
    let mut out = HashMap::new();
    loop {
        match reader.read_event_into(&mut buf) {
            Ok(Event::Eof) => break,
            Ok(Event::Start(e)) | Ok(Event::Empty(e))
                if e.local_name().as_ref() == b"person" =>
            {
                if let (Some(id), Some(name)) = (attr(&e, b"id"), attr(&e, b"displayName")) {
                    out.insert(id, name);
                }
            }
            _ => {}
        }
        buf.clear();
    }
    out
}

/// 解析 `threadedComments/threadedCommentN.xml`
fn parse_threaded_comments(xml: &[u8], persons: &HashMap<String, String>) -> Vec<Comment> {
    let mut reader = Reader::from_reader(xml);
    reader.config_mut().trim_text(true);
    let mut buf = Vec::with_capacity(8 * 1024);

    let mut in_comment = false;
    let mut in_text = false;
    let mut cell: Option<(u32, u16)> = None;
    let mut person: Option<String> = None;
    let mut id: Option<String> = None;
    let mut parent_id: Option<String> = None;
    let mut text = String::new();
    let mut out: Vec<Comment> = Vec::new();
    // 根批注 id → out 下标(回复按 parentId 并入父批注)
    let mut by_id: HashMap<String, usize> = HashMap::new();

    loop {
        match reader.read_event_into(&mut buf) {
            Ok(Event::Eof) => break,
            Ok(Event::Start(e)) => match e.local_name().as_ref() {
                b"threadedComment" => {
                    in_comment = true;
                    cell = attr(&e, b"ref")
                        .as_deref()
                        .and_then(parse_ref)
                        .map(|(c, r)| (r, c));
                    person = attr(&e, b"personId");
                    id = attr(&e, b"id");
                    parent_id = attr(&e, b"parentId");
                    text.clear();
                }
                b"text" if in_comment => in_text = true,
                _ => {}
            },
            Ok(Event::Text(t)) if in_text => {
                text.push_str(&String::from_utf8_lossy(t.as_ref()));
            }
            Ok(Event::End(e)) => match e.local_name().as_ref() {
                b"text" => in_text = false,
                b"threadedComment" => {
                    in_comment = false;
                    let author = person.as_ref().and_then(|p| persons.get(p).cloned());
                    let body = text.trim().to_string();
                    match parent_id.as_ref().and_then(|p| by_id.get(p).copied()) {
                        // 回复:并入父批注文本
                        Some(idx) => {
                            let who = author.as_deref().unwrap_or("回复");
                            out[idx].text.push_str(&format!("\n— {who}:{body}"));
                        }
                        // 根批注
                        None => {
                            if let Some((row, col)) = cell {
                                let idx = out.len();
                                if let Some(root_id) = id.clone() {
                                    by_id.insert(root_id, idx);
                                }
                                out.push(Comment {
                                    row,
                                    col,
                                    text: body,
                                    author,
                                });
                            }
                        }
                    }
                }
                _ => {}
            },
            _ => {}
        }
        buf.clear();
    }
    out
}

fn parse_comments(xml: &[u8]) -> Result<Vec<Comment>> {
    let mut reader = Reader::from_reader(xml);
    reader.config_mut().trim_text(false);
    let mut buf = Vec::with_capacity(8 * 1024);

    let mut authors: Vec<String> = Vec::new();
    let mut in_authors = false;
    let mut in_author = false;
    let mut in_comment = false;
    let mut in_text = false;
    let mut cur_cell: Option<(u32, u16)> = None;
    let mut cur_author: Option<String> = None;
    let mut cur_text = String::new();
    let mut out = Vec::new();

    loop {
        match reader.read_event_into(&mut buf) {
            Ok(Event::Eof) => break,
            Err(e) => return Err(e.into()),
            Ok(Event::Start(e)) => match e.local_name().as_ref() {
                b"authors" => in_authors = true,
                b"author" if in_authors => in_author = true,
                b"comment" => {
                    in_comment = true;
                    cur_cell = attr(&e, b"ref").as_deref().and_then(parse_ref).map(|(c, r)| (r, c));
                    let id = attr(&e, b"authorId").and_then(|v| v.parse::<usize>().ok());
                    cur_author = id.and_then(|i| authors.get(i).cloned());
                    cur_text.clear();
                }
                b"text" if in_comment => in_text = true,
                _ => {}
            },
            Ok(Event::Text(t)) => {
                if in_author {
                    authors.push(String::from_utf8_lossy(t.as_ref()).into_owned());
                } else if in_comment && in_text {
                    cur_text.push_str(&String::from_utf8_lossy(t.as_ref()));
                }
            }
            Ok(Event::End(e)) => match e.local_name().as_ref() {
                b"authors" => in_authors = false,
                b"author" => in_author = false,
                b"text" => in_text = false,
                b"comment" => {
                    in_comment = false;
                    if let Some((row, col)) = cur_cell {
                        out.push(Comment {
                            row,
                            col,
                            text: cur_text.trim().to_string(),
                            author: cur_author.clone(),
                        });
                    }
                }
                _ => {}
            },
            _ => {}
        }
        buf.clear();
    }
    Ok(out)
}

fn load_sheet_rels(source: &ZipSource, sheet_path: &str) -> HashMap<String, String> {
    let rels_path = format!("xl/worksheets/_rels/{}.rels", file_name(sheet_path));
    source
        .read_entry(&rels_path)
        .map(|x| parse_rels(&x))
        .unwrap_or_default()
}

fn attr(e: &BytesStart<'_>, name: &[u8]) -> Option<String> {
    e.attributes()
        .flatten()
        .find(|a| a.key.as_ref() == name)
        .map(|a| String::from_utf8_lossy(&a.value).into_owned())
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_parse_comments() {
        let xml = r#"<?xml version="1.0"?>
<comments xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main">
  <authors><author>张三</author></authors>
  <commentList>
    <comment ref="B2" authorId="0"><text><r><t>请核对数量</t></r></text></comment>
    <comment ref="C3"><text><t>无作者批注</t></text></comment>
  </commentList>
</comments>"#;
        let list = parse_comments(xml.as_bytes()).unwrap();
        assert_eq!(list.len(), 2);
        assert_eq!(list[0].row, 2);
        assert_eq!(list[0].col, 1);
        assert_eq!(list[0].text, "请核对数量");
        assert_eq!(list[0].author.as_deref(), Some("张三"));
        assert_eq!(list[1].text, "无作者批注");
        assert_eq!(list[1].author, None);
    }

    #[test]
    fn test_parse_threaded_comments_with_reply() {
        let xml = r#"<?xml version="1.0"?>
<ThreadedComments xmlns="http://schemas.microsoft.com/office/spreadsheetml/2018/threadedcomments">
  <threadedComment ref="B2" personId="{P1}" id="{C1}" date="2025-01-01T00:00:00Z"><text>请核对数量</text></threadedComment>
  <threadedComment ref="C3" personId="{P2}" id="{C2}"><text>已确认</text></threadedComment>
  <threadedComment parentId="{C1}" personId="{P2}" id="{C1R}"><text>已核对</text></threadedComment>
</ThreadedComments>"#;
        let mut persons = HashMap::new();
        persons.insert("{P1}".to_string(), "张三".to_string());
        persons.insert("{P2}".to_string(), "李四".to_string());
        let list = parse_threaded_comments(xml.as_bytes(), &persons);
        assert_eq!(list.len(), 2, "回复不单独成条");
        assert_eq!((list[0].row, list[0].col), (2, 1));
        assert_eq!(list[0].author.as_deref(), Some("张三"));
        assert!(list[0].text.contains("请核对数量"));
        assert!(list[0].text.contains("已核对"), "回复应并入父批注:{}", list[0].text);
        assert!(list[0].text.contains("李四"), "回复应带作者:{}", list[0].text);
        assert_eq!(list[1].text, "已确认");
    }
}