Skip to content

Commit

Permalink
Merge pull request xou#123 from rrmartins/master
Browse files Browse the repository at this point in the history
New date format
  • Loading branch information
xou committed May 26, 2022
2 parents ca206a4 + 936390e commit 147628a
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
14 changes: 7 additions & 7 deletions example.exs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@

require Elixlsx

alias Elixlsx.Sheet
alias Elixlsx.Workbook
alias Elixlsx.{Sheet, Workbook}

sheet1 =
Sheet.with_name("First")
sheet1 = Sheet.with_name("First")
# Set cell B2 to the string "Hi". :)
|> Sheet.set_cell("B2", "Hi")
# Optionally, set font properties:
Expand All @@ -21,17 +19,19 @@ sheet1 =
|> Sheet.set_cell("A3", 1_448_882_362, datetime: true)
# datetime: true outputs date and time, yyyymmdd limits the output to just the date
|> Sheet.set_cell("A4", 1_448_882_362, yyyymmdd: true)
# datetime: true ouputs date and time, yyyymmdd limits the output to just the date
|> Sheet.set_cell("A5", 1_448_882_362, yyyymm: true)
# make some room in the first column, otherwise the date will only show up as ###
|> Sheet.set_col_width("A", 18.0)
# Cell borders
|> Sheet.set_cell("A5", "Double border", border: [bottom: [style: :double, color: "#cc3311"]])
|> Sheet.set_cell("A6", "Double border", border: [bottom: [style: :double, color: "#cc3311"]])
# Formatting with empty content
|> Sheet.set_cell("A5", :empty,
|> Sheet.set_cell("A7", :empty,
bg_color: "#ffff00",
border: [bottom: [style: :double, color: "#cc3311"]]
)
# Boolean value
|> Sheet.set_cell("A6", true)
|> Sheet.set_cell("A7", true)
# Formula
|> Sheet.set_cell("E1", 1.2, num_format: "0.00")
|> Sheet.set_cell("E2", 2, num_format: "0.00")
Expand Down
10 changes: 10 additions & 0 deletions lib/elixlsx/style/num_fmt.ex
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ defmodule Elixlsx.Style.NumFmt do
props[:yyyymmdd] ->
date_yyyy_mm_dd()

props[:yyyymm] ->
date_yyyy_mm()

props[:datetime] ->
date_datetime()

Expand All @@ -39,6 +42,13 @@ defmodule Elixlsx.Style.NumFmt do
%NumFmt{format: "yyyy-mm-dd"}
end

@doc ~S"""
Returns a semi-ISP date format only month and year (YYYY-MM)
"""
def date_yyyy_mm do
%NumFmt{format: "yyyy-mm"}
end

@doc ~S"""
Returns a standard semi-iso datetime format.
"""
Expand Down
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ defmodule Elixlsx.Mixfile do
use Mix.Project

@source_url "https://github.com/xou/elixlsx"
@version "0.5.1"
@version "0.5.2"

def project do
[
Expand Down

0 comments on commit 147628a

Please sign in to comment.