GithubHelp home page GithubHelp logo

guandy2016 / npoi Goto Github PK

View Code? Open in Web Editor NEW

This project forked from dotnetcore/npoi

0.0 1.0 0.0 63.4 MB

A .NET library for reading and writing Microsoft Office binary and OOXML file formats.

License: Apache License 2.0

C# 99.66% PowerShell 0.03% CoffeeScript 0.01% Smalltalk 0.31%

npoi's Introduction

NPOI

Build status

This project is migrated from Tony Qu's NPOI by .NET Core Community.

NuGet Package

Install-Package DotNetCore.NPOI

How can it work on Linux?

On Linux, you need install libgdiplus. Since 1.2.0 libdl is also required.

  • Ubuntu 16.04 and above:

    • apt-get install libgdiplus libc6-dev
    • cd /usr/lib
    • ln -s libgdiplus.so gdiplus.dll
  • Fedora 23 and above:

    • dnf install libgdiplus
    • cd /usr/lib64/
    • ln -s libgdiplus.so.0 gdiplus.dll
  • CentOS 7 and above:

    • yum install autoconf automake libtool
    • yum install freetype-devel fontconfig libXft-devel
    • yum install libjpeg-turbo-devel libpng-devel giflib-devel libtiff-devel libexif-devel
    • yum install glib2-devel cairo-devel
    • git clone https://github.com/mono/libgdiplus
    • cd libgdiplus
    • ./autogen.sh
    • make
    • make install
    • cd /usr/lib64/
    • ln -s /usr/local/lib/libgdiplus.so gdiplus.dll
  • Docker

    • Alpine
    # base sdk-alpine/aspnetcore-runtime-alpine images
    
    RUN echo "http://dl-cdn.alpinelinux.org/alpine/edge/testing" >> /etc/apk/repositories
    RUN apk --update add libgdiplus
    
    • Debian
    FROM microsoft/dotnet:2.1-aspnetcore-runtime
    RUN apt-get update && apt-get install -y libgdiplus libc6-dev && ln -s /usr/lib/libgdiplus.so /usr/lib/gdiplus.dll
    ...
    

Getting Started

Export Excel

var newFile = @"newbook.core.xlsx";

using (var fs = new FileStream(newFile, FileMode.Create, FileAccess.Write)) {

    IWorkbook workbook = new XSSFWorkbook();

    ISheet sheet1 = workbook.CreateSheet("Sheet1");

    sheet1.AddMergedRegion(new CellRangeAddress(0, 0, 0, 10));
    var rowIndex = 0;
    IRow row = sheet1.CreateRow(rowIndex);
    row.Height = 30 * 80;
    row.CreateCell(0).SetCellValue("this is content");
    sheet1.AutoSizeColumn(0);
    rowIndex++;

    var sheet2 = workbook.CreateSheet("Sheet2");
    var style1 = workbook.CreateCellStyle();
    style1.FillForegroundColor = HSSFColor.Blue.Index2;
    style1.FillPattern = FillPattern.SolidForeground;

    var style2 = workbook.CreateCellStyle();
    style2.FillForegroundColor = HSSFColor.Yellow.Index2;
    style2.FillPattern = FillPattern.SolidForeground;

    var cell2 = sheet2.CreateRow(0).CreateCell(0);
    cell2.CellStyle = style1;
    cell2.SetCellValue(0);

    cell2 = sheet2.CreateRow(1).CreateCell(0);
    cell2.CellStyle = style2;
    cell2.SetCellValue(1);

    workbook.Write(fs);
}

Export Word

var newFile2 = @"newbook.core.docx";
using (var fs = new FileStream(newFile2, FileMode.Create, FileAccess.Write)) {
    XWPFDocument doc = new XWPFDocument();
    var p0 = doc.CreateParagraph();
    p0.Alignment = ParagraphAlignment.CENTER;
    XWPFRun r0 = p0.CreateRun();
    r0.FontFamily = "microsoft yahei";
    r0.FontSize = 18;
    r0.IsBold = true;
    r0.SetText("This is title");

    var p1 = doc.CreateParagraph();
    p1.Alignment = ParagraphAlignment.LEFT;
    p1.IndentationFirstLine = 500;
    XWPFRun r1 = p1.CreateRun();
    r1.FontFamily = "·ÂËÎ";
    r1.FontSize = 12;
    r1.IsBold = true;
    r1.SetText("This is content, content content content content content content content content content");

    doc.Write(fs);
}

npoi's People

Contributors

yang-xiaodong avatar joshcomley avatar gtbuchanan avatar baiyunchen avatar jondavidford avatar r0bnet avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.