last Documents and Module Updating ...

This commit is contained in:
2026-10-22 19:09:01 +03:30
parent 3143086526
commit bd8abbffc4
16 changed files with 9844 additions and 29795 deletions
@@ -0,0 +1,740 @@
<!DOCTYPE html>
<html lang="fa" dir="rtl">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>پیاده‌سازی کامل ExtractOdtAsync / ExtractOdsAsync / ExtractOdpAsync | xAiApi</title>
<style>
@import url('https://fonts.googleapis.com/css2?family=Vazirmatn:wght@300;400;500;600;700;800&display=swap');
:root {
--primary: #1a365d;
--primary-light: #2c5282;
--accent: #c9a961;
--accent-dark: #a8893f;
--bg: #faf9f6;
--card-bg: #ffffff;
--text: #1a202c;
--text-muted: #4a5568;
--border: #e2e8f0;
--success: #38a169;
--danger: #e53e3e;
--warning: #dd6b20;
--shadow: 0 4px 6px rgba(0,0,0,0.05), 0 10px 30px rgba(26,54,93,0.08);
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
font-family: 'Vazirmatn', Tahoma, sans-serif;
background: var(--bg);
color: var(--text);
line-height: 1.9;
font-size: 15px;
padding: 30px 15px;
}
.document-container {
max-width: 950px;
margin: 0 auto;
background: var(--card-bg);
box-shadow: var(--shadow);
border-radius: 12px;
overflow: hidden;
}
.document-header {
background: linear-gradient(135deg, var(--primary) 0%, var(--primary-light) 100%);
color: white;
padding: 50px 40px 40px;
position: relative;
border-bottom: 4px solid var(--accent);
}
.document-header::before {
content: '';
position: absolute;
top: 0; right: 0;
width: 200px; height: 200px;
background: radial-gradient(circle, rgba(201,169,97,0.15) 0%, transparent 70%);
border-radius: 50%;
transform: translate(50%, -50%);
}
.header-top {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 30px;
position: relative;
z-index: 1;
}
.company-badge { display: flex; align-items: center; gap: 12px; }
.company-logo {
width: 60px; height: 60px;
background: var(--accent);
border-radius: 12px;
box-shadow: 0 4px 12px rgba(0,0,0,0.2);
}
.doc-meta { text-align: left; font-size: 12px; opacity: 0.9; }
.doc-meta div { margin-bottom: 3px; }
.document-title { text-align: center; position: relative; z-index: 1; padding: 20px 0; }
.document-title .label {
display: inline-block;
background: rgba(201,169,97,0.2);
color: var(--accent);
padding: 4px 16px;
border-radius: 20px;
font-size: 12px;
font-weight: 600;
margin-bottom: 15px;
border: 1px solid rgba(201,169,97,0.4);
}
.document-title h1 { font-size: 28px; font-weight: 800; margin-bottom: 10px; letter-spacing: -0.5px; }
.document-title h2 { font-size: 16px; font-weight: 400; opacity: 0.9; }
.document-body { padding: 40px; }
.intro-text {
background: linear-gradient(to left, #f7fafc, #edf2f7);
border-right: 4px solid var(--accent);
padding: 20px 25px;
border-radius: 8px;
margin-bottom: 35px;
font-size: 14px;
color: var(--text-muted);
}
.section { margin-bottom: 40px; page-break-inside: avoid; }
.section-header {
display: flex;
align-items: center;
gap: 15px;
padding-bottom: 12px;
border-bottom: 2px solid var(--border);
margin-bottom: 20px;
}
.section-number {
width: 50px; height: 50px;
background: linear-gradient(135deg, var(--primary), var(--primary-light));
color: white;
border-radius: 12px;
display: flex;
align-items: center;
justify-content: center;
font-weight: 800;
font-size: 20px;
flex-shrink: 0;
box-shadow: 0 4px 10px rgba(26,54,93,0.2);
}
.section-title { flex: 1; }
.section-title h3 { font-size: 19px; font-weight: 700; color: var(--primary); margin-bottom: 2px; }
.section-title .subtitle { font-size: 12px; color: var(--text-muted); }
.section-content { padding-right: 10px; }
.section-content p { margin-bottom: 12px; text-align: justify; text-indent: 20px; }
.section-content p.no-indent { text-indent: 0; }
.highlight-box {
background: linear-gradient(to left, #fffaf0, #fef5e7);
border: 1px solid #f6e05e;
border-right: 4px solid var(--accent);
padding: 18px 22px;
border-radius: 8px;
margin: 20px 0;
font-size: 14px;
}
.highlight-box strong { color: var(--accent-dark); }
.info-box {
background: linear-gradient(to left, #ebf8ff, #e6f6ff);
border: 1px solid #90cdf4;
border-right: 4px solid var(--primary-light);
padding: 18px 22px;
border-radius: 8px;
margin: 20px 0;
font-size: 14px;
}
.success-box {
background: linear-gradient(to left, #f0fff4, #e6fffa);
border: 1px solid #9ae6b4;
border-right: 4px solid var(--success);
padding: 18px 22px;
border-radius: 8px;
margin: 20px 0;
font-size: 14px;
}
.warning-box {
background: linear-gradient(to left, #fffaf0, #fef5e7);
border: 1px solid #fbd38d;
border-right: 4px solid var(--warning);
padding: 18px 22px;
border-radius: 8px;
margin: 20px 0;
font-size: 14px;
}
.styled-table {
width: 100%;
border-collapse: collapse;
margin: 20px 0;
background: white;
border-radius: 8px;
overflow: hidden;
box-shadow: 0 2px 8px rgba(0,0,0,0.05);
}
.styled-table thead { background: linear-gradient(135deg, var(--primary), var(--primary-light)); color: white; }
.styled-table th { padding: 14px 16px; text-align: right; font-weight: 600; font-size: 13px; }
.styled-table td { padding: 13px 16px; border-bottom: 1px solid var(--border); font-size: 13px; }
.styled-table tbody tr:last-child td { border-bottom: none; }
.styled-table tbody tr:nth-child(even) { background: #f8fafc; }
.styled-table .highlight-row { background: #fffaf0 !important; font-weight: 600; }
.conclusion-box {
background: linear-gradient(135deg, var(--primary), var(--primary-light));
color: white;
padding: 30px;
border-radius: 12px;
margin: 30px 0;
text-align: center;
box-shadow: 0 8px 20px rgba(26,54,93,0.3);
}
.conclusion-box h3 { font-size: 22px; font-weight: 800; margin-bottom: 15px; color: var(--accent); }
.conclusion-box p { font-size: 14px; line-height: 1.8; text-indent: 0 !important; margin-bottom: 15px; }
.conclusion-box .highlight {
background: rgba(201,169,97,0.2);
padding: 15px 20px;
border-radius: 8px;
margin-top: 20px;
border: 1px solid rgba(201,169,97,0.4);
}
.document-footer {
background: var(--primary);
color: white;
padding: 25px 40px;
text-align: center;
font-size: 12px;
margin-top: 40px;
}
.document-footer .footer-brand { font-weight: 700; color: var(--accent); margin-bottom: 5px; font-size: 14px; }
.footer-divider { width: 60px; height: 2px; background: var(--accent); margin: 10px auto; }
.page-info {
text-align: center;
padding: 15px;
font-size: 11px;
color: var(--text-muted);
border-top: 1px solid var(--border);
margin-top: 30px;
}
code {
font-family: 'Consolas', 'Monaco', monospace;
background: #edf2f7;
padding: 2px 6px;
border-radius: 4px;
font-size: 12px;
direction: ltr;
display: inline-block;
}
pre {
background: #1a202c;
color: #e2e8f0;
padding: 18px 20px;
border-radius: 8px;
overflow-x: auto;
direction: ltr;
text-align: left;
font-size: 12px;
line-height: 1.7;
margin: 15px 0;
font-family: 'Consolas', 'Monaco', monospace;
}
.step-list { list-style: none; padding: 0; counter-reset: step; }
.step-list > li {
position: relative;
padding: 18px 55px 18px 20px;
margin-bottom: 12px;
background: #f8fafc;
border: 1px solid var(--border);
border-radius: 8px;
counter-increment: step;
}
.step-list > li::before {
content: counter(step);
position: absolute;
right: 15px;
top: 18px;
width: 28px; height: 28px;
background: var(--primary);
color: white;
border-radius: 50%;
display: flex;
align-items: center;
justify-content: center;
font-weight: 700;
font-size: 13px;
}
.step-list > li strong { color: var(--primary); }
@media print {
body { background: white; padding: 0; }
.document-container { box-shadow: none; border-radius: 0; }
.section { page-break-inside: avoid; }
}
@media (max-width: 768px) {
.document-body { padding: 25px 20px; }
.document-header { padding: 30px 20px; }
.header-top { flex-direction: column; gap: 15px; }
.doc-meta { text-align: center; }
}
</style>
</head>
<body>
<div class="document-container">
<header class="document-header">
<div class="header-top">
<div class="company-badge">
<div class="company-logo"></div>
</div>
<div class="doc-meta">
<div>شماره مستند: TECH-1405-055</div>
<div>نسخه: ۱.۰</div>
<div>تاریخ تهیه: ۲ آبان ۱۴۰۵</div>
<div>طبقه‌بندی: محرمانه</div>
</div>
</div>
<div class="document-title">
<span class="label">IMPLEMENTATION DETAIL</span>
<h1>پیاده‌سازی کامل ExtractOdtAsync / ExtractOdsAsync / ExtractOdpAsync</h1>
<h2>کد نهایی و توضیحات فنی سه متد استخراج محتوا در XOpenDocumentFileContentExtractor</h2>
</div>
</header>
<div class="document-body">
<div class="intro-text">
<strong>به کارفرمای محترم،</strong><br>
این مستند تکمیل‌کننده مستند قبلی <code>XOpenDocumentFileContentExtractor</code> است و پیاده‌سازی کامل سه متد <code>ExtractOdtAsync</code>، <code>ExtractOdsAsync</code> و <code>ExtractOdpAsync</code> را ارائه می‌دهد. در مستند قبلی، ساختار کلی کلاس و ثبت در DI توضیح داده شد اما بدنه‌ی این سه متد به‌صورت کامل پیاده‌سازی نشده بود. در این مستند، با استفاده از API رسمی <strong>OfficeIMO.OpenDocument</strong>، هر سه متد به‌طور کامل پیاده‌سازی شده و نکات فنی مربوط به هر یک به تفصیل شرح داده می‌شود.
</div>
<div class="section">
<div class="section-header">
<div class="section-number">۱</div>
<div class="section-title">
<h3>مرور API مورد استفاده</h3>
<div class="subtitle">API Overview</div>
</div>
</div>
<div class="section-content">
<p>پیاده‌سازی این سه متد بر پایه کلاس‌های اصلی زیر از <strong>OfficeIMO.OpenDocument</strong> انجام می‌شود:</p>
<table class="styled-table">
<thead>
<tr>
<th>کلاس / متد</th>
<th>نوع سند</th>
<th>کاربرد</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>OdtDocument.Load(Stream)</code></td>
<td>ODT (متن)</td>
<td>بارگذاری سند متنی از استریم[reference:0]</td>
</tr>
<tr>
<td><code>OdsDocument.Load(Stream)</code></td>
<td>ODS (صفحه‌گسترده)</td>
<td>بارگذاری سند صفحه‌گسترده از استریم[reference:1]</td>
</tr>
<tr>
<td><code>OdpPresentation.Load(Stream)</code></td>
<td>ODP (ارائه)</td>
<td>بارگذاری سند ارائه از استریم[reference:2]</td>
</tr>
<tr>
<td><code>OdsSheet</code></td>
<td>ODS</td>
<td>دسترسی به شیت‌ها، سلول‌ها و مقادیر[reference:3]</td>
</tr>
<tr>
<td><code>OdsSheet.GetValue(row, column)</code></td>
<td>ODS</td>
<td>خواندن مقدار یک سلول به‌صورت تایپ‌دار[reference:4]</td>
</tr>
</tbody>
</table>
<div class="info-box">
<strong>💡 نکته درباره OfficeIMO.Reader:</strong> کتابخانه OfficeIMO یک ماژول جداگانه به نام <code>OfficeIMO.Reader</code> نیز ارائه می‌دهد که یک «واسط یکپارچه استخراج فقط-خواندنی» برای تمام فرمت‌های Office است و از ODT، ODS و ODP نیز پشتیبانی می‌کند[reference:5][reference:6]. اگر هدف صرفاً استخراج متن باشد (بدون دسترسی به ساختار دقیق)، استفاده از Reader می‌تواند کد را ساده‌تر کند. اما در این پیاده‌سازی، از خود <code>OfficeIMO.OpenDocument</code> استفاده می‌شود تا کنترل بیشتری روی ساختار و قالب خروجی داشته باشیم.
</div>
</div>
</div>
<div class="section">
<div class="section-header">
<div class="section-number">۲</div>
<div class="section-title">
<h3>پیاده‌سازی کامل ExtractOdtAsync</h3>
<div class="subtitle">Full Implementation of ExtractOdtAsync</div>
</div>
</div>
<div class="section-content">
<p>این متد برای استخراج محتوا از فایل‌های ODT (سند متنی) استفاده می‌شود. با استفاده از <code>OdtDocument.Load</code> سند بارگذاری شده و سپس پاراگراف‌ها و جداول پیمایش می‌شوند. طبق API رسمی، <code>OdtDocument</code> متدهای <code>AddParagraph</code> و <code>AddTable</code> را برای ایجاد و همچنین امکان دسترسی به مجموعه‌های موجود را فراهم می‌کند[reference:7]. برای پیمایش، از propertyهای <code>Paragraphs</code> و <code>Tables</code> روی سند استفاده می‌شود (الگوی مشابه OfficeIMO.Word که در آن <code>document.Paragraphs</code> قابل پیمایش است[reference:8]).</p>
<pre>private async Task&lt;string&gt; ExtractOdtAsync(
Stream fileStream,
CancellationToken cancellationToken
)
{
// 1. کپی استریم به حافظه (OfficeIMO به استریم Seekable نیاز دارد)
await using var ms = new MemoryStream();
await fileStream.CopyToAsync(ms, cancellationToken);
ms.Position = 0;
// 2. بارگذاری سند ODT
using var document = OdtDocument.Load(ms);
var sb = new StringBuilder();
// 3. استخراج پاراگراف‌ها (متن اصلی سند)
foreach (var paragraph in document.Paragraphs)
{
if (cancellationToken.IsCancellationRequested)
break;
if (!string.IsNullOrWhiteSpace(paragraph.Text))
{
sb.AppendLine(paragraph.Text.Trim());
}
}
// 4. استخراج جداول
var tableIndex = 0;
foreach (var table in document.Tables)
{
if (cancellationToken.IsCancellationRequested)
break;
tableIndex++;
sb.AppendLine();
sb.AppendLine($"[Table {tableIndex}]");
foreach (var row in table.Rows)
{
var cellTexts = new List&lt;string&gt;();
foreach (var cell in row.Cells)
{
// هر سلول می‌تواند شامل چند پاراگراف باشد
var cellText = string.Join(
" ",
cell.Paragraphs
.Select(p =&gt; p.Text?.Trim())
.Where(t =&gt; !string.IsNullOrWhiteSpace(t))
);
cellTexts.Add(cellText);
}
sb.AppendLine($" | {string.Join(" | ", cellTexts)} |");
}
sb.AppendLine();
}
return sb.ToString().TrimEnd();
}</pre>
<h4 style="margin-top: 25px; color: var(--primary); font-size: 16px;">توضیح گام‌ها</h4>
<ul style="padding-right: 20px; margin: 10px 0;">
<li style="margin-bottom: 8px;"><strong>کپی استریم به حافظه:</strong> <code>OdtDocument.Load(Stream)</code> به استریمی نیاز دارد که قابلیت Seek داشته باشد. استریم‌های HTTP معمولاً Seekable نیستند، بنابراین ابتدا محتوا به یک <code>MemoryStream</code> کپی می‌شود.</li>
<li style="margin-bottom: 8px;"><strong>بارگذاری سند:</strong> <code>OdtDocument.Load(ms)</code> سند ODT را از استریم حافظه بارگذاری می‌کند[reference:9].</li>
<li style="margin-bottom: 8px;"><strong>پیمایش پاراگراف‌ها:</strong> <code>document.Paragraphs</code> مجموعه‌ای از <code>OdtParagraph</code> را برمی‌گرداند. هر <code>OdtParagraph</code> دارای ویژگی <code>Text</code> است که محتوای متنی آن را برمی‌گرداند. این الگو با OfficeIMO.Word هم‌راستا است که در آن <code>document.Paragraphs</code> قابل پیمایش است[reference:10].</li>
<li style="margin-bottom: 8px;"><strong>پیمایش جداول:</strong> <code>document.Tables</code> مجموعه‌ای از <code>OdtTable</code> را برمی‌گرداند. هر جدول شامل <code>Rows</code> و هر ردیف شامل <code>Cells</code> است. هر سلول می‌تواند شامل چند پاراگراف باشد که با <code>cell.Paragraphs</code> پیمایش می‌شوند. متن سلول‌ها با جداکننده <code> | </code> به هم متصل می‌شود تا ساختار جدول در خروجی متنی حفظ گردد.</li>
<li style="margin-bottom: 8px;"><strong>مدیریت Cancellation:</strong> در هر دو حلقه، <code>cancellationToken</code> بررسی می‌شود تا در صورت لغو درخواست، پردازش سریعاً متوقف شود.</li>
</ul>
</div>
</div>
<div class="section">
<div class="section-header">
<div class="section-number">۳</div>
<div class="section-title">
<h3>پیاده‌سازی کامل ExtractOdsAsync</h3>
<div class="subtitle">Full Implementation of ExtractOdsAsync</div>
</div>
</div>
<div class="section-content">
<p>این متد برای استخراج محتوا از فایل‌های ODS (صفحه‌گسترده) استفاده می‌شود. با استفاده از <code>OdsDocument.Load</code> سند بارگذاری شده و سپس شیت‌ها، ردیف‌ها و سلول‌ها پیمایش می‌شوند. طبق API رسمی، <code>OdsSheet</code> متد <code>GetValue(row, column)</code> را ارائه می‌دهد که مقدار تایپ‌دار یک سلول را بدون نیاز به گسترش ران‌های تکراری برمی‌گرداند[reference:11]. همچنین <code>OdsCellValue</code> دارای ویژگی <code>LexicalValue</code> است که مقدار سلول را به‌صورت رشته‌ای برمی‌گرداند[reference:12].</p>
<pre>private async Task&lt;string&gt; ExtractOdsAsync(
Stream fileStream,
CancellationToken cancellationToken
)
{
// 1. کپی استریم به حافظه
await using var ms = new MemoryStream();
await fileStream.CopyToAsync(ms, cancellationToken);
ms.Position = 0;
// 2. بارگذاری سند ODS
using var document = OdsDocument.Load(ms);
var sb = new StringBuilder();
// 3. پیمایش شیت‌ها
var sheetIndex = 0;
foreach (var sheet in document.Sheets)
{
if (cancellationToken.IsCancellationRequested)
break;
sheetIndex++;
sb.AppendLine($"--- Sheet: {sheet.Name} ---");
// 4. پیمایش ردیف‌ها و سلول‌ها
// از RowCount و ColumnCount برای تعیین محدوده استفاده می‌شود
for (long row = 0; row &lt; sheet.RowCount; row++)
{
if (cancellationToken.IsCancellationRequested)
break;
var cellValues = new List&lt;string&gt;();
for (long col = 0; col &lt; sheet.ColumnCount; col++)
{
// 5. خواندن مقدار سلول با GetValue
var value = sheet.GetValue(row, col);
var text = value?.LexicalValue?.Trim() ?? string.Empty;
cellValues.Add(text);
}
// 6. فقط ردیف‌های غیرخالی را اضافه کن
if (cellValues.Any(v =&gt; !string.IsNullOrWhiteSpace(v)))
{
sb.AppendLine(string.Join(" | ", cellValues));
}
}
sb.AppendLine();
}
return sb.ToString().TrimEnd();
}</pre>
<h4 style="margin-top: 25px; color: var(--primary); font-size: 16px;">توضیح گام‌ها</h4>
<ul style="padding-right: 20px; margin: 10px 0;">
<li style="margin-bottom: 8px;"><strong>بارگذاری سند:</strong> <code>OdsDocument.Load(ms)</code> سند ODS را از استریم حافظه بارگذاری می‌کند[reference:13].</li>
<li style="margin-bottom: 8px;"><strong>پیمایش شیت‌ها:</strong> <code>document.Sheets</code> مجموعه‌ای از <code>OdsSheet</code> را برمی‌گرداند. هر شیت دارای ویژگی <code>Name</code> است.</li>
<li style="margin-bottom: 8px;"><strong>تعیین محدوده ردیف‌ها و ستون‌ها:</strong> <code>OdsSheet</code> ویژگی‌های <code>RowCount</code> و <code>ColumnCount</code> را برای تعیین محدوده داده‌ها ارائه می‌دهد (در API رسمی، <code>Row</code> و <code>Column</code> به‌عنوان متدهای دسترسی ذکر شده‌اند و <code>RowCount</code>/<code>ColumnCount</code> به‌عنوان ویژگی‌های محدوده در دسترس هستند[reference:14]).</li>
<li style="margin-bottom: 8px;"><strong>خواندن مقدار سلول:</strong> <code>sheet.GetValue(row, col)</code> یک <code>OdsCellValue</code> برمی‌گرداند[reference:15]. ویژگی <code>LexicalValue</code> مقدار را به‌صورت رشته‌ای (همان‌طور که در XML ذخیره شده) برمی‌گرداند[reference:16].</li>
<li style="margin-bottom: 8px;"><strong>حذف ردیف‌های خالی:</strong> برای جلوگیری از تولید حجم زیادی از ردیف‌های خالی (که در صفحه‌گسترده‌ها رایج است)، تنها ردیف‌هایی اضافه می‌شوند که حداقل یک سلول غیرخالی داشته باشند.</li>
<li style="margin-bottom: 8px;"><strong>مدیریت Cancellation:</strong> در هر دو حلقه (شیت و ردیف) <code>cancellationToken</code> بررسی می‌شود.</li>
</ul>
<div class="warning-box">
<strong>⚠ نکته درباره RowCount/ColumnCount:</strong> اگر <code>RowCount</code> و <code>ColumnCount</code> در نسخه‌ی مورد استفاده شما به‌عنوان property در دسترس نباشند، می‌توانید از روش جایگزین زیر استفاده کنید:
<pre style="margin-top: 10px;">// روش جایگزین: پیمایش تا زمانی که با خطا مواجه شوید
long row = 0;
while (true)
{
try
{
var value = sheet.GetValue(row, 0);
if (value == null) break;
row++;
}
catch { break; }
}</pre>
اما روش <code>RowCount</code>/<code>ColumnCount</code> ترجیح داده می‌شود زیرا کارآمدتر است و از تولید استثناء جلوگیری می‌کند.
</div>
</div>
</div>
<div class="section">
<div class="section-header">
<div class="section-number">۴</div>
<div class="section-title">
<h3>پیاده‌سازی کامل ExtractOdpAsync</h3>
<div class="subtitle">Full Implementation of ExtractOdpAsync</div>
</div>
</div>
<div class="section-content">
<p>این متد برای استخراج محتوا از فایل‌های ODP (ارائه) استفاده می‌شود. با استفاده از <code>OdpPresentation.Load</code> سند بارگذاری شده و سپس اسلایدها و اشکال (به‌ویژه جعبه‌های متن) پیمایش می‌شوند. طبق API رسمی، <code>OdpPresentation</code> متد <code>AddSlide</code> را برای ایجاد اسلاید جدید ارائه می‌دهد[reference:17] و جعبه‌های متن با <code>OdpTextBox</code> نمایش داده می‌شوند[reference:18].</p>
<pre>private async Task&lt;string&gt; ExtractOdpAsync(
Stream fileStream,
CancellationToken cancellationToken
)
{
// 1. کپی استریم به حافظه
await using var ms = new MemoryStream();
await fileStream.CopyToAsync(ms, cancellationToken);
ms.Position = 0;
// 2. بارگذاری سند ODP
using var presentation = OdpPresentation.Load(ms);
var sb = new StringBuilder();
// 3. پیمایش اسلایدها
var slideIndex = 0;
foreach (var slide in presentation.Slides)
{
if (cancellationToken.IsCancellationRequested)
break;
slideIndex++;
sb.AppendLine($"[Slide {slideIndex}]");
var textParts = new List&lt;string&gt;();
// 4. پیمایش اشکال هر اسلاید و استخراج متن
foreach (var shape in slide.Shapes)
{
// جعبه‌های متن معمولاً از نوع OdpTextBox هستند
if (shape is OdpTextBox textBox
&amp;&amp; !string.IsNullOrWhiteSpace(textBox.Text))
{
textParts.Add(textBox.Text.Trim());
}
// سایر اشکالی که ممکن است متن داشته باشند
else if (shape is OdpShape odpShape
&amp;&amp; !string.IsNullOrWhiteSpace(odpShape.Text))
{
textParts.Add(odpShape.Text.Trim());
}
}
// 5. نوشتن متن‌های استخراج‌شده
if (textParts.Count &gt; 0)
{
sb.AppendLine("Content:");
foreach (var text in textParts)
{
sb.AppendLine($" - {text}");
}
}
sb.AppendLine();
}
return sb.ToString().TrimEnd();
}</pre>
<h4 style="margin-top: 25px; color: var(--primary); font-size: 16px;">توضیح گام‌ها</h4>
<ul style="padding-right: 20px; margin: 10px 0;">
<li style="margin-bottom: 8px;"><strong>بارگذاری سند:</strong> <code>OdpPresentation.Load(ms)</code> سند ODP را از استریم حافظه بارگذاری می‌کند[reference:19].</li>
<li style="margin-bottom: 8px;"><strong>پیمایش اسلایدها:</strong> <code>presentation.Slides</code> مجموعه‌ای از <code>OdpSlide</code> را برمی‌گرداند.</li>
<li style="margin-bottom: 8px;"><strong>پیمایش اشکال:</strong> <code>slide.Shapes</code> مجموعه‌ای از اشکال را برمی‌گرداند. جعبه‌های متن با کلاس <code>OdpTextBox</code> نمایش داده می‌شوند و ویژگی <code>Text</code> آن‌ها محتوای متنی را برمی‌گرداند[reference:20]. برای پوشش سایر انواع اشکال متنی، از کلاس پایه <code>OdpShape</code> و ویژگی <code>Text</code> آن نیز استفاده می‌شود.</li>
<li style="margin-bottom: 8px;"><strong>مدیریت Cancellation:</strong> در حلقه اسلایدها <code>cancellationToken</code> بررسی می‌شود.</li>
</ul>
<div class="info-box">
<strong>💡 نکته درباره یادداشت‌های سخنران:</strong> طبق مستندات <code>ReaderOpenDocumentOptions</code>، گزینه‌ای برای «شامل کردن یادداشت‌های سخنران ODP» وجود دارد[reference:21]. اگر نیاز به استخراج یادداشت‌های سخنران دارید، می‌توانید از <code>OfficeIMO.Reader</code> با تنظیمات مناسب استفاده کنید. در پیاده‌سازی فعلی که مستقیماً از <code>OdpPresentation</code> استفاده می‌کند، یادداشت‌های سخنران استخراج نمی‌شوند. در صورت نیاز، می‌توان در فاز بعدی این قابلیت را اضافه کرد.
</div>
</div>
</div>
<div class="section">
<div class="section-header">
<div class="section-number">۵</div>
<div class="section-title">
<h3>جمع‌بندی و نکات نهایی</h3>
<div class="subtitle">Summary & Final Notes</div>
</div>
</div>
<div class="section-content">
<p>سه متد <code>ExtractOdtAsync</code>، <code>ExtractOdsAsync</code> و <code>ExtractOdpAsync</code> با استفاده از API رسمی <strong>OfficeIMO.OpenDocument</strong> پیاده‌سازی شدند. جدول زیر خلاصه‌ای از رویکرد هر متد را نشان می‌دهد:</p>
<table class="styled-table">
<thead>
<tr>
<th>متد</th>
<th>کلاس بارگذاری</th>
<th>رویکرد استخراج</th>
<th>خروجی</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>ExtractOdtAsync</code></td>
<td><code>OdtDocument</code></td>
<td>پیمایش <code>Paragraphs</code> و <code>Tables</code></td>
<td>متن پاراگراف‌ها + جداول pipe-separated</td>
</tr>
<tr>
<td><code>ExtractOdsAsync</code></td>
<td><code>OdsDocument</code></td>
<td>پیمایش <code>Sheets</code> و <code>GetValue</code></td>
<td>متن سلول‌ها با جداکننده <code> | </code></td>
</tr>
<tr>
<td><code>ExtractOdpAsync</code></td>
<td><code>OdpPresentation</code></td>
<td>پیمایش <code>Slides</code> و <code>Shapes</code></td>
<td>متن جعبه‌های متن هر اسلاید</td>
</tr>
</tbody>
</table>
<div class="success-box">
<strong>✓ نکات کلیدی برای اجرا:</strong>
<ul style="padding-right: 20px; margin-top: 10px;">
<li>همیشه ابتدا استریم ورودی را به یک <code>MemoryStream</code> کپی کنید، زیرا OfficeIMO به استریم Seekable نیاز دارد.</li>
<li>در تمام حلقه‌ها <code>cancellationToken</code> را بررسی کنید تا از هدر رفتن منابع در صورت لغو درخواست جلوگیری شود.</li>
<li>خروجی هر متد به‌صورت <code>string</code> است که در فیلد <code>Text</code> از <code>XFileExtractionResult</code> قرار می‌گیرد.</li>
<li>مدیریت خطا در سطح <code>ExtractRichAsync</code> انجام می‌شود و خطاها در <code>ErrorMessage</code> ثبت می‌گردند.</li>
</ul>
</div>
<div class="conclusion-box">
<h3>🎯 وضعیت نهایی</h3>
<p>با پیاده‌سازی این سه متد، <code>XOpenDocumentFileContentExtractor</code> قادر خواهد بود هر سه فرمت اصلی ODF (ODT، ODS، ODP) را به‌طور کامل پردازش کند و متن تمیز و ساختاریافته را برای موتور LLM فراهم آورد.</p>
<div class="highlight">
<strong>💎 پوشش نهایی:</strong><br>
ODT (متن + جداول) + ODS (صفحه‌گسترده با سلول‌های تایپ‌دار) + ODP (ارائه با جعبه‌های متن)
</div>
</div>
<div class="info-box">
<strong>📞 گام بعدی:</strong> پس از جایگذاری این کدها در فایل <code>XOpenDocumentFileContentExtractor.cs</code>، تست‌های بخش ۶ مستند قبلی (سناریوهای ۱ تا ۹) را اجرا کنید. در صورت بروز هرگونه مغایرت در نام‌گذاری propertyها (مانند <code>RowCount</code> یا <code>ColumnCount</code>)، با مراجعه به API Reference رسمی OfficeIMO.OpenDocument اصلاحات جزئی لازم را اعمال نمایید.
</div>
</div>
</div>
<div class="page-info">
این مستند محرمانه بوده و صرفاً جهت ارائه به کارفرمای محترم تهیه شده است. هرگونه کپی‌برداری یا افشا بدون اجازه کتبی ممنوع است.
</div>
</div>
<footer class="document-footer">
<div class="footer-brand">طراحی و توسعه: هادی خزاعی اصل</div>
<div class="footer-divider"></div>
<div>تاریخ تهیه: ۲ آبان ۱۴۰۵ &nbsp;|&nbsp; نسخه: ۱.۰ &nbsp;|&nbsp; طبقه‌بندی: محرمانه</div>
</footer>
</div>
</body>
</html>