1. محصولات
  2.   ویرایشگر
  3.   .NET
  4.   FileFormat.Words for .NET
 
  

API منبع باز دات نت برای اسناد پردازش کلمه در سی شارپ و ASP.NET

ایجاد، باز کردن و به‌روزرسانی پاراگراف‌ها، تصاویر، جداول و سایر محتوای اسناد Microsoft Word از داخل برنامه‌های NET خود با استفاده از FileFormat.Words for .NET

FileFormat.Words برای .NET API چیست؟

FileFormat.Words for .NET یک API .NET منبع باز برای کار با فایل های Microsoft Word است. می توان از آن در برنامه های دات نت توسعه یافته در سی شارپ و ASP.NET برای اسناد پردازش ورد مانند ایجاد، باز کردن و اصلاح اسناد Word استفاده کرد. API با بسته بندی موتورهای متن باز مختلف از جمله Microsoft OpenXML SDK توسعه یافته است. شما می توانید برنامه های دات نت را برای تولید گزارش بسازید، گردش کار اسناد را خودکار کنید و سیستم های مدیریت اسناد را ارتقا دهید. FileFormat.Words برای دات نت ادغام قابلیت پردازش اسناد MS Word را ساده می کند.

FileFormat.Words for .NET API - ویژگی های کلیدی

در زیر برخی از ویژگی های اصلی FileFormat.Words برای .NET API آورده شده است:

  • پردازش جامع سند: اسناد Word را در برنامه‌های NET ایجاد، ویرایش، تبدیل و رندر کنید.
  • پشتیبانی از فرمت فایل: از DOC، DOCX، RTF، HTML، PDF، EPUB، ODT و موارد دیگر پشتیبانی می‌کند.
  • دستکاری سند: صفحات، بخش‌ها، سرصفحه‌ها، پاورقی‌ها، نشانک‌ها و فهرست مطالب را اضافه یا حذف کنید.
  • پردازش با وفاداری بالا: اسناد را با دقت بالا به تصاویر یا قالب‌های طرح‌بندی ثابت (PDF، XPS) ارائه دهید.
  • دستکاری متن: متن را پیدا و جایگزین کنید، متن را قالب‌بندی کنید، متن را استخراج کنید و سبک‌های سفارشی را اعمال کنید.
  • ادغام و گزارش نامه ایمیل: از ادغام نامه برای ایجاد اسناد از الگوها و منابع داده پشتیبانی می کند.
  • عناصر سند پیشرفته: جداول، تصاویر، اشکال، نمودارها و اشیاء SmartArt را درج کنید.
  • امضاهای دیجیتال و رمزگذاری: امضای دیجیتالی، محافظت از رمز عبور، و رمزگذاری اسناد را اضافه کنید.
  • ماکروها و اسکریپت‌نویسی: ماکروها (VBA) را حفظ و مدیریت کنید، که امکان انجام وظایف پیچیده اتوماسیون را فراهم می‌کند.
  • قابلیت‌های تبدیل: بین قالب‌های Word و انواع فایل‌های مختلف مانند PDF و HTML تبدیل کنید.
  • پشتیبانی Cloud: برای دستکاری اسناد مبتنی بر ابر، با Aspose Cloud ادغام شود.
  • پشتیبانی جامع API: مستندات گسترده API، نمونه‌ها و پشتیبانی انجمن.
GitHub

آمار GitHub

نام: FileFormat.Words-for-.NET
زبان: C#
ستاره ها: 29
چنگال: 7
مجوز: MIT License
آخرین به روز رسانی مخزن در 2025-03-18

شروع به کار با FileFormat.Words برای NET API

می توانید کتابخانه FileFormat.Words برای دات نت را از GitHub یا Nugget دانلود کنید.

نصب و راه اندازی

نصب FileFormat.Words برای دات نت ساده است و مطابق شکل زیر می توان آن را از ناگت انجام داد:

نصب FileFormat.Words برای NET API


NuGet\Install-Package FileFormat.Words

نمونه کد برای FileFormat.Words برای NET API

FileFormat.Words for .NET یک API قدرتمند است که ویژگی های غنی را برای کار با اسناد Word از جمله فرمت های فایل DOC و DOCX فراهم می کند. این قابلیت پردازش کلمه غنی مانند ایجاد یک سند از ابتدا، باز کردن یک سند موجود و به روز رسانی محتوای آن، و تبدیل سند به فرمت های مختلف مانند PDF را ارائه می دهد. API را می توان به راحتی در برنامه های C# و ASP.NET بدون نیاز به وارد شدن به جزئیات اساسی فرمت های فایل استفاده کرد.

چگونه یک فایل Word Document DOCX در دات نت ایجاد کنیم؟

FileFormat.Words for .NET API به شما امکان می دهد یک سند DOCX را از ابتدا از داخل برنامه C# یا ASP.NET خود تنها با چند خط کد ایجاد کنید. می توانید از کد منبع زیر برای ایجاد یک سند خالی با استفاده از API استفاده کنید:

/// <summary>
/// Creates a new Word Document with structured content using
/// <a href="https://www.nuget.org/packages/FileFormat.Words">FileFormat.Words</a>.
/// Generates paragraphs with heading styles defined by the Word document template.
/// Adds normal paragraphs under each heading paragraph, including text runs with various fonts as per the template.
/// Saves the newly created Word Document.
/// </summary>
/// <param name="documentDirectory">
/// The directory where the Word Document will be saved (default is the root of your project).
/// </param>
/// <param name="filename">
/// The name of the Word Document file (default is "WordParagraphs.docx") to be saved to the directlry
/// defined by documentDirectory..
/// </param>
public void CreateWordParagraphs(string documentDirectory = docsDirectory, string filename = "WordParagraphs.docx")
{
try
{
// Initialize a new word document with the default template
var doc = new FileFormat.Words.Document();
System.Console.WriteLine("Word Document with default template initialized");
// Initialize the body with the new document
var body = new FileFormat.Words.Body(doc);
System.Console.WriteLine("Body of the Word Document initialized");
// Get all paragraph styles
var paragraphStyles = doc.GetElementStyles().ParagraphStyles;
System.Console.WriteLine("Paragraph styles loaded");
// Get all fonts defined by FontTable and Theme
var fonts = doc.GetElementStyles().TableFonts;
var fontsTheme = doc.GetElementStyles().ThemeFonts;
System.Console.WriteLine("Fonts defined by FontsTable and Theme loaded");
// Merge all fonts
fonts.AddRange(fontsTheme);
System.Console.WriteLine("All Fonts merged");
// Create Headings Paragraph and append to the body.
foreach (var paragraphStyle in paragraphStyles.Where(style => !style.Contains("Normal")))
{
var paragraphWithStyle = new FileFormat.Words.IElements.Paragraph { Style = paragraphStyle };
paragraphWithStyle.AddRun(new Run {
Text = $"Paragraph with {paragraphStyle} Style"
});
System.Console.WriteLine($"Styled Paragraph with {paragraphStyle} Created");
body.AppendChild(paragraphWithStyle);
System.Console.WriteLine($"Styled Paragraph with {paragraphStyle} Appended to Word Document Body");
// Create Normal Paragraph and include text runs with various fonts as per the template.
var paragraphNormal = new FileFormat.Words.IElements.Paragraph();
System.Console.WriteLine("Normal Paragraph Created");
paragraphNormal.AddRun(new FileFormat.Words.IElements.Run
{
Text = $"Text in normal paragraph with default font and size but with bold " +
$"and underlined Gray Color ",
Color = FileFormat.Words.IElements.Colors.Gray,
Bold = true,
Underline = true
});
foreach (var font in fonts)
{
paragraphNormal.AddRun(new Run
{
Text = $"Text in normal paragraph with font {font} and size 10 but with default " +
$"color, bold, and underlines. ",
FontFamily = font,
FontSize = 10
});
}
System.Console.WriteLine("All Runs with all fonts Created for Normal Paragraph");
body.AppendChild(paragraphNormal);
System.Console.WriteLine($"Normal Paragraph Appended to Word Document Body");
}
// Save the newly created Word Document.
doc.Save($"{documentDirectory}/{filename}");
System.Console.WriteLine($"Word Document {filename} Created. Please check directory: "+
$"{System.IO.Path.GetFullPath(documentDirectory)}");
}
catch (System.Exception ex)
{
throw new FileFormat.Words.FileFormatException("An error occurred.", ex);
}
}

چگونه یک فایل DOCX موجود را در سی شارپ بخوانیم؟

FileFormat.Words برای دات نت به شما امکان می دهد یک سند Word موجود DOCX را در برنامه C# خود بخوانید. همانطور که در نمونه کد زیر نشان داده شده است، می توانید سند را در برنامه خود بارگذاری کنید، محتوای آن را تغییر دهید و سپس با استفاده از API آن را در دیسک ذخیره کنید.

/// <summary>
/// Loads a Word Document with structured content using
/// <a href="https://www.nuget.org/packages/FileFormat.Words">FileFormat.Words</a>.
/// Traverses paragraphs and displays associated styles as defined by the Word document template.
/// Traverses through each run (text fragment) within each paragraph and displays fragment values.
/// </summary>
/// <param name="documentDirectory">
/// The directory where the Word Document to load is present
/// (default is the root of your project).
/// </param>
/// <param name="filename">
/// The name of the Word Document file to load (default is "WordParagraphs.docx" - please replace it
/// with your word document present at the directory defined by documentDirectory).
/// </param>
public void ReadWordParagraphs(string documentDirectory = docsDirectory, string filename = "WordParagraphs.docx")
{
try
{
// Load the Word Document
var doc = new FileFormat.Words.Document($"{documentDirectory}/{filename}");
var body = new FileFormat.Words.Body(doc);
var num = 0;
System.Console.WriteLine("Paragraphs Plain Text");
// Traverse and display paragraphs with plain text
foreach (var paragraph in body.Paragraphs)
{
num++;
System.Console.WriteLine($" Paragraph Number: {num}");
System.Console.WriteLine($" Paragraph Style: {paragraph.Style}");
System.Console.WriteLine($" Paragraph Text: {paragraph.Text}");
}
num = 0;
var runnum = 0;
System.Console.WriteLine("Paragraphs with formatting");
// Traverse and display paragraphs with formatting details
foreach (var paragraph in body.Paragraphs)
{
num++;
System.Console.WriteLine($" Paragraph Number: {num}");
System.Console.WriteLine($" Paragraph Style: {paragraph.Style}");
// Traverse and display runs within each paragraph
foreach (var run in paragraph.Runs)
{
runnum++;
System.Console.WriteLine($" Text fragment ({num} - {runnum}): {run.Text}");
System.Console.WriteLine($" Font fragment ({num} - {runnum}): {run.FontFamily}");
System.Console.WriteLine($" Color fragment ({num} - {runnum}): {run.Color}");
System.Console.WriteLine($" Size fragment ({num} - {runnum}): {run.FontSize}");
System.Console.WriteLine($" Bold fragment ({num} - {runnum}): {run.Bold}");
System.Console.WriteLine($" Italic fragment ({num} - {runnum}): {run.Italic}");
System.Console.WriteLine($" Underline fragment ({num} - {runnum}): {run.Underline}");
}
runnum = 0;
}
}
catch (System.Exception ex)
{
throw new FileFormat.Words.FileFormatException("An error occurred.", ex);
}
}

چگونه جداول را در یک سند Word در دات نت ایجاد کنیم؟

FileFormat.Words برای NET SDK افزودن جداول به سند Word DOCX را بسیار راحت می کند. می‌توانید از API برای ایجاد یک جدول با سطرها و ستون‌های متعدد و اضافه کردن محتویات به سند مانند نمونه کد زیر استفاده کنید.

/// <summary>
/// Creates a new Word Document with structured content using
/// <a href="https://www.nuget.org/packages/FileFormat.Words">FileFormat.Words</a>.
/// Generates 5(rows) x 3(cols) tables with table styles defined by the Word document template.
/// Appends each table to the body of the word document.
/// Saves the newly created word document.
/// </summary>
/// <param name="documentDirectory">
/// The directory where the Word Document will be saved (default is root of your project).
/// </param>
/// <param name="filename">
/// The name of the Word Document file (default is "WordTables.docx").
/// </param>
public void CreateWordDocumentWithTables(string documentDirectory = "../../../",
string filename = "WordTables.docx")
{
try
{
// Initialize a new word document with the default template
var doc = new FileFormat.Words.Document();
System.Console.WriteLine("Word Document with default template initialized");
// Initialize the body with the new document
var body = new FileFormat.Words.Body(doc);
System.Console.WriteLine("Body of the Word Document initialized");
// Get all table styles
var tableStyles = doc.GetElementStyles().TableStyles;
System.Console.WriteLine("Table styles loaded");
// Create Headings Paragraph and append to the body.
foreach (var tableStyle in tableStyles)
{
var table = new FileFormat.Words.IElements.Table(5,3);
table.Style = tableStyle;
table.Column.Width = 2500;
var rowNumber = 0;
var columnNumber = 0;
var para = new FileFormat.Words.IElements.Paragraph();
para.Style = FileFormat.Words.IElements.Headings.Heading1;
para.AddRun(new FileFormat.Words.IElements.Run {
Text = $"Table With Style '{tableStyle}' : "
});
body.AppendChild(para);
foreach (var row in table.Rows)
{
rowNumber++;
foreach(var cell in row.Cells)
{
columnNumber++;
para = new FileFormat.Words.IElements.Paragraph();
para.AddRun(new FileFormat.Words.IElements.Run {
Text = $"Row {rowNumber} Column {columnNumber}"
});
cell.Paragraphs.Add(para);
}
columnNumber = 0;
}
body.AppendChild(table);
System.Console.WriteLine($"Table with style {tableStyle} created and appended");
}
// Save the newly created Word Document.
doc.Save($"{documentDirectory}/{filename}");
System.Console.WriteLine($"Word Document {filename} Created. Please check directory: "+
$"{System.IO.Path.GetFullPath(documentDirectory)}");
}
catch (System.Exception ex)
{
throw new FileFormat.Words.FileFormatException("An error occurred.", ex);
}
}

FileFormat.Words برای منابع NET

نتیجه گیری

محصولات مشابه

 فارسی