NPOI Documentation

repository·master·Indexed 27 days ago

https://github.com/nissl-lab/npoi

A .NET library for reading and writing Microsoft Office files, including Excel (.xls, .xlsx) and Word (.docx). A port of the Apache POI project, NPOI supports .NET 8, .NET Standard 2.0/2.1, and .NET Framework 4.0+. It provides functionality for managing POIFS filesystem objects via the Entry interface, implementing Excel functions like INDEX, and offering utility collections such as BidirectionalDictionary. The library also includes classes for configuring VML shapes, fills, and paths.

Tokens
4K
Snippets
5
Records
42
Agent score
86%

What's inside NPOI

  1. Overview of NPOI

    master
    NPOI is the .NET implementation of the Apache POI project. It provides functionality to read and write Microsoft Office files (Office 2003 and 2007 formats) within .NET applications. It supports both importing and exporting data and is designed to be interface-oriented (specifically within the NPOI.SS namespace).
  2. Create a read-only BidirectionalDictionary

    master

    You can create a read-only view of a dictionary using different methods depending on the type you are working with:

    1. If you have a BidirectionalDictionary<TKey, TValue>, use the .AsReadOnly() method.
    2. If you are working with the IBidirectionalDictionary interface, wrap it in a new ReadOnlyBidirectionalDictionary<TKey, TValue>.
    // From a BidirectionalDictionary instance
    var readOnlyDictionary = dictionary.AsReadOnly();
    
    // From an IBidirectionalDictionary instance
    using System.Collections.ObjectModel;
    var readOnlyDictionary = new ReadOnlyBidirectionalDictionary<string, string>(dictionary);
  3. Use BidirectionalDictionary for two-way lookups

    master

    A BidirectionalDictionary (also known as a BiMap or Two-way dictionary) allows you to look up values by keys and keys by values. It is compatible with .NET Standard 2.0. You can access the reverse mapping via the .Inverse property.

    using System.Collections.Generic;
    
    var countryCapitalDictionary = new BidirectionalDictionary<string, string>()
    {
        ["Italy"] = "Rome",
        ["India"] = "New Delhi",
        ["USA"]   = "Washington, D.C.",
    };
    
    Console.WriteLine(countryCapitalDictionary["Italy"]); // "Rome"
    Console.WriteLine(countryCapitalDictionary.Inverse["Rome"]); // "Italy"
  4. Configure VML Textbox properties with CT_Textbox

    master

    Use the CT_Textbox class to represent VML textbox elements. You can set the id, style, and inset attributes. The ItemXml property allows you to store and retrieve the inner XML content of the textbox.

    To create a CT_Textbox from an existing XML node, use the Parse method.

  5. Configure VML TextPath properties with CT_TextPath

    master

    Use the CT_TextPath class to define text paths in VML. Key properties include:

    • id: The element identifier.
    • style: The CSS-like style string.
    • on: A ST_TrueFalse value indicating if the path is active.
    • fitshape: Whether the text fits the shape.
    • fitpath: Whether the text fits the path.
    • trim: Whether to trim the text.
    • xscale: The horizontal scaling factor.
    • @string: The actual text content.

    Use CT_TextPath.Parse(node, namespaceManager) to instantiate from an XML node.

  6. Configure VML Fill with CT_Fill

    master

    The CT_Fill class represents a VML fill definition. You can configure various attributes such as color, opacity, type, and source to define how a shape is filled.

    Key properties include:

    • id: Unique identifier.
    • type: The fill type (e.g., solid, gradient, tile).
    • color / color2: Color values.
    • opacity: Opacity level.
    • src: Source for the fill (e.g., an image).
    • angle: Rotation angle for gradients.

    Use AddNewFill() on a CT_Shape to initialize a new fill object.

  7. Create VML Arc elements with CT_Arc

    master
    The CT_Arc class defines a VML arc. It includes properties for the start and end angles (startAngle, endAngle) and supports various child elements like path, fill, stroke, and shadow. Note that startAngle and endAngle require setting the startAngleSpecified and endAngleSpecified flags (handled via the Specified pattern) to be included in the XML output.