Skip to content

Commit

Permalink
Added XlsxNumberFormat.Text (a.k.a. @).
Browse files Browse the repository at this point in the history
  • Loading branch information
Salvo Isaja committed Jul 6, 2020
1 parent 9cae359 commit f0f918b
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 4 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,7 @@ Excel defines and reserves many "magic" number formats, and this library exposes
* `XlsxNumberFormat.Scientific`: scientific notation with two decimals and two-digit exponent, that is the format code `"0.00E+00"`.
* `XlsxNumberFormat.ShortDate`: localized day, month and year as digits; for a European format the equivalent code would be `"dd/mm/yyyy"` but the actual code would be locale-dependent.
* `XlsxNumberFormat.ShortDateTime`: localized day, month and year as digits with hours and minutes; for a European format the equivalent code would be `"dd/mm/yyyy hh:mm"` but the actual code would be locale-dependent.
* `XlsxNumberFormat.Text`: treat newly inserted numbers as text, that is the format code `"@"`.


#### Alignment
Expand Down Expand Up @@ -480,5 +481,4 @@ Redistribution and use in source and binary forms, with or without modification,

2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
,
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2 changes: 2 additions & 0 deletions examples/Examples/NumberFormats.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public static void Run()
var scientificStyle = XlsxStyle.Default.With(XlsxNumberFormat.Scientific);
var shortDateStyle = XlsxStyle.Default.With(XlsxNumberFormat.ShortDate);
var shortDateTimeStyle = XlsxStyle.Default.With(XlsxNumberFormat.ShortDateTime);
var textStyle = XlsxStyle.Default.With(XlsxNumberFormat.Text);
var customStyle1 = XlsxStyle.Default.With(customNumberFormat1);
var customStyle2 = XlsxStyle.Default.With(customNumberFormat2);

Expand All @@ -64,6 +65,7 @@ public static void Run()
.BeginRow().Write(nameof(XlsxNumberFormat.Scientific)).Write(1234.5678, scientificStyle).Write(1.2, scientificStyle)
.BeginRow().Write(nameof(XlsxNumberFormat.ShortDate)).Write(1234.5678, shortDateStyle).Write(1.2, shortDateStyle)
.BeginRow().Write(nameof(XlsxNumberFormat.ShortDateTime)).Write(1234.5678, shortDateTimeStyle).Write(1.2, shortDateTimeStyle)
.BeginRow().Write(nameof(XlsxNumberFormat.Text)).Write(1234.5678, textStyle).Write(1.2, textStyle)
.BeginRow().Write(customNumberFormat1.FormatCode).Write(1234.5678, customStyle1).Write(1.2, customStyle1)
.BeginRow().Write(customNumberFormat2.FormatCode).Write(1234.5678, customStyle2).Write(1.2, customStyle2);
}
Expand Down
2 changes: 1 addition & 1 deletion src/LargeXlsx/LargeXlsx.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<Version>1.0.0</Version>
<Version>1.1.0</Version>
<Authors>Salvo Isaja</Authors>
<Company>Salvo Isaja</Company>
<Copyright>Copyright 2020 Salvatore Isaja</Copyright>
Expand Down
3 changes: 2 additions & 1 deletion src/LargeXlsx/Stylesheet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ public Stylesheet()
[XlsxNumberFormat.TwoDecimalPercentage] = 10,
[XlsxNumberFormat.Scientific] = 11,
[XlsxNumberFormat.ShortDate] = 14,
[XlsxNumberFormat.ShortDateTime] = 22
[XlsxNumberFormat.ShortDateTime] = 22,
[XlsxNumberFormat.Text] = 49
};
_nextNumberFormatId = FirstCustomNumberFormatId;

Expand Down
1 change: 1 addition & 0 deletions src/LargeXlsx/XlsxNumberFormat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public class XlsxNumberFormat : IEquatable<XlsxNumberFormat>
public static readonly XlsxNumberFormat Scientific = new XlsxNumberFormat("0.00E+00");
public static readonly XlsxNumberFormat ShortDate = new XlsxNumberFormat("dd/mm/yyyy");
public static readonly XlsxNumberFormat ShortDateTime = new XlsxNumberFormat("dd/mm/yyyy hh:mm");
public static readonly XlsxNumberFormat Text = new XlsxNumberFormat("@");

public string FormatCode { get; }

Expand Down

0 comments on commit f0f918b

Please sign in to comment.