צור מסמכי PDF או Word ב C#

צור מסמך חדש כמעט בכל פורמט באופן פרוגרמטי באמצעות ספריית הנאמנות הגבוהה שלנו C#

באמצעות ממשק API לתכנות שלנו, מפתחי .NET יכולים ליצור בקלות מסמך ב PDF, DOC, DOCX, HTML, EPUB ופורמטים רבים אחרים עם מספר שורות קוד בלבד.

הצג את קטע הקוד

צור מסמך באמצעות C#

עם ה API החזק הנתון, מפתחי C# יכולים ליצור מסמכים כמעט בכל פורמט. כדי לעשות זאת, עליך לבצע מספר שלבים באמצעות ספריית .NET שלנו:

  1. הוסף שם קובץ
  2. התחל ליצור מסמך באמצעות C#
  3. שמור את המסמך שנוצר בפורמט שנבחר

ראוי לציין שמסמך ריק אמור מבחינה טכנית להכיל פסקה אחת, כך שכשאתה יוצר מסמך באופן תוכנתי, תקבל בדיוק את מבנה המסמך הבסיסי הזה.

שים לב שאתה יכול להוסיף תוכן באופן מיידי למסמך חדש שנוצר. כך, תקבלו לא רק מסמך ריק, אלא מסמך המכיל את התוכן הדרוש. למידע נוסף על אופן עריכת מסמך, עיין בדף העריכה.

צור מסמך ב C# באופן פרוגרמטי

ספריית .NET הנתונה מאפשרת לך ליצור מסמך באופן פרוגרמטי בכל פורמט נתמך - PDF, DOCX, DOC, RTF, ODT, EPUB, HTML ואחרים.

נסה את הפונקציונליות החזקה שלנו וראה כיצד ליצור מסמך בפורמטים מסוימים באמצעות הדוגמה הבאה:

צור מסמך חדש באמצעות C#
בחר את פורמט היעד מהרשימה
הפעל קוד
using Aspose.Words;

var doc = new Document();
var builder = new DocumentBuilder(doc);

var font = builder.Font;
font.Name = "Courier New";            
font.Color = Color.Blue;
font.Size = 36;
font.HighlightColor = Color.Yellow;

builder.Write("Morbi enim nunc faucibus a.");

doc.Save("Output.docx");
using Aspose.Words; var doc = new Document(); var builder = new DocumentBuilder(doc); var firstRun = new Run(doc, "Proin eros metus, sagittis sed. "); var secondRun = new Run(doc, "Morbi enim nunc faucibus a."); doc.FirstSection.Body.FirstParagraph.AppendChild(firstRun); doc.FirstSection.Body.FirstParagraph.AppendChild(secondRun); builder.MoveTo(secondRun); builder.StartBookmark("Aspose bookmark"); // אם NextSibling הוא null, סביר להניח שזו Run האחרונה בפסקה. if (secondRun.NextSibling != null) builder.MoveTo(secondRun.NextSibling); else builder.MoveTo(secondRun.ParentParagraph); builder.EndBookmark("Aspose bookmark"); doc.Save("Output.docx"); using Aspose.Words; var doc = new Document(); var builder = new DocumentBuilder(doc); var firstRun = new Run(doc, "Proin eros metus, sagittis sed. "); var secondRun = new Run(doc, "Morbi enim nunc faucibus a."); doc.FirstSection.Body.FirstParagraph.AppendChild(firstRun); doc.FirstSection.Body.FirstParagraph.AppendChild(secondRun); builder.MoveTo(secondRun); builder.StartBookmark("Aspose bookmark"); // אם NextSibling הוא null, סביר להניח שזו Run האחרונה בפסקה. if (secondRun.NextSibling != null) builder.MoveTo(secondRun.NextSibling); else builder.MoveTo(secondRun.ParentParagraph); builder.EndBookmark("Aspose bookmark"); var saveOptions = new PdfSaveOptions(); saveOptions.OutlineOptions.BookmarksOutlineLevels.Add("Aspose bookmark", 1); doc.Save("Output.docx", saveOptions);
using Aspose.Words;

var doc = new Document();

var run = new Run(doc, "Proin eros metus, sagittis sed.");
var para = doc.FirstSection.Body.FirstParagraph;
para.AppendChild(run);

var comment = new Comment(doc)
{
    Author = "John Doe",
    Initial = "JD",
    DateTime = DateTime.Now
};
comment.SetText("Quisque fringilla leo.");            

var commentRangeStart = new CommentRangeStart(doc, comment.Id);
var commentRangeEnd = new CommentRangeEnd(doc, comment.Id);

run.ParentNode.InsertBefore(commentRangeStart, run);
run.ParentNode.InsertAfter(commentRangeEnd, run);
commentRangeEnd.ParentNode.InsertAfter(comment, commentRangeEnd);

comment.AddReply("Jane Doe", "JD", DateTime.Now, "Pellentesque vel sapien justo.");

doc.Save("Output.docx");
using Aspose.Words; var doc = new Document(); var builder = new DocumentBuilder(doc); var firstRun = new Run(doc, "Proin eros metus, sagittis sed. "); var secondRun = new Run(doc, "Morbi enim nunc faucibus a."); doc.FirstSection.Body.FirstParagraph.AppendChild(firstRun); doc.FirstSection.Body.FirstParagraph.AppendChild(secondRun); builder.MoveTo(secondRun); builder.StartBookmark("Aspose bookmark"); // אם NextSibling הוא null, סביר להניח שזו Run האחרונה בפסקה. if (secondRun.NextSibling != null) builder.MoveTo(secondRun.NextSibling); else builder.MoveTo(secondRun.ParentParagraph); builder.EndBookmark("Aspose bookmark"); doc.Save("Output.docx"); using Aspose.Words; var doc = new Document(); var builder = new DocumentBuilder(doc); var firstRun = new Run(doc, "Proin eros metus, sagittis sed. "); var secondRun = new Run(doc, "Morbi enim nunc faucibus a."); doc.FirstSection.Body.FirstParagraph.AppendChild(firstRun); doc.FirstSection.Body.FirstParagraph.AppendChild(secondRun); builder.MoveTo(secondRun); builder.StartBookmark("Aspose bookmark"); // אם NextSibling הוא null, סביר להניח שזו Run האחרונה בפסקה. if (secondRun.NextSibling != null) builder.MoveTo(secondRun.NextSibling); else builder.MoveTo(secondRun.ParentParagraph); builder.EndBookmark("Aspose bookmark"); var saveOptions = new PdfSaveOptions(); saveOptions.OutlineOptions.BookmarksOutlineLevels.Add("Aspose bookmark", 1); doc.Save("Output.docx", saveOptions);
using Aspose.Words;

var doc = new Document();
var builder = new DocumentBuilder(doc);

var firstRun = new Run(doc, "Proin eros metus, sagittis sed. ");
var secondRun = new Run(doc, "Morbi enim nunc faucibus a.");
doc.FirstSection.Body.FirstParagraph.AppendChild(firstRun);
doc.FirstSection.Body.FirstParagraph.AppendChild(secondRun);

builder.MoveTo(secondRun);
builder.StartBookmark("Aspose bookmark");
// אם NextSibling הוא null, סביר להניח שזו Run האחרונה בפסקה.
if (secondRun.NextSibling != null)            
    builder.MoveTo(secondRun.NextSibling);            
else            
    builder.MoveTo(secondRun.ParentParagraph);            
builder.EndBookmark("Aspose bookmark");

doc.Save("Output.docx");
using Aspose.Words; var doc = new Document(); var builder = new DocumentBuilder(doc); var firstRun = new Run(doc, "Proin eros metus, sagittis sed. "); var secondRun = new Run(doc, "Morbi enim nunc faucibus a."); doc.FirstSection.Body.FirstParagraph.AppendChild(firstRun); doc.FirstSection.Body.FirstParagraph.AppendChild(secondRun); builder.MoveTo(secondRun); builder.StartBookmark("Aspose bookmark"); // אם NextSibling הוא null, סביר להניח שזו Run האחרונה בפסקה. if (secondRun.NextSibling != null) builder.MoveTo(secondRun.NextSibling); else builder.MoveTo(secondRun.ParentParagraph); builder.EndBookmark("Aspose bookmark"); doc.Save("Output.docx"); using Aspose.Words; var doc = new Document(); var builder = new DocumentBuilder(doc); var firstRun = new Run(doc, "Proin eros metus, sagittis sed. "); var secondRun = new Run(doc, "Morbi enim nunc faucibus a."); doc.FirstSection.Body.FirstParagraph.AppendChild(firstRun); doc.FirstSection.Body.FirstParagraph.AppendChild(secondRun); builder.MoveTo(secondRun); builder.StartBookmark("Aspose bookmark"); // אם NextSibling הוא null, סביר להניח שזו Run האחרונה בפסקה. if (secondRun.NextSibling != null) builder.MoveTo(secondRun.NextSibling); else builder.MoveTo(secondRun.ParentParagraph); builder.EndBookmark("Aspose bookmark"); var saveOptions = new PdfSaveOptions(); saveOptions.OutlineOptions.BookmarksOutlineLevels.Add("Aspose bookmark", 1); doc.Save("Output.docx", saveOptions);
using Aspose.Words;

var doc = new Document();
var builder = new DocumentBuilder(doc);

Shape shape = builder.InsertChart(ChartType.Pie, 432, 252);
Chart chart = shape.Chart;
chart.Title.Text = "Demo Chart";

chart.Series.Clear();
chart.Series.Add("Series 1",
    new string[] { "Category1", "Category2", "Category3" },
    new double[] { 2.7, 3.2, 0.8 });

doc.Save("Output.docx");
using Aspose.Words; var doc = new Document(); var builder = new DocumentBuilder(doc); var firstRun = new Run(doc, "Proin eros metus, sagittis sed. "); var secondRun = new Run(doc, "Morbi enim nunc faucibus a."); doc.FirstSection.Body.FirstParagraph.AppendChild(firstRun); doc.FirstSection.Body.FirstParagraph.AppendChild(secondRun); builder.MoveTo(secondRun); builder.StartBookmark("Aspose bookmark"); // אם NextSibling הוא null, סביר להניח שזו Run האחרונה בפסקה. if (secondRun.NextSibling != null) builder.MoveTo(secondRun.NextSibling); else builder.MoveTo(secondRun.ParentParagraph); builder.EndBookmark("Aspose bookmark"); doc.Save("Output.docx"); using Aspose.Words; var doc = new Document(); var builder = new DocumentBuilder(doc); var firstRun = new Run(doc, "Proin eros metus, sagittis sed. "); var secondRun = new Run(doc, "Morbi enim nunc faucibus a."); doc.FirstSection.Body.FirstParagraph.AppendChild(firstRun); doc.FirstSection.Body.FirstParagraph.AppendChild(secondRun); builder.MoveTo(secondRun); builder.StartBookmark("Aspose bookmark"); // אם NextSibling הוא null, סביר להניח שזו Run האחרונה בפסקה. if (secondRun.NextSibling != null) builder.MoveTo(secondRun.NextSibling); else builder.MoveTo(secondRun.ParentParagraph); builder.EndBookmark("Aspose bookmark"); var saveOptions = new PdfSaveOptions(); saveOptions.OutlineOptions.BookmarksOutlineLevels.Add("Aspose bookmark", 1); doc.Save("Output.docx", saveOptions);
הפעל קוד

כיצד ליצור מסמך ב C#

  1. התקן Aspose.Words for .NET
  2. הוסף הפניה לספרייה (ייבא את הספרייה) לפרויקט C# שלך
  3. צור מסמך חדש
  4. התקשר לשיטת Save(), העברת שם הקובץ
  5. קבל את התוצאה כקובץ נפרד

ספריית C# ליצירת מסמכים

ישנן שלוש אפשרויות חלופיות להתקנת "Aspose.Words עבור .NET" במערכת שלך. אנא בחר אחד שדומה לצרכים שלך ופעל לפי ההוראות המפורטות:

דרישות מערכת

המוצר שלנו הוא חוצה פלטפורמות לחלוטין ותומך בכל ההטמעות העיקריות של NET.

  • .NET ≥ 5.0
  • .NET Core ≥ 2.0
  • .NET Standard ≥ 2.0
  • .NET Framework ≥ 3.5
  • MonoMac
  • MonoAndroid
  • Xamarin

ככל שקוד .NET אינו תלוי בחומרה או במערכת ההפעלה הבסיסית, אלא רק במכונה וירטואלית, אתה חופשי לפתח כל סוג של תוכנה עבור Windows, macOS, Android, iOS ו-Linux. רק ודא שהתקנת את הגרסה המתאימה של .NET Framework, .NET Core, Windows Azure, Mono או Xamarin.

אנו ממליצים להשתמש בסביבות פיתוח משולבות של Microsoft Visual Studio, Xamarin ו-MonoDevelop ליצירת יישומי C#, F#, VB.NET.

לפרטים נוספים, עיין בתיעוד המוצר.

פורמטי הקבצים הפופולריים ביותר

5%

הירשם לעדכוני מוצר Aspose

קבל ניוזלטרים והצעות חודשיים שנשלחו ישירות לתיבת הדואר שלך.

© Aspose Pty Ltd 2001-2024. כל הזכויות שמורות.