Table of Contents

Developer Guide: Openize.OpenXML-SDK for .NET

Welcome to the Openize.OpenXML-SDK for .NET developer guide! This SDK offers a powerful and intuitive set of APIs to manipulate Word documents, Excel spreadsheets, and PowerPoint presentations programmatically within .NET applications. Whether you're generating reports, editing existing content, or automating document workflows, Openize.OpenXML-SDK simplifies working with OpenXML formats through a clean and consistent interface. This guide provides practical code examples and step-by-step summaries for performing common document operations—making it easier for developers to integrate document processing into their .NET projects efficiently.

Word Processing

  1. Load the Word .docx document.
  2. Access the body of the document.
  3. Initialize paragraph counter.
  4. Loop through all paragraphs and display:
    • Paragraph number
    • Paragraph style
    • Plain text
  5. Reset counters for the next section.
  6. Loop through all paragraphs again:
    • Display paragraph number and style
    • Loop through text runs and display:
      • Text
      • Font family
      • Font color
      • Font size
      • Bold flag
      • Italic flag
      • Underline flag

Example

		// Load the Word Document
        var doc = new FileFormat.Words.Document("filename.docx");
        var body = new FileFormat.Words.Body(doc);
        var num = 0;

        System.Console.WriteLine("Paragraphs Plain Text");

        // Traverse and display paragraphs with plain text
        foreach (var paragraph in body.Paragraphs)
        {
            num++;
            System.Console.WriteLine($" Paragraph Number: {num}");
            System.Console.WriteLine($" Paragraph Style: {paragraph.Style}");
            System.Console.WriteLine($" Paragraph Text: {paragraph.Text}");
        }

        num = 0;
        var runnum = 0;
        System.Console.WriteLine("Paragraphs with formatting");

        // Traverse and display paragraphs with formatting details
        foreach (var paragraph in body.Paragraphs)
        {
            num++;
            System.Console.WriteLine($" Paragraph Number: {num}");
            System.Console.WriteLine($" Paragraph Style: {paragraph.Style}");

            // Traverse and display runs within each paragraph
            foreach (var run in paragraph.Runs)
            {
                runnum++;
                System.Console.WriteLine($"  Text fragment ({num} - {runnum}): {run.Text}");
                System.Console.WriteLine($"  Font fragment ({num} - {runnum}): {run.FontFamily}");
                System.Console.WriteLine($"  Color fragment ({num} - {runnum}): {run.Color}");
                System.Console.WriteLine($"  Size fragment ({num} - {runnum}): {run.FontSize}");
                System.Console.WriteLine($"  Bold fragment ({num} - {runnum}): {run.Bold}");
                System.Console.WriteLine($"  Italic fragment ({num} - {runnum}): {run.Italic}");
                System.Console.WriteLine($"  Underline fragment ({num} - {runnum}): {run.Underline}");
           }
           runnum = 0;
        }

Spreadsheet Processing

  1. Define the file path for the Excel file (testFile.xlsx).
  2. Load the workbook from the specified file path.
  3. Access the first worksheet in the workbook.
  4. Define a cell reference (B10).
  5. Access the specified cell from the worksheet.
  6. Insert the value "randomValue" into the cell.
  7. Save the workbook back to the original file path.

Example

using Openize.Cells

string filePath = "testFile.xlsx";

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

    // Define the cellReference
    string cellReference = "B10";
    Cell cell = firstSheet.Cells[cellReference];
    
    // Insert the actual value to the cell.
    cell.PutValue("randomValue"); 

    wb.Save(filePath);
}

Presentation Processing

  1. Open the PowerPoint presentation file (test.pptx).
  2. Create a new slide.
  3. Create a Rectangle object and set its properties:
    • Width: 500.0
    • Height: 300.0
    • X position: half of the width
    • Y position: half of the height
    • Background color: #5f7200
  4. Draw the rectangle on the slide.
  5. Append the slide to the presentation.
  6. Save the presentation.

Example

Presentation presentation = Presentation.Open("test.pptx");
// Create slide
Slide slide = new Slide();
// Create Rectangle object and set it's properties
Rectangle rectangle = new Rectangle();
rectangle.Width = 500.0;
rectangle.Height =300.0;
rectangle.X = rectangle.Width / 2;
rectangle.Y = rectangle.Height / 2;
rectangle.BackgroundColor = "5f7200";
slide.DrawRectangle(triangle);
// Append slide into presentation
presentation.AppendSlide(slide);
// Save presentation
presentation.Save();

Cross-Cutting Features

  • Unified API design for consistency across document types
  • High-performance processing for large files
  • Cross-platform support (.NET 6+ on Windows, Linux, macOS)
  • Lightweight SDK, no need for Microsoft Office installed
  • Easily extendable and integrable with CI/CD pipelines