[12074] | 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 OfficeOpenXml.Style.XmlAccess;
|
---|
| 36 |
|
---|
| 37 | namespace OfficeOpenXml.Style
|
---|
| 38 | {
|
---|
| 39 | /// <summary>
|
---|
| 40 | /// Toplevel class for cell styling
|
---|
| 41 | /// </summary>
|
---|
| 42 | public sealed class ExcelStyle : StyleBase
|
---|
| 43 | {
|
---|
| 44 | internal ExcelStyle(ExcelStyles styles, OfficeOpenXml.XmlHelper.ChangedEventHandler ChangedEvent, int positionID, string Address, int xfsId) :
|
---|
| 45 | base(styles, ChangedEvent, positionID, Address)
|
---|
| 46 | {
|
---|
| 47 | Index = xfsId;
|
---|
| 48 | ExcelXfs xfs;
|
---|
| 49 | if (positionID > -1)
|
---|
| 50 | {
|
---|
| 51 | xfs = _styles.CellXfs[xfsId];
|
---|
| 52 | }
|
---|
| 53 | else
|
---|
| 54 | {
|
---|
| 55 | xfs = _styles.CellStyleXfs[xfsId];
|
---|
| 56 | }
|
---|
| 57 | Styles = styles;
|
---|
| 58 | PositionID = positionID;
|
---|
| 59 | Numberformat = new ExcelNumberFormat(styles, ChangedEvent, PositionID, Address, xfs.NumberFormatId);
|
---|
| 60 | Font = new ExcelFont(styles, ChangedEvent, PositionID, Address, xfs.FontId);
|
---|
| 61 | Fill = new ExcelFill(styles, ChangedEvent, PositionID, Address, xfs.FillId);
|
---|
| 62 | Border = new Border(styles, ChangedEvent, PositionID, Address, xfs.BorderId);
|
---|
| 63 | }
|
---|
| 64 | /// <summary>
|
---|
| 65 | /// Numberformat
|
---|
| 66 | /// </summary>
|
---|
| 67 | public ExcelNumberFormat Numberformat { get; set; }
|
---|
| 68 | /// <summary>
|
---|
| 69 | /// Font styling
|
---|
| 70 | /// </summary>
|
---|
| 71 | public ExcelFont Font { get; set; }
|
---|
| 72 | /// <summary>
|
---|
| 73 | /// Fill Styling
|
---|
| 74 | /// </summary>
|
---|
| 75 | public ExcelFill Fill { get; set; }
|
---|
| 76 | /// <summary>
|
---|
| 77 | /// Border
|
---|
| 78 | /// </summary>
|
---|
| 79 | public Border Border { get; set; }
|
---|
| 80 | /// <summary>
|
---|
| 81 | /// The horizontal alignment in the cell
|
---|
| 82 | /// </summary>
|
---|
| 83 | public ExcelHorizontalAlignment HorizontalAlignment
|
---|
| 84 | {
|
---|
| 85 | get
|
---|
| 86 | {
|
---|
| 87 | return _styles.CellXfs[Index].HorizontalAlignment;
|
---|
| 88 | }
|
---|
| 89 | set
|
---|
| 90 | {
|
---|
| 91 | _ChangedEvent(this, new StyleChangeEventArgs(eStyleClass.Style, eStyleProperty.HorizontalAlign, value, _positionID, _address));
|
---|
| 92 | }
|
---|
| 93 | }
|
---|
| 94 | /// <summary>
|
---|
| 95 | /// The vertical alignment in the cell
|
---|
| 96 | /// </summary>
|
---|
| 97 | public ExcelVerticalAlignment VerticalAlignment
|
---|
| 98 | {
|
---|
| 99 | get
|
---|
| 100 | {
|
---|
| 101 | return _styles.CellXfs[Index].VerticalAlignment;
|
---|
| 102 | }
|
---|
| 103 | set
|
---|
| 104 | {
|
---|
| 105 | _ChangedEvent(this, new StyleChangeEventArgs(eStyleClass.Style, eStyleProperty.VerticalAlign, value, _positionID, _address));
|
---|
| 106 | }
|
---|
| 107 | }
|
---|
| 108 | /// <summary>
|
---|
| 109 | /// Wrap the text
|
---|
| 110 | /// </summary>
|
---|
| 111 | public bool WrapText
|
---|
| 112 | {
|
---|
| 113 | get
|
---|
| 114 | {
|
---|
| 115 | return _styles.CellXfs[Index].WrapText;
|
---|
| 116 | }
|
---|
| 117 | set
|
---|
| 118 | {
|
---|
| 119 | _ChangedEvent(this, new StyleChangeEventArgs(eStyleClass.Style, eStyleProperty.WrapText, value, _positionID, _address));
|
---|
| 120 | }
|
---|
| 121 | }
|
---|
| 122 | /// <summary>
|
---|
| 123 | /// Readingorder
|
---|
| 124 | /// </summary>
|
---|
| 125 | public ExcelReadingOrder ReadingOrder
|
---|
| 126 | {
|
---|
| 127 | get
|
---|
| 128 | {
|
---|
| 129 | return _styles.CellXfs[Index].ReadingOrder;
|
---|
| 130 | }
|
---|
| 131 | set
|
---|
| 132 | {
|
---|
| 133 | _ChangedEvent(this, new StyleChangeEventArgs(eStyleClass.Style, eStyleProperty.ReadingOrder, value, _positionID, _address));
|
---|
| 134 | }
|
---|
| 135 | }
|
---|
| 136 | /// <summary>
|
---|
| 137 | /// Shrink the text to fit
|
---|
| 138 | /// </summary>
|
---|
| 139 | public bool ShrinkToFit
|
---|
| 140 | {
|
---|
| 141 | get
|
---|
| 142 | {
|
---|
| 143 | return _styles.CellXfs[Index].ShrinkToFit;
|
---|
| 144 | }
|
---|
| 145 | set
|
---|
| 146 | {
|
---|
| 147 | _ChangedEvent(this, new StyleChangeEventArgs(eStyleClass.Style, eStyleProperty.ShrinkToFit, value, _positionID, _address));
|
---|
| 148 | }
|
---|
| 149 | }
|
---|
| 150 | /// <summary>
|
---|
| 151 | /// The margin between the border and the text
|
---|
| 152 | /// </summary>
|
---|
| 153 | public int Indent
|
---|
| 154 | {
|
---|
| 155 | get
|
---|
| 156 | {
|
---|
| 157 | return _styles.CellXfs[Index].Indent;
|
---|
| 158 | }
|
---|
| 159 | set
|
---|
| 160 | {
|
---|
| 161 | if (value <0 || value > 250)
|
---|
| 162 | {
|
---|
| 163 | throw(new ArgumentOutOfRangeException("Indent must be between 0 and 250"));
|
---|
| 164 | }
|
---|
| 165 | _ChangedEvent(this, new StyleChangeEventArgs(eStyleClass.Style, eStyleProperty.Indent, value, _positionID, _address));
|
---|
| 166 | }
|
---|
| 167 | }
|
---|
| 168 | /// <summary>
|
---|
| 169 | /// Text orientation in degrees. Values range from 0 to 180.
|
---|
| 170 | /// </summary>
|
---|
| 171 | public int TextRotation
|
---|
| 172 | {
|
---|
| 173 | get
|
---|
| 174 | {
|
---|
| 175 | return _styles.CellXfs[Index].TextRotation;
|
---|
| 176 | }
|
---|
| 177 | set
|
---|
| 178 | {
|
---|
| 179 | if (value < 0 || value > 180)
|
---|
| 180 | {
|
---|
| 181 | throw new ArgumentOutOfRangeException("TextRotation out of range.");
|
---|
| 182 | }
|
---|
| 183 | _ChangedEvent(this, new StyleChangeEventArgs(eStyleClass.Style, eStyleProperty.TextRotation, value, _positionID, _address));
|
---|
| 184 | }
|
---|
| 185 | }
|
---|
| 186 | /// <summary>
|
---|
| 187 | /// If true the cell is locked for editing when the sheet is protected
|
---|
| 188 | /// <seealso cref="ExcelWorksheet.Protection"/>
|
---|
| 189 | /// </summary>
|
---|
| 190 | public bool Locked
|
---|
| 191 | {
|
---|
| 192 | get
|
---|
| 193 | {
|
---|
| 194 | return _styles.CellXfs[Index].Locked;
|
---|
| 195 | }
|
---|
| 196 | set
|
---|
| 197 | {
|
---|
| 198 | _ChangedEvent(this, new StyleChangeEventArgs(eStyleClass.Style, eStyleProperty.Locked, value, _positionID, _address));
|
---|
| 199 | }
|
---|
| 200 | }
|
---|
| 201 | /// <summary>
|
---|
| 202 | /// If true the formula is hidden when the sheet is protected.
|
---|
| 203 | /// <seealso cref="ExcelWorksheet.Protection"/>
|
---|
| 204 | /// </summary>
|
---|
| 205 | public bool Hidden
|
---|
| 206 | {
|
---|
| 207 | get
|
---|
| 208 | {
|
---|
| 209 | return _styles.CellXfs[Index].Hidden;
|
---|
| 210 | }
|
---|
| 211 | set
|
---|
| 212 | {
|
---|
| 213 | _ChangedEvent(this, new StyleChangeEventArgs(eStyleClass.Style, eStyleProperty.Hidden, value, _positionID, _address));
|
---|
| 214 | }
|
---|
| 215 | }
|
---|
| 216 |
|
---|
| 217 |
|
---|
| 218 | const string xfIdPath = "@xfId";
|
---|
| 219 | /// <summary>
|
---|
| 220 | /// The index in the style collection
|
---|
| 221 | /// </summary>
|
---|
| 222 | public int XfId
|
---|
| 223 | {
|
---|
| 224 | get
|
---|
| 225 | {
|
---|
| 226 | return _styles.CellXfs[Index].XfId;
|
---|
| 227 | }
|
---|
| 228 | set
|
---|
| 229 | {
|
---|
| 230 | _ChangedEvent(this, new StyleChangeEventArgs(eStyleClass.Style, eStyleProperty.XfId, value, _positionID, _address));
|
---|
| 231 | }
|
---|
| 232 | }
|
---|
| 233 | internal int PositionID
|
---|
| 234 | {
|
---|
| 235 | get;
|
---|
| 236 | set;
|
---|
| 237 | }
|
---|
| 238 | internal ExcelStyles Styles
|
---|
| 239 | {
|
---|
| 240 | get;
|
---|
| 241 | set;
|
---|
| 242 | }
|
---|
| 243 | internal override string Id
|
---|
| 244 | {
|
---|
| 245 | get
|
---|
| 246 | {
|
---|
| 247 | return Numberformat.Id + "|" + Font.Id + "|" + Fill.Id + "|" + Border.Id + "|" + VerticalAlignment + "|" + HorizontalAlignment + "|" + WrapText.ToString() + "|" + ReadingOrder.ToString() + "|" + XfId.ToString();
|
---|
| 248 | }
|
---|
| 249 | }
|
---|
| 250 |
|
---|
| 251 | }
|
---|
| 252 | }
|
---|