FileFormat.Words, Word belgelerine tabloları programlı olarak eklemenize/değiştirmenize olanak tanıyan ücretsiz bir kelime işlemci modülü sunan açık kaynaklı bir kitaplıktır. {.wp-blok başlığı}

FileFormat.words kullanarak kelime dosyalarında tablo nasıl yapılır

Genel Bakış

Word belgesindeki tablo, veri temsili söz konusu olduğunda ayrılmaz bir parça olarak kabul edilir. En yaygın belge öğesidir ve iş belgesi oluşturma açısından büyük kolaylık sunar. Şaşırtıcı bir şekilde, yerel makinenizde MS Word kullanmadan veya yüklemeden bir Word belgesinde bir tablo oluşturabilirsiniz. Evet, kelime belgelerini programlı olarak oluşturmanızı ve manipüle etmenizi sağlayan birücretsiz kelime işlemci**tanıtayım. .NET için FileFormat.Words Word belge işleme işleminin eksiksiz bir paketidir. Bu nedenle, bu blog yazısında, Word’de bir tablo nasıl yapılacağını bu .NET kütüphanesini FileFormat.Words kullanarak öğreneceğiz. Bu blog gönderisi aşağıdaki bölümleri kapsamaktadır:

Kelime için Tablo Jeneratörü - API Kurulumu

.NET için FileFormat.Words MS Word işlemi için çok çeşitli özellikler sunar. Bu açık kaynaklı API’nın kurulumu çok kolaydır. Ancak, aşağıdaki komutu Nuget Paket Yöneticisi’ne çalıştırarak Nuget Paketi yüklemesinin 8 indirebilirsiniz.

Install-Package FileFormat.Words

Bir Word belgesinde program olarak nasıl bir tablo oluşturulur

Bu açık kaynaklı ücretsiz kelime proseso r eylemde görmek için bazı kodlar yazalım. Aslında, FileFormat.Words Kütüphanesi kullanarak bir Word belgesinde nasıl tablo oluşturulacağını göreceğiz. Lütfen aşağıdaki adımları ve kod snippet’ini izleyin:

  • Belge sınıfının bir örneğini başlatın.
  • Body sınıfının yapıcısını belge sınıfı nesnesiyle başlatın.
  • Tablo sınıfının bir nesnesi oluşturun.
  • Topborder12, BottomDorder, rightBorder, LeftBorder, InsideTicalBorder ve InsideHorizontalborder sınıflarının yapıcılarını başlatın. Masanın tüm taraflarının sınırını ayarlayın.
  • Sınır stilini ve sınırda genişliği ayarlamak için BasicBlackSquares_Border yöntemini çağırın.
  • Tableborders sınıfının bir örneğini oluşturun.
  • Ek Topborder, BottomDorder, Rightborder, LeftBorder, InsideVerticalBorder ve InsideHorizontalborder sınıflarının Tableborders sınıfının nesnesine nesneleri.
  • TableProperties sınıfının bir örneğini başlatın.
  • Tableborders sınıfının nesnesini eklemek için tabloProperties sınıfının ek yöntemini çağırın.
  • Tablejustification sınıfının bir örneğini oluşturun ve tabloyu belgenin sol tarafına konumlandırmak için Alignleft yöntemini çağırın.
  • Tablejustination nesnesini TBLprop nesnesine eklemek için ek yöntemini çağırın.
  • Tablo sınıfının apendchild yöntemi tablo özelliklerini tabloya ekleyecektir.
  • Bir tablo satırı oluşturmak için tablow sınıfının bir nesnesi oluşturun.
  • TableCell sınıfının bir örneğini başlatın.
  • TableHeaders yöntemini çağırarak ilk sütunun başlığını ayarlayın.
  • Tablo hücresinin içine metin eklemek için tablo kontrol sınıfının ek yöntemini çağırın.
  • TableCellProperties tablo özelliklerinin bir nesnesi oluşturun
  • TableCellwidth sınıfının nesnesini başlatarak ve TBLCellProps nesnesine ekleyerek tablo hücresinin genişliğini ayarlayın.
  • Ek yöntemi, TBLCellProps nesnesini masa örtüsü sınıfının nesnesine ekleyecektir.
  • Satırları tabloya eklemek için ek yöntemini çağırın.
  • Apdchild yöntemi tabloyu belgenin gövdesine ekleyecektir.
  • Kaydet yöntemi Word belgesini diske kaydedecektir.
using FileFormat.Words;
using FileFormat.Words.Table;

namespace Example
{
    class Program
    {
        static void Main(string[] args)
        {
            // Initialize an instance of the Document class.
            using (Document doc = new Document())
            {
                // Instantiate the constructor of the Body class with the Document class object.
                Body body = new Body(doc);
                // Create an object of the Table class.
                Table table = new Table();
                // Initialize the constructor of the TopBorder class to set the border of the top side of the table.
                TopBorder topBorder = new TopBorder();
                // Invoke the basicBlackSquares_border method to set the border style and border line width.
                topBorder.basicBlackSquares_border(20);
                // To set the border of the bottom side of the table.
                BottomBorder bottomBorder = new BottomBorder();
                bottomBorder.basicBlackSquares_border(20);
                // To set the border of the right side of the table.
                RightBorder rightBorder = new RightBorder();
                rightBorder.basicBlackSquares_border(20);
                // To set the border of the left side of the table.
                LeftBorder leftBorder = new LeftBorder();
                leftBorder.basicBlackSquares_border(20);
                // To set the inside vertical border of the table.
                InsideVerticalBorder insideVerticalBorder = new InsideVerticalBorder();
                insideVerticalBorder.basicBlackSquares_border(20);
                // To set the inside vehorizontalrtical border of the table.
                InsideHorizontalBorder insideHorizontalBorder = new InsideHorizontalBorder();
                insideHorizontalBorder.basicBlackSquares_border(20);
                // Create an instance of the TableBorders class. 
                TableBorders tableBorders = new TableBorders();
                // Append the object of the TopBorder class to the object of the TableBorders class.
                tableBorders.AppendTopBorder(topBorder);
                // Append the object of the BottomBorder class.
                tableBorders.AppendBottomBorder(bottomBorder);
                // Append the object of the RightBorder class.
                tableBorders.AppendRightBorder(rightBorder);
                // Append the object of the LeftBorder class.
                tableBorders.AppendLeftBorder(leftBorder);
                // Append the object of the InsideVerticalBorder class.
                tableBorders.AppendInsideVerticalBorder(insideVerticalBorder);
                // Append the object of the InsideHorizontalBorder class.
                tableBorders.AppendInsideHorizontalBorder(insideHorizontalBorder);

                // Initialize an instance of the TableProperties class.
                TableProperties tblProp = new TableProperties();
                // Invoke the Append method to attach the object of the TableBorders class.
                tblProp.Append(tableBorders);
                // Create an instance of the TableJustification class 
                TableJustification tableJustification = new TableJustification();
                // Call the AlignLeft method to position the table on left side of the document.
                tableJustification.AlignLeft();
                // Invoke the Append method to attach the tableJustification object to the tblProp object.
                tblProp.Append(tableJustification);

                // The AppendChild method will attach the table propertiese to the table.
                table.AppendChild(tblProp);

                // Create an object of the TableRow class to create a table row.
                TableRow tableRow = new TableRow();
                TableRow tableRow2 = new TableRow();

                // Initialize an istance of the TableCell class.
                TableCell tableCell = new TableCell();
                Paragraph para = new Paragraph();
                Run run = new Run();

                // Set the header of the first column by invoking the TableHeaders method.
                table.TableHeaders("Name");
                run.Text = "Mustafa";
                para.AppendChild(run);
                // Call the Append method to add text inside the table cell.
                tableCell.Append(para);

                // Create an object of the TableCellProperties table properties 
                TableCellProperties tblCellProps = new TableCellProperties();

                // Set the width of table cell by initializing the object of the TableCellWidth class and append to tblCellProps object.
                tblCellProps.Append(new TableCellWidth("2400"));
                // Append method will attach the tblCellProps object with the object of the TableCell class.
                tableCell.Append(tblCellProps);

                TableCell tableCell2 = new TableCell();
                Paragraph para2 = new Paragraph();
                Run run2 = new Run();

                // set the header of the second column
                table.TableHeaders("Nationality");
                run2.Text = "Pakistani";
                para2.AppendChild(run2);
                tableCell2.Append(para2);

                TableCellProperties tblCellProps2 = new TableCellProperties();
                tblCellProps2.Append(new TableCellWidth("1400"));
                tableCell2.Append(tblCellProps2);

                TableCell tableCell3 = new TableCell();
                Paragraph para3 = new Paragraph();
                Run run3 = new Run();
                table.TableHeaders("Age");
                run3.Text = "30";
                para3.AppendChild(run3);
                tableCell3.Append(para3);

                TableCellProperties tblCellProps3 = new TableCellProperties();
                tblCellProps3.Append(new TableCellWidth("1400"));
                tableCell3.Append(tblCellProps3);
                // Call the Append method to add cells into table row.
                tableRow.Append(tableCell);
                tableRow.Append(tableCell2);
                tableRow.Append(tableCell3);

                // create table cell
                TableCell _tableCell = new TableCell();
                Paragraph _para = new Paragraph();
                Run _run = new Run();

                _run.Text = "sultan";
                _para.AppendChild(_run);
                _tableCell.Append(_para);

                TableCellProperties tblCellProps1_ = new TableCellProperties();
                tblCellProps1_.Append(new TableCellWidth("2400"));
                _tableCell.Append(tblCellProps1_);


                TableCell _tableCell2 = new TableCell();
                Paragraph _para2 = new Paragraph();
                Run _run2 = new Run();

                _run2.Text = "British";
                _para2.AppendChild(_run2);
                _tableCell2.Append(_para2);

                TableCellProperties tblCellProps2_ = new TableCellProperties();
                tblCellProps2_.Append(new TableCellWidth("1400"));
                _tableCell2.Append(tblCellProps2_);

                TableCell _tableCell3 = new TableCell();
                Paragraph _para3 = new Paragraph();
                Run _run3 = new Run();

                _run3.Text = "2";
                _para3.AppendChild(_run3);
                _tableCell3.Append(_para3);

                TableCellProperties tblCellProps3_ = new TableCellProperties();
                tblCellProps3_.Append(new TableCellWidth("1400"));
                _tableCell3.Append(tblCellProps3_);

                tableRow2.Append(_tableCell);
                tableRow2.Append(_tableCell2);
                tableRow2.Append(_tableCell3);
                // Call the Append method to add the rows into table.
                table.Append(tableRow);
                table.Append(tableRow2);
                // The AppendChild method will add the table to the body of the document.
                body.AppendChild(table);
                // The Save method will save the Word document onto the disk.
                doc.Save("/Docs.docx");
            }

        }

    }
}

Yukarıdaki kod snippet’inin çıkışı aşağıdaki resimde gösterilmiştir:

Word belgesinde tablo nasıl oluşturulur

Sonuç

Bu bizi bu makalenin sonuna getiriyor ve umarız bir kelimede tablo nasıl yapılır belgede dosyaFormat.Words Kütüphanesi kullanarak. Ayrıca, C#‘daki kelime belgeleri için bir tablo jeneratörü oluşturmak istiyorsanız bu kılavuz size yardımcı olacaktır. Ayrıca, bu ücretsiz kelime işlemci API açık kaynaktır ve belgelerini burada bulabilirsiniz. Son olarak, FileFormat.com diğer konulara blog yayınları yazmaya devam ediyor. Dahası, bizi Facebook, LinkedIn ve Twitter dahil olmak üzere sosyal medya platformlarımızda takip edebilirsiniz.

katkıda bulun

Çünkü [.NET] için FileFormat.Words açık kaynaklı bir projedir ve GitHub ‘de mevcuttur. Dolayısıyla, topluluktan katkı çok takdir ediliyor.

Bir soru sorun

Forum ‘de sorularınızı veya sorgularınızı bize bildirebilirsiniz.

Sık Sorulan Sorular-SSS {.wp-blok başlık}

** Bir kelime belgesinde nasıl tablo oluştururum?** Bu açık kaynaklı .NET kütüphanesi kullanarak Word belgesinde bir tablo oluşturmak çok kolaydır. Dahası, bu API’yi daha fazla keşfedebilirsiniz. ** C#?** Ayrıntılı bir kod snippet’inden geçmek için lütfen bunu link izleyin ve C#‘da bir DOCX dosyası oluşturmak için adımlar. ** Word’de nasıl özel bir tablo biçimi oluştururum?** .NET için FileFormat.Words, MS Word’ü programlı olarak manipüle etmek ve oluşturmak için özellikler sunan ücretsiz bir kitaplıktır. Aslında, yöntemleri ve özellikleri görmek için bu ad alanını fileFormat.words.table keşfedebilirsiniz.

Ayrıca bkz.