1. Home
  2.   Open xml sdk
  3.   Openize.OpenXML-SDK untuk .NET

Openize.OpenXML-SDK untuk .NET

 
 

Memanipulasi Dokumen Office di Aplikasi C# .NET

Buat, muat, dan modifikasi berbagai konten dokumen Microsoft Office, termasuk file Word, Excel, dan PowerPoint, hanya dengan beberapa baris kode.

Openize.OpenXML-SDK untuk .NET adalah SDK .NET sumber terbuka yang mudah digunakan, dirancang untuk pembuatan dan kustomisasi dokumen Microsoft Office secara efisien. Pustaka C# yang intuitif ini memungkinkan pembuatan dan manipulasi dokumen Word, Excel, dan PowerPoint dengan baris kode yang minimal.

Instalasi solusi ringan ini berjalan dengan lancar dan menawarkan berbagai fitur untuk berbagai kebutuhan dokumen. Openize.OpenXML-SDK memanfaatkan kekuatan OpenXML SDK, sebuah teknologi yang didukung oleh Microsoft. Sebagai pembungkus yang praktis, Openize.OpenXML-SDK menyederhanakan penggunaan kemampuan lanjutan.

Dirancang untuk pengembang, pustaka .NET sumber terbuka ini memungkinkan perluasan fungsionalitas dengan menggunakan pustaka OpenXML SDK. Desainnya yang ramah pengguna membuatnya mudah digunakan. Pustaka ini menawarkan berbagai fitur cerdas, termasuk menambahkan paragraf baru, menerapkan format teks, menyisipkan dan mengubah ukuran gambar, mengekstrak gambar, memodifikasi properti dokumen, dan masih banyak lagi.

Jelajahi repositori GitHub kami untuk berkontribusi, memberikan saran perbaikan, dan meningkatkan SDK Sumber Terbuka ini: https://github.com/openize-com/openize-open-xml-sdk-net

Previous Next

Memulai dengan Openize.OpenXML-SDK untuk .NET

Cara yang disarankan untuk menginstal Openize.OpenXML-SDK untuk .NET adalah menggunakan NuGet. Silakan gunakan perintah berikut untuk instalasi yang lancar.

Instal Openize.OpenXML-SDK untuk .NET melalui NuGet

NuGet\Install-Package Openize.OpenXML-SDK 
Anda juga dapat mengunduhnya langsung dari GitHub.

Membuat Dokumen Word Secara Programatis

Cuplikan kode berikut membuat dokumen Word secara programatis.

Membuat Dokumen Word melalui SDK .NET

 
// Create an instance of the Document class.
Document doc = new Document();

// Invoke the Save method to save the Word document onto the disk.
doc.Save("/Docs.docx");

Menambahkan Teks ke Dokumen Word

Cuplikan kode berikut menambahkan teks ke dokumen secara programatis.

Membuat Paragraf dalam Dokumen Word melalui SDK .NET


// Create an instance of the Document class.
using (Document doc = new Document())
{
    //Initialize the constructor with the Document class object.
    Body body = new Body(doc);
    // Instantiate an instance of the Paragraph class.
    Paragraph para1 = new Paragraph();
    // Set the text of the paragraph.
    para1.AddRun(new Run { Text = "This is a Paragraph." });
    // Invoke AppendChild method of the body class to add a paragraph to the document.
    body.AppendChild(para1);
    // Call the Save method to save the Word document onto the disk.
    doc.Save("/Docs.docx"); 
}

Membuat Spreadsheet/Workbook Excel Kosong Secara Programatis

Cuplikan kode berikut menunjukkan cara membuat dan menyimpan spreadsheet Excel baru menggunakan C# dengan pustaka FileFormat.Cells.

  • Kode dimulai dengan mengimpor pustaka FileFormat.Cells, yang memungkinkan manipulasi spreadsheet Excel.
  • Di dalam namespace Example, kelas Program didefinisikan.
  • Metode Main berfungsi sebagai titik masuk program dan menerima argumen baris perintah jika ada (string[] args).
  • Instance kelas Workbook diinisialisasi dengan `Workbook workbook = new Workbook();`.
  • Metode Save dipanggil pada instance workbook untuk menyimpan file Excel dengan nama "Spreadsheet.xlsx" di direktori root "/".

Salin dan tempel cuplikan kode di bawah ini ke dalam file utama Anda dan jalankan program.

Membuat Workbook / Spreadsheet Kosong dalam C#

 
using System;
using Openize.Cells;

namespace Example
{
    class Program
    {
        static void Main(string[] args)
        {
            // Initialize an instance of the Workbook class.
            var workbook = new Openize.Cells.Workbook();

            // Call the Save method to save the MS Excel Spreadsheet/Workbook onto the disk.
            workbook.Save("Z:\\Downloads\\Spreadsheet.xlsx");
            
            Console.WriteLine("Excel spreadsheet created successfully.");
        }
    }
}

Menyisipkan Baris ke dalam Lembar Kerja Excel pada Indeks Tertentu

Contoh C# ini menunjukkan cara menyisipkan baris ke dalam lembar kerja Excel pada indeks tertentu menggunakan pustaka Openize.Cells.

Salin dan tempel cuplikan kode di bawah ini ke dalam file utama Anda dan jalankan program.

Membuat Workbook / Spreadsheet Kosong dalam C#

 
using System;
using Openize.Cells;

class Program
{
    static void Main(string[] args)
    {
        string filePath = "Z:\\Downloads\\test_spreadsheet.xlsx";

        // Load the workbook from the specified file path
        using (var wb = new Openize.Cells.Workbook(filePath))
        {
            // Access the first worksheet in the workbook
            var firstSheet = wb.Worksheets[0];

            // Define the starting row index and the number of rows to insert
            uint startRowIndex = 5;
            uint numberOfRows = 3;

            // Insert the rows into the worksheet
            firstSheet.InsertRows(startRowIndex, numberOfRows);

            // Get the total row count after insertion
            int rowsCount = firstSheet.GetRowCount();

            // Output the updated row count to the console
            Console.WriteLine("Rows Count=" + rowsCount);

            // Save the workbook to reflect the changes made
            wb.Save(filePath);

            Console.WriteLine("Rows inserted and workbook saved successfully.");
        }
    }
}

Membuat Presentasi PowerPoint Secara Programatis

Cuplikan kode berikut membuat presentasi PowerPoint secara programatis.

Membuat Presentasi PowerPoint melalui API .NET

 
// Create an object of the Presentation class.
 Presentation presentation = Presentation.Create("presentation.pptx");

//Perform necessary operations.
//...

// Call the Save method to save the PowerPoint file onto the disk.
presentation.Save();

Menyisipkan Teks ke dalam Presentasi PowerPoint

Cuplikan kode berikut menyisipkan teks ke dalam presentasi PowerPoint secara programatis.

Menyisipkan Teks ke dalam Presentasi melalui API .NET

 

// Create a new PowerPoint presentation at the specified file path
Presentation presentation = Presentation.Create("D:\\AsposeSampleResults\\test2.pptx");

// Create a text shape for the title and set its properties
TextShape shape = new TextShape();
shape.Text = "Title: Here is my first title From FF";
shape.TextColor = "980078";
shape.FontFamily = "Baguet Script";

// Create the slide and add the text shape to it
Slide slide = new Slide();
slide.AddTextShapes(shape);

// Append the slide to the presentation
presentation.AppendSlide(slide);

// Save the modified presentation
presentation.Save();


Lebih Banyak Contoh Kode dan Sumber Daya

Jelajahi contoh kode lebih lanjut di Openize Gists.

 Indonesian