Git Product home page Git Product logo

picoxlsx's Introduction

PicoXLSX PicoXLSX

nuget license FOSSA Status

PicoXLSX is a small .NET library written in C#, to create Microsoft Excel files in the XLSX format (Microsoft Excel 2007 or newer) in an easy and native way

  • Minimum of dependencies (*
  • No need for an installation of Microsoft Office
  • No need for Office interop libraries
  • No need for 3rd party libraries
  • No need for an installation of the Microsoft Open Office XML SDK (OOXML)

Please have a look at the successor library NanoXLSX for reader support.

Project website: https://picoxlsx.rabanti.ch See the Change Log for recent updates.

What's new in version 3.x

  • Copy functions for worksheets
  • Several additional checks, exception handling and updated documentation

Note: Most changes came from the rewritten NanoXLSX library v2.0. Unit testing was also introduced there. Therefore, the change list in PicoXLSX is not as long as in NanoXLSX, since many these changes are dealing with reader functionality.

Roadmap

Version 3.x of PicoXLSX was completely overhauled along with NanoXLSX v3.x. However, v3.x it is not planned as a LTS version. The upcoming v4.x is supposed to introduce some important functions, like in-line cell formatting, better formula handling and additional worksheet features. Furthermore, it is planned to introduce more modern OOXML features like the SHA256 implementation of worksheet passwords. One of the main aspects of this upcoming version is the retirement of the original code base in favor of a facade, using NanoXLSX as single dependency. This will reduce the maintenance effort dramatically.

Requirements

PicoXLSX was created with .NET version 4.5. Newer versions like 4.6 are working and tested. Furthermore, .NET Standard 2.0 is supported since v2.9. Older versions of.NET like 3.5 and 4.0 may also work with minor changes. Some functions introduced in .NET 4.5 were used and must be adapted in this case.

.NET 4.5 or newer

*)The only requirement to compile the library besides .NET (v4.5 or newer) is the assembly WindowsBase, as well as System.IO.Compression. These assemblies are standard components in all Microsoft Windows systems (except Windows RT systems). If your IDE of choice supports referencing assemblies from the Global Assembly Cache (GAC) of Windows, select WindowsBase and Compression from there. If you want so select the DLLs manually and Microsoft Visual Studio is installed on your system, the DLL of WindowsBase can be found most likely under "c:\Program Files\Reference Assemblies\Microsoft\Framework\v3.0\WindowsBase.dll", as well as System.IO.Compression under "c:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.5\System.IO.Compression.dll". Otherwise you find them in the GAC, under "c:\Windows\Microsoft.NET\assembly\GAC_MSIL\WindowsBase" and "c:\Windows\Microsoft.NET\assembly\GAC_MSIL\System.IO.Compression"

The NuGet package does not require dependencies

.NET Standard

.NET Standard v2.0 resolves the dependency System.IO.Compression automatically, using NuGet and does not rely anymore on WindowsBase in the development environment. In contrast to the .NET >=4.5 version, no manually added dependencies necessary (as assembly references) to compile the library.

Please note that the demo project of the .NET Standard version will not work in Visual Studio 2017. To get the build working, unload the demo project of the .NET Standard version.

Documentation project

If you want to compile the documentation project (folder: Documentation; project file: shfbproj), you need also the Sandcastle Help File Builder (SHFB). It is also freely available. But you don't need the documentation project to build the NanoXLSX library.

The .NET version of the documentation may vary, based on the installation. If v4.5 is not available, upgrade to target to a newer version, like v4.6

Installation

Using NuGet

By Package Manager (PM):

Install-Package PicoXLSX

By .NET CLI:

dotnet add package PicoXLSX

As DLL

Simply place the PicoXLSX DLL into your .NET project and add a reference to it. Please keep in mind that the .NET version of your solution must match with the runtime version of the PicoXLSX DLL (currently compiled with 4.5 and .NET Standard 2.0).

As source files

Place all .CS files from the PicoXLSX source folder into your project. You can place them into a sub-folder if you wish. The files contains definitions for workbooks, worksheets, cells, styles, meta-data, low level methods and exceptions. In case of the .NET >=4.5 version, the necessary dependencies have to be referenced as well.

Usage

Quick Start (shortened syntax)

 Workbook workbook = new Workbook("myWorkbook.xlsx", "Sheet1");         // Create new workbook with a worksheet called Sheet1
 workbook.WS.Value("Some Data");                                        // Add cell A1
 workbook.WS.Formula("=A1");                                            // Add formula to cell B1
 workbook.WS.Down();                                                    // Go to row 2
 workbook.WS.Value(DateTime.Now, Style.BasicStyles.Bold);               // Add formatted value to cell A2
 workbook.Save();                                                       // Save the workbook as myWorkbook.xlsx

Quick Start (regular syntax)

 Workbook workbook = new Workbook("myWorkbook.xlsx", "Sheet1");         // Create new workbook with a worksheet called Sheet1
 workbook.CurrentWorksheet.AddNextCell("Some Data");                    // Add cell A1
 workbook.CurrentWorksheet.AddNextCell(42);                             // Add cell B1
 workbook.CurrentWorksheet.GoToNextRow();                               // Go to row 2
 workbook.CurrentWorksheet.AddNextCell(DateTime.Now);                   // Add cell A2
 workbook.Save();                                                       // Save the workbook as myWorkbook.xlsx

Further References

See the full API-Documentation at: https://rabanti-github.github.io/PicoXLSX/.

The Demo project contains 17 simple use cases. You can find also the full documentation in the Documentation-Folder (html files or single chm file) or as C# documentation in the particular .CS files.

See also: Getting started in the Wiki

License

FOSSA Status

picoxlsx's People

Contributors

actions-user avatar fossabot avatar rabanti-github avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

picoxlsx's Issues

Individual Cell Styles

Hello,

Appreciate the library. I'm having an issue and I'm not sure if its just my lack of understanding or if its perhaps a bug.

When I run the following code (hand typed here, so ignore syntactical errors) I would have expected that my row of data to have a gray background except for the cell in column 2 having a red background.

workbook.CurrentWorksheet.AddCellRange(data, new Cell.Address(0, idx), new Cell.Address(data.Count - 1, idx), Style.BasicStyles.ColorizedBackground("a6a1a1"));
workbook.CurrentWorksheet.GetCell(2, idx).SetStyle(Style.BasicStyles.ColorizedBackground("bf6262"));

It currently changes the style for the whole row to have the red background.
I though perhaps it was the fact that I was adding a range of data instead of a single cell at a time so I tried this as well, with the same result:

data.ForEach(p=> workbook.CurrentWorksheet.AddNextCell(p, Style.BasicStyles.ColorizedBackground("a6a1a1")));
workbook.CurrentWorksheet.GetCell(2, 0).SetStyle(Style.BasicStyles.ColorizedBackground("bf6262"));

Would you expect it to change the style of the whole row or am I doing something wrong?

Features request

Hi,
I'm missing some features.

  • Write RichText to cells
  • Add conditional formattings to cells
  • Some more overloads for convenience like to make the switch to library more easy:
    Cell.Range(startColumn, startRow, endColumn, endRow)).
    Workbooks.Add("name") which return a new workbook

Perhaps you can put them on the roadmap.

Thanks

What about basic read access?

Hey,

I'm entertaining using this. Based on the documentation it seems like this tool is intended to write to disk only. Can I use this to simply iterate and read spreadsheet rows?

I'm avoiding the interlop assemblies for such a simple task.

Tab Color

Is it possible to change tab color? I was looking for something like this worksheet.TabColor but didn't found.

Merged cells style border lost?

Hello,

It looks like merged cell style keeps borders only for top-left cell, does not matter in which order value, style and merge happened:

           var style = new Style();
           style.CurrentBorder.RightStyle = Style.Border.StyleValue.medium;

           var wb = new Workbook(true);
           var sh = wb.CurrentWorksheet;

           int xy = 1;
           // Value, Merge, Style
           sh.AddCell("V,M,S", xy, xy);
           sh.MergeCells(new Cell.Address(xy, xy), new Cell.Address(xy, xy + 1));
           sh.SetStyle(new Cell.Address(xy, xy), new Cell.Address(xy, xy + 1), style);

           xy = 3;
           // Value, Style, Merge
           sh.AddCell("V,S,M", xy, xy);
           sh.SetStyle(new Cell.Address(xy, xy), new Cell.Address(xy, xy + 1), style);
           sh.MergeCells(new Cell.Address(xy, xy), new Cell.Address(xy, xy + 1));

           xy = 5;
           // no Value, Style, Merge
           sh.SetStyle(new Cell.Address(xy, xy), new Cell.Address(xy, xy + 1), style);
           sh.MergeCells(new Cell.Address(xy, xy), new Cell.Address(xy, xy + 1));

           xy = 7;
           // no Value, Merge, Style
           sh.MergeCells(new Cell.Address(xy, xy), new Cell.Address(xy, xy + 1));
           sh.SetStyle(new Cell.Address(xy, xy), new Cell.Address(xy, xy + 1), style);

           wb.SaveAs("c:\\temp\\merge.xlsx");`

изображение

I was also trying to assign style only to left-top corder before merge in hope that it will be applied to the whole merged cell - no luck as well.

Is it a bug or this needs to be written in some other way?

SaveAsStream closes the Stream

When using the SaveAsStream Method the Stream is closed. This is mostly ok with a FileStream, but with a MemoryStream you can't read the Stream into something else that accepts a Stream. The Demo's say you can use a MemoryStream, but I'm not sure how you could ever do that. I am using this to create an XLSX from a DataTable and then archive it into a document repo via its API. Since the MemoryStream is closed I can't archive it directly from the Stream. I have to use a FileStream or Save the file which does the same thing. Then read the saved file to archive it. It works with the work around so it isn't critical, but figured I was log it as an issue since the Demo says MemoryStreams are supported. Thanks.

MemoryStream.CanWrite evaluates to false after calling the SaveAsStream method.

Cells' style are not retain when merging cells

Hi, when merging several cells, for which the first has an applied style, the merged cell doesn't have any style applied.
The method «ResolveMergedCells» always replace the style of ALL CELLS by the MergeCellStyle (which is empty).

if (pos != 0)
   {
      cell.DataType = Cell.CellType.EMPTY;
   }
   cell.SetStyle(mergeStyle);

To preserve the style of the first cell, it should be:

if (pos != 0)
   {
      cell.DataType = Cell.CellType.EMPTY;
      cell.SetStyle(mergeStyle);
   }

custom cell style for dates

Hi,

How do you define a cell style custom format for a date ? I wanted to make the cell style for a date as yyyy.mm.dd

Regards,

--

Please delete me. I created it wrongly here where it belongs to NanoXLSX

good job

good job !!

new version, get it ,thanks.

Bug SetWoorkbookProtection

Hi, i think there is a bug here :
image
a white space is missing in workkbook.xml file before workBookPassword property.
this bug corrupts the xlsx file when user try to set workbookProtection.

RichTextString

When generating files, RichTextString is not supported, similar to Excel's Cell.Characters

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.