1. Ürün:% s
  2.   Kelime İşleme
  3.   .NET
  4.   Open XML SDK
 
  

.NET Kitaplığı Kelime İşleme Belgeleri Oluşturma

Word dosyalarını okuyun, yazın, işleyin ve dönüştürün, açık kaynak .NET API aracılığıyla DOCX'te Tablolar Oluşturun.

Açık XML SDK, Microsoft tarafından geliştirilen ve dahil olmak üzere Kelime İşleme Belgelerini işlemek için Microsoft açık kaynak davranış kuralları altında dağıtılan açık kaynaklı bir API'dir. DOCXDOTXDOCMDOTM dosya biçimleri

API'yi kullanarak metin, üstbilgi, altbilgi, son notlar, dipnotlar, stiller, temalar ve daha fazlasını ekleyebilirsiniz. Yüksek performanslı kelime belgeleri oluşturmanıza ve bunlardan veri çıkarmanıza olanak tanır. API, .NET 3.5, .NET 4.0, .NET 4.6 ve .NET Standard 1.3 dahil olmak üzere çeşitli .NET platformlarını destekler.

Previous Next

Açık XML SDK'sına Başlarken

Öncelikle .NET Framework 3.5 veya üzeri bir sürüme sahip olmanız gerekmektedir. Bundan sonra, lütfen depoyu GitHub'dan manuel olarak indirin veya NuGet.

Yükleme  NuGet'ten XML SDK'sını açın

 Install-Package DocumentFormat.OpenXml

C# kullanarak DOCX dosyasını işleyin

Açık XML SDK, .NET programcılarının kendi .NET uygulamalarından kelime işlemeyi oluşturmasına ve değiştirmesine olanak tanır. Mevcut bir dosyayı değiştirmek için mevcut bir dosyayı açabilir ve metin, paragraflar, tablolar ve daha fazlası gibi değişiklikleri ekleyebilirsiniz.

DOCX'e Paragraf Ekle - C#

// Open an existing word processing document
using (WordprocessingDocument wordprocessingDocument = WordprocessingDocument.Open("fileformat.docx", true))
{
  Body body = wordprocessingDocument.MainDocumentPart.Document.Body;
  // Add paragraph
  Paragraph para = body.AppendChild(new Paragraph());
  Run run = para.AppendChild(new Run());
  run.AppendChild(new Text("File Format Developer Guide"));
}

C# kullanarak DOCX'te bir Tablo oluşturun

API, geliştiricilerin Kelime İşlem belgelerine bir tablo eklemesine olanak tanır. Tablo ekleyebilir, tablo özelliklerini ayarlayabilir, tablo ızgarasını ayarlayabilir ve sütun ızgarası özelliklerini ayarlayabilirsiniz. Ayrıca, sırasıyla TableCell ve TableRow sınıflarını kullanarak tablo hücrelerini ve satırları yönetebilirsiniz.

DOCX'te Tablo Oluştur - C#

// Open an existing word processing document
using (WordprocessingDocument wordprocessingDocument = WordprocessingDocument.Open("fileformat.docx", true))
{
  Body body = wordprocessingDocument.MainDocumentPart.Document.Body;
  // Create a table.
  Table table = new Table();
  // Set the style and width for the table.
  TableProperties tableProperties = new TableProperties();
  TableStyle tableStyle = new TableStyle() { Val = "TableGrid" };
  // Make the table width 100% of the page width.
  TableWidth tableWidth = new TableWidth() { Width = "5000", Type = TableWidthUnitValues.Pct };
  // Apply
  tableProperties.Append(tableStyle, tableWidth);
  table.AppendChild(tableProperties);
  // Add columns
  TableGrid tableGrid = new TableGrid(new GridColumn(), new GridColumn(), new GridColumn());
  table.AppendChild(tableGrid);
  // Create 1 row to the table.
  TableRow tableRow = new TableRow();
  // Add a cell to each column in the row.
  TableCell tableCell = new TableCell(new Paragraph(new Run(new Text("Column 1"))));
  TableCell tableCell1 = new TableCell(new Paragraph(new Run(new Text("Column 2"))));
  //Append data
  tableRow.Append(tableCell, tableCell1);
  // Add row to the table.
  table.AppendChild(tableRow);
  // Add the table to the document
  body.AppendChild(table);
}

Kelime İşlem Belgesinde Üst Bilgiler ve Alt Bilgiler

Belgelerin uygun şekilde düzenlenmesi çok önemlidir ve her kuruluşun ihtiyacıdır. Başlıklar ve alt bilgiler, ilgili tarihler, konular, yazarın adı, resimler, sayfa numaraları vb. gibi bazı ek bilgileri yerleştirerek sözcük işlem belgelerini düzgün bir şekilde düzenlemeye yardımcı olabilecek belgelerin önemli parçalarıdır. Ayrıca birden fazla başlığın eklenmesini de destekler.

Word Belgesinde Başlıkları Yönetin

 
public static void ApplyHeader(WordprocessingDocument doc)
{
  // Get the main document part.
  MainDocumentPart mainDocPart = doc.MainDocumentPart;
  HeaderPart headerPart1 = mainDocPart.AddNewPart("r97");
  Header header1 = new Header();
  Paragraph paragraph1 = new Paragraph(){ };
  Run run1 = new Run();
  Text text1 = new Text();
  text1.Text = "Header stuff";
  run1.Append(text1);
  paragraph1.Append(run1);
  header1.Append(paragraph1);
  headerPart1.Header = header1;
  SectionProperties sectionProperties1 = mainDocPart.Document.Body.Descendants().FirstOrDefault();
  if (sectionProperties1 == null)
  {
  sectionProperties1 = new SectionProperties() { };
  mainDocPart.Document.Body.Append(sectionProperties1);
  }
  HeaderReference headerReference1 = new HeaderReference() { Type = HeaderFooterValues.Default, Id = "r97" };
  sectionProperties1.InsertAt(headerReference1,0);
}

Word Belgesinde Alt Bilgileri Yönetin

 
public static void ApplyFooter(WordprocessingDocument doc)
{
  // Get the main document part.
  MainDocumentPart mainDocPart = doc.MainDocumentPart;
  FooterPart footerPart1 = mainDocPart.AddNewPart("r98");
  Footer footer1 = new Footer();
  Paragraph paragraph1 = new Paragraph() { };
  Run run1 = new Run();
  Text text1 = new Text();
  text1.Text = "Footer stuff";
  run1.Append(text1);
  paragraph1.Append(run1);
  footer1.Append(paragraph1);
  footerPart1.Footer = footer1;
  SectionProperties sectionProperties1 = mainDocPart.Document.Body.Descendants().FirstOrDefault();
  if (sectionProperties1 == null)
  {
    sectionProperties1 = new SectionProperties() { };
    mainDocPart.Document.Body.Append(sectionProperties1);
  }
  FooterReference footerReference1 = new FooterReference() { Type = DocumentFormat.OpenXml.Wordprocessing.HeaderFooterValues.Default, Id = "r98" };
  sectionProperties1.InsertAt(footerReference1, 0);
}
 Türkçe