1 | /*******************************************************************************
|
---|
2 | * You may amend and distribute as you like, but don't remove this header!
|
---|
3 | *
|
---|
4 | * EPPlus provides server-side generation of Excel 2007/2010 spreadsheets.
|
---|
5 | * See http://www.codeplex.com/EPPlus for details.
|
---|
6 | *
|
---|
7 | * Copyright (C) 2011 Jan Källman
|
---|
8 | *
|
---|
9 | * This library is free software; you can redistribute it and/or
|
---|
10 | * modify it under the terms of the GNU Lesser General Public
|
---|
11 | * License as published by the Free Software Foundation; either
|
---|
12 | * version 2.1 of the License, or (at your option) any later version.
|
---|
13 |
|
---|
14 | * This library is distributed in the hope that it will be useful,
|
---|
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
---|
17 | * See the GNU Lesser General Public License for more details.
|
---|
18 | *
|
---|
19 | * The GNU Lesser General Public License can be viewed at http://www.opensource.org/licenses/lgpl-license.php
|
---|
20 | * If you unfamiliar with this license or have questions about it, here is an http://www.gnu.org/licenses/gpl-faq.html
|
---|
21 | *
|
---|
22 | * All code and executables are provided "as is" with no warranty either express or implied.
|
---|
23 | * The author accepts no liability for any damage or loss of business that this product may cause.
|
---|
24 | *
|
---|
25 | * Code change notes:
|
---|
26 | *
|
---|
27 | * Author Change Date
|
---|
28 | * ******************************************************************************
|
---|
29 | * Jan Källman Initial Release 2009-10-01
|
---|
30 | * Jan Källman License changed GPL-->LGPL 2011-12-16
|
---|
31 | *******************************************************************************/
|
---|
32 | using System;
|
---|
33 | using System.Collections.Generic;
|
---|
34 | using System.Text;
|
---|
35 | using System.Text.RegularExpressions;
|
---|
36 | using System.Globalization;
|
---|
37 |
|
---|
38 | namespace OfficeOpenXml.Style
|
---|
39 | {
|
---|
40 | /// <summary>
|
---|
41 | /// The numberformat of the cell
|
---|
42 | /// </summary>
|
---|
43 | public sealed class ExcelNumberFormat : StyleBase
|
---|
44 | {
|
---|
45 | internal ExcelNumberFormat(ExcelStyles styles, OfficeOpenXml.XmlHelper.ChangedEventHandler ChangedEvent, int PositionID, string Address, int index) :
|
---|
46 | base(styles, ChangedEvent, PositionID, Address)
|
---|
47 | {
|
---|
48 | Index = index;
|
---|
49 | }
|
---|
50 | /// <summary>
|
---|
51 | /// The numeric index fror the format
|
---|
52 | /// </summary>
|
---|
53 | public int NumFmtID
|
---|
54 | {
|
---|
55 | get
|
---|
56 | {
|
---|
57 | return Index;
|
---|
58 | }
|
---|
59 | //set
|
---|
60 | //{
|
---|
61 | // _ChangedEvent(this, new StyleChangeEventArgs(eStyleClass.Numberformat, "NumFmtID", value, _workSheetID, _address));
|
---|
62 | //}
|
---|
63 | }
|
---|
64 | /// <summary>
|
---|
65 | /// The numberformat
|
---|
66 | /// </summary>
|
---|
67 | public string Format
|
---|
68 | {
|
---|
69 | get
|
---|
70 | {
|
---|
71 | for(int i=0;i<_styles.NumberFormats.Count;i++)
|
---|
72 | {
|
---|
73 | if(Index==_styles.NumberFormats[i].NumFmtId)
|
---|
74 | {
|
---|
75 | return _styles.NumberFormats[i].Format;
|
---|
76 | }
|
---|
77 | }
|
---|
78 | return "general";
|
---|
79 | }
|
---|
80 | set
|
---|
81 | {
|
---|
82 | _ChangedEvent(this, new StyleChangeEventArgs(eStyleClass.Numberformat, eStyleProperty.Format, (string.IsNullOrEmpty(value) ? "General" : value), _positionID, _address));
|
---|
83 | }
|
---|
84 | }
|
---|
85 |
|
---|
86 | internal override string Id
|
---|
87 | {
|
---|
88 | get
|
---|
89 | {
|
---|
90 | return Format;
|
---|
91 | }
|
---|
92 | }
|
---|
93 | /// <summary>
|
---|
94 | /// If the numeric format is a build-in from.
|
---|
95 | /// </summary>
|
---|
96 | public bool BuildIn { get; private set; }
|
---|
97 |
|
---|
98 | internal static string GetFromBuildInFromID(int _numFmtId)
|
---|
99 | {
|
---|
100 | switch (_numFmtId)
|
---|
101 | {
|
---|
102 | case 0:
|
---|
103 | return "General";
|
---|
104 | case 1:
|
---|
105 | return "0";
|
---|
106 | case 2:
|
---|
107 | return "0.00";
|
---|
108 | case 3:
|
---|
109 | return "#,##0";
|
---|
110 | case 4:
|
---|
111 | return "#,##0.00";
|
---|
112 | case 9:
|
---|
113 | return "0%";
|
---|
114 | case 10:
|
---|
115 | return "0.00%";
|
---|
116 | case 11:
|
---|
117 | return "0.00E+00";
|
---|
118 | case 12:
|
---|
119 | return "# ?/?";
|
---|
120 | case 13:
|
---|
121 | return "# ??/??";
|
---|
122 | case 14:
|
---|
123 | return "mm-dd-yy";
|
---|
124 | case 15:
|
---|
125 | return "d-mmm-yy";
|
---|
126 | case 16:
|
---|
127 | return "d-mmm";
|
---|
128 | case 17:
|
---|
129 | return "mmm-yy";
|
---|
130 | case 18:
|
---|
131 | return "h:mm AM/PM";
|
---|
132 | case 19:
|
---|
133 | return "h:mm:ss AM/PM";
|
---|
134 | case 20:
|
---|
135 | return "h:mm";
|
---|
136 | case 21:
|
---|
137 | return "h:mm:ss";
|
---|
138 | case 22:
|
---|
139 | return "m/d/yy h:mm";
|
---|
140 | case 37:
|
---|
141 | return "#,##0 ;(#,##0)";
|
---|
142 | case 38:
|
---|
143 | return "#,##0 ;[Red](#,##0)";
|
---|
144 | case 39:
|
---|
145 | return "#,##0.00;(#,##0.00)";
|
---|
146 | case 40:
|
---|
147 | return "#,##0.00;[Red](#,##0.00)";
|
---|
148 | case 45:
|
---|
149 | return "mm:ss";
|
---|
150 | case 46:
|
---|
151 | return "[h]:mm:ss";
|
---|
152 | case 47:
|
---|
153 | return "mmss.0";
|
---|
154 | case 48:
|
---|
155 | return "##0.0";
|
---|
156 | case 49:
|
---|
157 | return "@";
|
---|
158 | default:
|
---|
159 | return string.Empty;
|
---|
160 | }
|
---|
161 | }
|
---|
162 | internal static int GetFromBuildIdFromFormat(string format)
|
---|
163 | {
|
---|
164 | switch (format)
|
---|
165 | {
|
---|
166 | case "General":
|
---|
167 | case "":
|
---|
168 | return 0;
|
---|
169 | case "0":
|
---|
170 | return 1;
|
---|
171 | case "0.00":
|
---|
172 | return 2;
|
---|
173 | case "#,##0":
|
---|
174 | return 3;
|
---|
175 | case "#,##0.00":
|
---|
176 | return 4;
|
---|
177 | case "0%":
|
---|
178 | return 9;
|
---|
179 | case "0.00%":
|
---|
180 | return 10;
|
---|
181 | case "0.00E+00":
|
---|
182 | return 11;
|
---|
183 | case "# ?/?":
|
---|
184 | return 12;
|
---|
185 | case "# ??/??":
|
---|
186 | return 13;
|
---|
187 | case "mm-dd-yy":
|
---|
188 | return 14;
|
---|
189 | case "d-mmm-yy":
|
---|
190 | return 15;
|
---|
191 | case "d-mmm":
|
---|
192 | return 16;
|
---|
193 | case "mmm-yy":
|
---|
194 | return 17;
|
---|
195 | case "h:mm AM/PM":
|
---|
196 | return 18;
|
---|
197 | case "h:mm:ss AM/PM":
|
---|
198 | return 19;
|
---|
199 | case "h:mm":
|
---|
200 | return 20;
|
---|
201 | case "h:mm:ss":
|
---|
202 | return 21;
|
---|
203 | case "m/d/yy h:mm":
|
---|
204 | return 22;
|
---|
205 | case "#,##0 ;(#,##0)":
|
---|
206 | return 37;
|
---|
207 | case "#,##0 ;[Red](#,##0)":
|
---|
208 | return 38;
|
---|
209 | case "#,##0.00;(#,##0.00)":
|
---|
210 | return 39;
|
---|
211 | case "#,##0.00;[Red](#,##0.00)":
|
---|
212 | return 40;
|
---|
213 | case "mm:ss":
|
---|
214 | return 45;
|
---|
215 | case "[h]:mm:ss":
|
---|
216 | return 46;
|
---|
217 | case "mmss.0":
|
---|
218 | return 47;
|
---|
219 | case "##0.0":
|
---|
220 | return 48;
|
---|
221 | case "@":
|
---|
222 | return 49;
|
---|
223 | default:
|
---|
224 | return int.MinValue;
|
---|
225 | }
|
---|
226 | }
|
---|
227 | }
|
---|
228 | }
|
---|