Skip to content
This repository was archived by the owner on Mar 9, 2020. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 54 additions & 44 deletions EPPlus/Style/XmlAccess/ExcelNumberFormatXml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@

* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Lesser General Public License for more details.
*
* The GNU Lesser General Public License can be viewed at http://www.opensource.org/licenses/lgpl-license.php
* If you unfamiliar with this license or have questions about it, here is an http://www.gnu.org/licenses/gpl-faq.html
*
* All code and executables are provided "as is" with no warranty either express or implied.
* All code and executables are provided "as is" with no warranty either express or implied.
* The author accepts no liability for any damage or loss of business that this product may cause.
*
* Code change notes:
*
*
* Author Change Date
* ******************************************************************************
* Jan Källman Initial Release 2009-10-01
Expand All @@ -44,8 +44,8 @@ public sealed class ExcelNumberFormatXml : StyleXmlHelper
{
internal ExcelNumberFormatXml(XmlNamespaceManager nameSpaceManager) : base(nameSpaceManager)
{
}

}
internal ExcelNumberFormatXml(XmlNamespaceManager nameSpaceManager, bool buildIn): base(nameSpaceManager)
{
BuildIn = buildIn;
Expand All @@ -61,38 +61,38 @@ internal ExcelNumberFormatXml(XmlNamespaceManager nsm, XmlNode topNode) :
// const string idPath = "@numFmtId";
/// <summary>
/// Id for number format
///
///
/// Build in ID's
///
/// 0 General
/// 1 0
/// 2 0.00
/// 3 #,##0
/// 4 #,##0.00
/// 9 0%
/// 10 0.00%
/// 11 0.00E+00
/// 12 # ?/?
/// 13 # ??/??
/// 14 mm-dd-yy
/// 15 d-mmm-yy
/// 16 d-mmm
/// 17 mmm-yy
/// 18 h:mm AM/PM
/// 19 h:mm:ss AM/PM
/// 20 h:mm
/// 21 h:mm:ss
/// 22 m/d/yy h:mm
/// 37 #,##0 ;(#,##0)
/// 38 #,##0 ;[Red](#,##0)
/// 39 #,##0.00;(#,##0.00)
/// 40 #,##0.00;[Red](#,##0.00)
/// 45 mm:ss
/// 46 [h]:mm:ss
/// 47 mmss.0
/// 48 ##0.0E+0
///
/// 0 General
/// 1 0
/// 2 0.00
/// 3 #,##0
/// 4 #,##0.00
/// 9 0%
/// 10 0.00%
/// 11 0.00E+00
/// 12 # ?/?
/// 13 # ??/??
/// 14 mm-dd-yy
/// 15 d-mmm-yy
/// 16 d-mmm
/// 17 mmm-yy
/// 18 h:mm AM/PM
/// 19 h:mm:ss AM/PM
/// 20 h:mm
/// 21 h:mm:ss
/// 22 m/d/yy h:mm
/// 37 #,##0 ;(#,##0)
/// 38 #,##0 ;[Red](#,##0)
/// 39 #,##0.00;(#,##0.00)
/// 40 #,##0.00;[Red](#,##0.00)
/// 45 mm:ss
/// 46 [h]:mm:ss
/// 47 mmss.0
/// 48 ##0.0E+0
/// 49 @
/// </summary>
/// </summary>
public int NumFmtId
{
get
Expand Down Expand Up @@ -127,10 +127,10 @@ public string Format
}
internal string GetNewID(int NumFmtId, string Format)
{

if (NumFmtId < 0)
{
NumFmtId = ExcelNumberFormat.GetFromBuildIdFromFormat(Format);
NumFmtId = ExcelNumberFormat.GetFromBuildIdFromFormat(Format);
}
return NumFmtId.ToString();
}
Expand Down Expand Up @@ -225,7 +225,7 @@ internal ExcelFormatTranslator(string format, int numFmtID)
{
ToNetFormat(format, false);
ToNetFormat(format, true);
}
}
}
internal string NetTextFormat { get; private set; }
internal string NetFormat { get; private set; }
Expand Down Expand Up @@ -316,9 +316,8 @@ private void ToNetFormat(string ExcelFormat, bool forColWidth)
{
SpecialDateFormat = eSystemDateFormat.SystemLongTime;
}
else
else if (int.TryParse(li[1], NumberStyles.HexNumber, CultureInfo.InvariantCulture, out var num))
{
var num = int.Parse(li[1], NumberStyles.HexNumber);
try
{
Culture = CultureInfo.GetCultureInfo(num & 0xFFFF);
Expand All @@ -328,6 +327,17 @@ private void ToNetFormat(string ExcelFormat, bool forColWidth)
Culture = null;
}
}
else
{
try
{
Culture = CultureInfo.GetCultureInfo(li[1]);
}
catch
{
Culture = null;
}
}
}
}
else if(bracketText.StartsWith("<") ||
Expand All @@ -336,7 +346,7 @@ private void ToNetFormat(string ExcelFormat, bool forColWidth)
{
SpecialDateFormat = eSystemDateFormat.Conditional;
}
else
else
{
sb.Append(bracketText);
SpecialDateFormat = eSystemDateFormat.Conditional;
Expand Down Expand Up @@ -394,7 +404,7 @@ private void ToNetFormat(string ExcelFormat, bool forColWidth)
if (c == '.' || c == ',')
{
sb.Append('\\');
}
}
sb.Append(c);
prevBslsh = false;
}
Expand Down Expand Up @@ -563,7 +573,7 @@ internal string FormatFraction(double d)
{
fixedDenominator = 0;
}

if (d == 0 || double.IsNaN(d))
{
if (fmt[0].Trim() == "" && fmt[1].Trim() == "")
Expand Down Expand Up @@ -624,7 +634,7 @@ internal string FormatFraction(double d)

divRes = 1 / (divRes - intDivRes); //Rest
}

numerator = (int)numerators[listPos];
denomerator = (int)denominators[listPos];
}
Expand Down