Skip to content

Commit

Permalink
Merge pull request #5 from ThomasTJdev/prepped
Browse files Browse the repository at this point in the history
Prepped - refactor + only Linux support. Fixes issue #1 and #6 .
  • Loading branch information
ThomasTJdev committed Jan 6, 2022
2 parents 059df7e + 4a34039 commit a36864c
Show file tree
Hide file tree
Showing 67 changed files with 17,092 additions and 56 deletions.
42 changes: 42 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Build XLSX

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os:
- ubuntu-latest
version:
- stable

steps:
- uses: actions/checkout@v1
- uses: jiro4989/setup-nim-action@master
with:
nim-version: ${{ matrix.version }}

- name: copy libxlsxwriter.so to /usr/lib
run: |
sudo cp nimlibxlsxwriter/include/libxlsxwriter.so /usr/lib/libxlsxwriter.so
- name: Print Nim version
run: nim -v

- name: Print Nimble version
run: nimble -v

- name: Nimble Refresh
run: nimble -y refresh

- name: Nimble Install dependencies
run: nimble -y install --depsOnly

- name: Build binaries
run: nimble test
7 changes: 4 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
nimlibxlsxwriter/
tests/
!tests/*.nim
tests/*

!tests/*.nim
!tests/config.nims
104 changes: 92 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,14 @@

# General

Nimlibxlsxwriter is a [Nim](https://nim-lang.org/) wrapper for the [libxlsxwriter](https://github.com/jmcnamara/libxlsxwriter) library.
Nimlibxlsxwriter is a [Nim](https://nim-lang.org/) wrapper for the
[libxlsxwriter](https://github.com/jmcnamara/libxlsxwriter) library.


# OS support

The package only supports Linux. For legacy support of Windows/Mac see [Legacy support](legacy/LEAGACY.md).

Nimlibxlsxwriter is distributed as a [Nimble](https://github.com/nim-lang/nimble) package and depends on [nimgen](https://github.com/genotrance/nimgen) and [c2nim](https://github.com/nim-lang/c2nim/) to generate the wrappers. The libxlsxwriter source code is downloaded using Git so having ```git``` in the path is required.

# Installation

Expand All @@ -20,19 +25,40 @@ $ cd nimlibxlsxwriter
$ nimble install
```

## Dynamic XLSX library
This is required before installing the nimble package. It might already be
available on your system.

You need to build the original C sourcecode to generate the dynamic library, see
the [how to here](http://libxlsxwriter.github.io/getting_started.html), or you
can cheat, cross your fingers and do it like Github Actions:
```
$ git clone https://github.com/ThomasTJdev/nimlibxlsxwriter
$ cd nimlibxlsxwriter
# Might need `sudo`
$ cp nimlibxlsxwriter/include/libxlsxwriter.so /usr/lib/libxlsxwriter.so
```

# Want more XLSX?

Then checkout:
- [xlsx](https://github.com/xflywind/xlsx): For reading and parsing XLSX files.
- [xlsxio](https://github.com/jiiihpeeh/xlsxio-nim): For reading and writing


# Usage

```nim
import nimlibxlsxwriter/xlsxwriter
import nimlibxlsxwriter
proc main() =
# Create a new workbook and add a worksheet
var workbook: ptr lxw_workbook = workbook_new("demo.xlsx")
var worksheet: ptr lxw_worksheet = workbook_add_worksheet(workbook, nil)
var workbook = workbook_new("demo.xlsx")
var worksheet = workbook_add_worksheet(workbook, nil)
# Add a format.
var format: ptr lxw_format = workbook_add_format(workbook)
var format = workbook_add_format(workbook)
# Set the bold property for the format
format_set_bold(format)
Expand All @@ -58,12 +84,66 @@ proc main() =
main()
```

Refer to the ```tests``` diretory for examples on how the library can be used.
```nim
import nimlibxlsxwriter
# Credits
proc main() =
Nimlibxlsxwriter wraps the libxlsxwriter source code and all licensing terms of [libxlsxwriter](https://github.com/jmcnamara/libxlsxwriter) apply to the usage of this package.
# Create a new workbook and add a worksheet
var
workbook = workbook_new("demo2.xlsx")
worksheet = workbook_add_worksheet(workbook, nil)
# Text formats
var
formatHeading = workbook_add_format(workbook)
formatText = workbook_add_format(workbook)
# Heading
format_set_bold(formatHeading)
format_set_bg_color(formatHeading, 0x171921)
format_set_font_name(formatHeading, "Arial")
format_set_font_size(formatHeading, 12)
format_set_font_color(formatHeading, 0xFFFFFF)
format_set_border(formatHeading, 1)
format_set_border_color(formatHeading, 0x1000000)
format_set_align(formatHeading, 10)
format_set_align(formatHeading, 2)
format_set_text_wrap(formatHeading)
# Text
format_set_bg_color(formatText, 0xFFFFFF)
format_set_font_name(formatText, "Arial")
format_set_font_size(formatText, 10)
format_set_font_color(formatText, 0x1000000)
format_set_border(formatText, 1)
format_set_border_color(formatText, 0x1000000)
format_set_align(formatText, 10)
format_set_text_wrap(formatText)
# Write heading
discard worksheet_write_string(worksheet, 0, 0, "Nim for the win", formatHeading)
# Write some text
discard worksheet_set_column(worksheet, 0, 0, 15, nil) # Column width: col-A
discard worksheet_write_string(worksheet, 1, 0, "A-2: Procedure", formatText) # Write text
discard worksheet_set_row(worksheet, 1, 35.0, nil) # Change row height: row-2
discard worksheet_set_column(worksheet, 1, 1, 25, nil) # Column width: col-B
discard worksheet_write_string(worksheet, 2, 1, "B-3: Long procedure", formatText) # Write text
# Set print area
discard worksheet_print_area(worksheet, 0, 0, 2, 1)
discard workbook_close(workbook)
Credits go out to [c2nim](https://github.com/nim-lang/c2nim/) as well without which this package would be greatly limited in its abilities.
main()
```

Refer to the ```tests``` diretory for examples on how the library can be used.

# Credits

Credits to original author [KeepCoolWithCoolidge](https://github.com/KeepCoolWithCoolidge).
Nimlibxlsxwriter wraps the libxlsxwriter source code and all licensing terms of
[libxlsxwriter](https://github.com/jmcnamara/libxlsxwriter) apply to the usage
of this package.
34 changes: 34 additions & 0 deletions legacy/LEAGACY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Legacy notice

`nimlibxlsxwriter` was originally developed by KeepCoolWithCoolidge using
`nimgen`. Since then development of `nimgen` was deprecated and Github changed
master branch name to `main`.

`nimgen` had the external git repo branch hardcoded to `master`, which became
a problem when the C-library `libxlsxwriter` changed its branch name to `main`.

It has been a hassle to update but was partly resolved in https://github.com/ThomasTJdev/nimlibxlsxwriter/pull/4
and Genotrace was so kind to merge a pull request in `nimgen`: https://github.com/genotrance/nimgen/pull/50.


# Reason

Personally I have no need for using `nimlibxlsxwriter` on Windows, so I have
decided to remove that support. That can be categorized as a breaking change...

To give a fair notice I created the issue https://github.com/ThomasTJdev/nimlibxlsxwriter/issues/6
on the 26th og Juli 2021 with one month deadline before merging the Linux-only-PR.

I have now waited for 6 months due to using the package locally with no problem.
But *now* it's time! It's time because we have gotten another XLSX-package in
the Nimble library!


# What to do

Well, if this gives you trouble place open an issue on the GitHub repo. If you
want to use `nimgen`, then you have it right here! But no support from me.

```bash
$ nimgen nimlibxlsxwriter.cfg
```
2 changes: 1 addition & 1 deletion nimlibxlsxwriter.cfg → legacy/nimlibxlsxwriter.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -172,4 +172,4 @@ export drawing
import chart
export chart
import queue
export queue"""
export queue"""
2 changes: 2 additions & 0 deletions nimlibxlsxwriter.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
include
nimlibxlsxwriter/xlsxwriter
46 changes: 21 additions & 25 deletions nimlibxlsxwriter.nimble
Original file line number Diff line number Diff line change
@@ -1,41 +1,37 @@
# Package

version = "0.1.4"
version = "0.3.0"
author = "Original: KeepCoolWithCoolidge / Fork: ThomasTJdev"
description = "libxslxwriter wrapper for Nim"
license = "MIT"
skipDirs = @["tests"]

# Dependencies

requires "nim >= 1.2.0"
requires "nimgen >= 0.5.2"
requires "c2nim >= 0.9.14"

import distros

var cmd = ""
if detectOs(Windows):
cmd = "cmd /c "

task setup, "Checkout and generate":
exec cmd & "nimgen nimlibxlsxwriter.cfg"

before install:
setupTask()
task setup, "Check OS":
if detectOs(Windows):
quit("Cannot run on Windows. Checkout legacy/LEGACY.md for support")

task test, "Run tests":
withDir("tests"):
exec "nim c -r anatomy.nim"
exec "nim c -r array_formula.nim"
exec "nim c -r autofilter.nim"
exec "nim c -r chart_area.nim"
exec "nim c -r chart_bar.nim"
exec "nim c -r chart_clustered.nim"
exec "nim c -r chart_column.nim"
exec "nim c -r chart_data_table.nim"
exec "nim c -r chart_data_tools.nim"
exec "nim c -r chart_test.nim"
exec "nim c -r date_and_times.nim"
exec "nim c -r date_and_times_2.nim"
exec "nim c -r date_and_times_3.nim"
withDir("tests"):
exec "nim c -r anatomy.nim"
exec "nim c -r array_formula.nim"
exec "nim c -r autofilter.nim"
exec "nim c -r chart_area.nim"
exec "nim c -r chart_bar.nim"
exec "nim c -r chart_clustered.nim"
exec "nim c -r chart_column.nim"
exec "nim c -r chart_data_table.nim"
exec "nim c -r chart_data_tools.nim"
exec "nim c -r chart_test.nim"
exec "nim c -r date_and_times.nim"
exec "nim c -r date_and_times_2.nim"
exec "nim c -r date_and_times_3.nim"

before install:
setupTask()
Loading

0 comments on commit a36864c

Please sign in to comment.