सी # का उपयोग कर वर्ड दस्तावेज़ में टेबल कैसे बनाएं

यह ट्यूटोरियल C# का उपयोग करके Word दस्तावेज़ में तालिका बनाने के दो अलग-अलग तरीकों को सूचीबद्ध करता है। हम पहले Aspose DocumentBuilder की मदद से C# का उपयोग करके Word में तालिका बनाएंगे और बाद में Word दस्तावेज़ ऑब्जेक्ट मॉडल (DOM) में सीधे C# का उपयोग करके Word तालिका बनाएंगे।

सी#का उपयोग कर वर्ड डॉक्यूमेंट में टेबल बनाने के चरण

  1. समाधान में NuGet से Aspose.Words for .NET पैकेज का संदर्भ लें
  2. आयात Aspose.Words and Aspose.Words.Tables namespaces
  3. DocumentBuilder या Table क्लास इंस्टेंस बनाएं
  4. तालिका पंक्ति में सेल जोड़ने के लिए InsertCell या Table.Rows.Cells.Add विधि का उपयोग करें
  5. अनुच्छेद पाठ सम्मिलित करने के लिए DocumentBuilder.Write या Cell.AppendChild विधि का उपयोग करें
  6. तालिका में एकाधिक पंक्तियाँ बनाएँ और Word दस्तावेज़ में तालिका निर्माण समाप्त करें
  7. डिस्क पर DOCX प्रारूप में तालिका के साथ Word दस्तावेज़ के रूप में सहेजें

निम्नलिखित Aspose DocumentBuilder कोड उदाहरण का उपयोग C# Word तालिका निर्माण के लिए .NET अनुप्रयोग में किया जा सकता है।

सी # का उपयोग कर वर्ड दस्तावेज़ में तालिका बनाने के लिए कोड

using Aspose.Words;
using Aspose.Words.Tables;
namespace CreateTableInWordDocumentUsingCsharp
{
class CreateTableWord
{
static void Main(string[] args)
{
// Set license before C# Word table creation
License setupToCreateTable = new License();
setupToCreateTable.SetLicense(@"license file path.lic");
// Document Builder object to create Table in Word document
DocumentBuilder toCreateTableInWord = new DocumentBuilder();
// Mark the start of Word Table
Table tableInWord = toCreateTableInWord.StartTable();
// Insert a new Row & then first Cell in Word Table
toCreateTableInWord.InsertCell();
// Write text in Table Cell
toCreateTableInWord.Write("Table Row 1 and Cell 1");
// Insert a new Cell in same Word Table Row
toCreateTableInWord.InsertCell();
// Insert an Image in Word Table Cell
toCreateTableInWord.InsertImage("insert image in word table.jpg");
// Mark the end of Table Row
toCreateTableInWord.EndRow();
// Mark end of Word Table creation
toCreateTableInWord.EndTable();
// Save Word DOCX document with Table on disk
toCreateTableInWord.Document.Save("c# word table created in.docx");
}
}
}

अनिवार्य रूप से, यह तालिका बनाएँ Word C# ऐप आपको Word दस्तावेज़ में एक तालिका सम्मिलित करने में सक्षम बनाता है। यह पहले टेबल की पहली पंक्ति में दो सेल जोड़ता है और बाद में पहले सेल में टेक्स्ट कंटेंट लिखता है और फिर वर्ड सी # में छवि जोड़ें अंतिम सेल में।

सी # (डीओएम क्लासेस) का उपयोग कर वर्ड टेबल बनाने के लिए कोड

using Aspose.Words;
using Aspose.Words.Tables;
namespace CreateWordTable
{
class CreateTableInWord
{
static void Main(string[] args)
{
// Set license before creating Word table
License license = new License();
license.SetLicense(@"license file path.lic");
Document wordDocument = new Document(); // Create empty Word document
Table wordTable = new Table(wordDocument); // Create Table object
wordTable.Rows.Add(new Row(wordDocument)); // Create a Row inside Table
wordTable.FirstRow.Cells.Add(new Cell(wordDocument)); // Create a single Cell in Table Row
wordTable.FirstRow.FirstCell.AppendChild(new Paragraph(wordDocument)); // Add a Paragraph inside Cell
// Write text content inside Word Table Cell
wordTable.FirstRow.FirstCell.FirstParagraph.Runs.Add(new Run(wordDocument, "Text in Table Row 1 and Cell 1"));
// Insert Table at the end of Word Document
wordDocument.FirstSection.Body.InsertBefore(wordTable, wordDocument.FirstSection.Body.LastParagraph);
// Save Word document to DOCX format
wordDocument.Save("c# word table created in.docx");
}
}
}

उपरोक्त एस्पोज वर्ड क्रिएट टेबल सी # कोड उदाहरण टेबल, रो, सेल और पैराग्राफ क्लासेस का उपयोग करके वर्ड डॉक्यूमेंट ऑब्जेक्ट मॉडल में टेबल एलिमेंट जोड़ने के लिए एक वैकल्पिक दृष्टिकोण प्रस्तुत करता है।

 हिन्दी