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

Openize.OpenXML-SDK for .NET

 
 

C# .NET 앱에서 Office 문서를 조작하세요

몇 줄의 코드만으로 Microsoft Office 문서(Word, Excel, PowerPoint)를 생성, 로드 및 수정할 수 있습니다.

Openize.OpenXML-SDK for .NET은 Microsoft Office 문서의 생성 및 사용자 지정을 쉽게 할 수 있도록 설계된 오픈 소스 .NET SDK입니다. 직관적인 C# 라이브러리를 통해 최소한의 코드로 Word, Excel, PowerPoint 문서를 처리할 수 있습니다.

이 가벼운 솔루션은 간편하게 설치할 수 있으며, 다양한 문서 처리 요구를 충족할 수 있습니다. Openize.OpenXML-SDK는 Microsoft가 지원하는 OpenXML SDK의 기능을 활용하여 보다 편리하게 사용할 수 있도록 구성되었습니다.

개발자를 위해 설계된 이 오픈 소스 .NET 라이브러리는 OpenXML SDK를 활용하여 기능을 확장할 수 있습니다. 직관적인 설계 덕분에 쉽게 사용할 수 있으며, 새로운 단락 추가, 텍스트 서식 지정, 이미지 삽입 및 크기 조정, 이미지 추출, 문서 속성 수정 등 다양한 기능을 제공합니다.

GitHub 저장소를 방문하여 기여하고, 개선 사항을 제안하며, 이 오픈 소스 SDK를 더욱 발전시켜 보세요: https://github.com/openize-com/openize-open-xml-sdk-net

Previous Next

Openize.OpenXML-SDK for .NET 시작하기

Openize.OpenXML-SDK for .NET을 설치하는 가장 권장되는 방법은 NuGet을 사용하는 것입니다. 원활한 설치를 위해 다음 명령어를 사용하세요.

NuGet을 통해 Openize.OpenXML-SDK for .NET 설치

NuGet\Install-Package Openize.OpenXML-SDK 
또한 GitHub에서 직접 다운로드할 수도 있습니다.

Word 문서를 프로그래밍 방식으로 생성하기

다음 코드 스니펫은 Word 문서를 프로그래밍 방식으로 생성하는 방법을 보여줍니다.

.NET SDK를 사용하여 Word 문서 생성

 
// 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");

Word 문서에 텍스트 추가

다음 코드 스니펫은 Word 문서에 텍스트를 추가하는 방법을 보여줍니다.

.NET SDK를 사용하여 Word 문서에 단락 추가


// 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"); 
}

빈 Excel 스프레드시트/워크북 프로그래밍 방식으로 생성

다음 코드 스니펫은 C#과 FileFormat.Cells 라이브러리를 사용하여 Microsoft Excel 스프레드시트를 생성하고 저장하는 방법을 보여줍니다.

  • 먼저 FileFormat.Cells 라이브러리를 가져와 Excel 스프레드시트 조작 기능을 사용할 수 있도록 합니다.
  • Example 네임스페이스 내에서 Program 클래스를 정의합니다.
  • Main 메서드는 프로그램의 진입점이며, 명령줄 인수(string[] args)를 받을 수 있습니다.
  • Workbook 클래스의 인스턴스를 `Workbook workbook = new Workbook();`으로 생성합니다.
  • Save 메서드를 호출하여 Excel 스프레드시트를 저장합니다. 파일은 루트 디렉터리(`/`)에 "Spreadsheet.xlsx"라는 이름으로 저장됩니다.

아래 코드 스니펫을 복사하여 메인 파일에 붙여넣고 프로그램을 실행하세요.

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.");
        }
    }
}

Excel 워크시트에서 특정 행 위치에 행 삽입

이 C# 예제는 Openize.Cells 라이브러리를 사용하여 Excel 워크시트에서 특정 행 위치에 행을 삽입하는 방법을 보여줍니다.

아래 코드 스니펫을 복사하여 메인 파일에 붙여넣고 프로그램을 실행하세요.

C#에서 Excel 시트에 행 삽입

 
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.");
        }
    }
}

PowerPoint 프레젠테이션을 프로그래밍 방식으로 생성

다음 코드 스니펫은 PowerPoint 프레젠테이션을 프로그래밍 방식으로 생성하는 방법을 보여줍니다.

.NET API를 사용하여 PowerPoint 프레젠테이션 생성

 
// 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();

프레젠테이션에 텍스트 삽입

다음 코드 스니펫은 PowerPoint 프레젠테이션에 텍스트를 프로그래밍 방식으로 삽입하는 방법을 보여줍니다.

.NET API를 사용하여 프레젠테이션에 텍스트 삽입

 

// 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();


추가 코드 예제 및 리소스

더 많은 상세 코드 예제를 확인하려면 Openize Gists를 방문하세요.

 한국인