Пример #1
0
 /// <summary>
 /// Removes the defined style from the style sheet of the workbook
 /// </summary>
 /// <param name="style">Style to remove</param>
 /// <param name="onlyIfUnused">If true, the style will only be removed if not used in any cell</param>
 /// <exception cref="StyleException">Throws an StyleException if the style was not found in the style collection (could not be referenced)</exception>
 public void RemoveStyle(Style.Style style, bool onlyIfUnused)
 {
     if (style == null)
     {
         throw new StyleException("UndefinedStyleException", "The style to remove is not defined");
     }
     RemoveStyle(style.Name, onlyIfUnused);
 }
Пример #2
0
 /// <summary>
 /// Init method called in the constructors
 /// </summary>
 private void Init()
 {
     worksheets   = new List <Worksheet>();
     styleManager = new StyleManager();
     styleManager.AddStyle(new Style.Style("default", 0, true));
     Style.Style borderStyle = new Style.Style("default_border_style", 1, true);
     borderStyle.CurrentBorder = Style.Style.BasicStyles.DottedFill_0_125.CurrentBorder;
     borderStyle.CurrentFill   = Style.Style.BasicStyles.DottedFill_0_125.CurrentFill;
     styleManager.AddStyle(borderStyle);
     workbookMetadata = new Metadata();
     shortener        = new Shortener();
 }
Пример #3
0
 /// <summary>
 /// Sets the lock state of the cell
 /// </summary>
 /// <param name="isLocked">If true, the cell will be locked if the worksheet is protected</param>
 /// <param name="isHidden">If true, the value of the cell will be invisible if the worksheet is protected</param>
 /// <exception cref="StyleException">Throws an UndefinedStyleException if the style used to lock cells cannot be referenced</exception>
 /// <remarks>The listed exception should never happen because the mentioned style is internally generated</remarks>
 public void SetCellLockedState(bool isLocked, bool isHidden)
 {
     Style.Style lockStyle;
     if (cellStyle == null)
     {
         lockStyle = new Style.Style();
     }
     else
     {
         lockStyle = cellStyle.CopyStyle();
     }
     lockStyle.CurrentCellXf.Locked = isLocked;
     lockStyle.CurrentCellXf.Hidden = isHidden;
     SetStyle(lockStyle);
 }
Пример #4
0
 /// <summary>
 /// Removes the assigned style from the cell
 /// </summary>
 /// <exception cref="StyleException">Throws an StyleException if the style cannot be referenced</exception>
 public void RemoveStyle()
 {
     if (WorksheetReference == null)
     {
         throw new StyleException("UndefinedStyleException", "No worksheet reference was defined while trying to remove a style from a cell");
     }
     if (WorksheetReference.WorkbookReference == null)
     {
         throw new StyleException("UndefinedStyleException", "No workbook reference was defined on the worksheet while trying to remove a style from a cell");
     }
     if (cellStyle != null)
     {
         string styleName = cellStyle.Name;
         cellStyle = null;
         WorksheetReference.WorkbookReference.RemoveStyle(styleName, true);
     }
 }
Пример #5
0
 /// <summary>
 /// Sets the style of the cell
 /// </summary>
 /// <param name="style">Style to assign</param>
 /// <returns>If the passed style already exists in the workbook, the existing one will be returned, otherwise the passed one</returns>
 /// <exception cref="StyleException">Throws an StyleException if the style cannot be referenced or no style was defined</exception>
 public Style.Style SetStyle(Style.Style style)
 {
     if (WorksheetReference == null)
     {
         throw new StyleException("UndefinedStyleException", "No worksheet reference was defined while trying to set a style to a cell");
     }
     if (WorksheetReference.WorkbookReference == null)
     {
         throw new StyleException("UndefinedStyleException", "No workbook reference was defined on the worksheet while trying to set a style to a cell");
     }
     if (style == null)
     {
         throw new StyleException("UndefinedStyleException", "No style to assign was defined");
     }
     Style.Style s = WorksheetReference.WorkbookReference.AddStyle(style);
     cellStyle = s;
     return(s);
 }
Пример #6
0
        /// <summary>
        /// Method to resolve all merged cells in all worksheets. Only the value of the very first cell of the locked cells range will be visible. The other values are still present (set to EMPTY) but will not be stored in the worksheet.
        /// </summary>
        /// <exception cref="StyleException">Throws an StyleException if one of the styles of the merged cells cannot be referenced or is null</exception>
        public void ResolveMergedCells()
        {
            Style.Style         mergeStyle = Style.Style.BasicStyles.MergeCellStyle;
            int                 pos;
            List <Cell.Address> addresses;
            Cell                cell;

            foreach (Worksheet sheet in worksheets)
            {
                foreach (KeyValuePair <string, Cell.Range> range in sheet.MergedCells)
                {
                    pos       = 0;
                    addresses = Cell.GetCellRange(range.Value.StartAddress, range.Value.EndAddress);
                    foreach (Cell.Address address in addresses)
                    {
                        if (sheet.Cells.ContainsKey(address.ToString()) == false)
                        {
                            cell                    = new Cell();
                            cell.DataType           = Cell.CellType.EMPTY;
                            cell.RowNumber          = address.Row;
                            cell.ColumnNumber       = address.Column;
                            cell.WorksheetReference = sheet;
                            sheet.AddCell(cell, cell.ColumnNumber, cell.RowNumber);
                        }
                        else
                        {
                            cell = sheet.Cells[address.ToString()];
                        }
                        if (pos != 0)
                        {
                            cell.DataType = Cell.CellType.EMPTY;
                        }
                        cell.SetStyle(mergeStyle);
                        pos++;
                    }
                }
            }
        }
Пример #7
0
 /// <summary>
 /// Adds a style component to a style
 /// </summary>
 /// <param name="baseStyle">Style to append a component</param>
 /// <param name="newComponent">Component to add to the baseStyle</param>
 /// <returns>Returns the managed style of the style manager</returns>
 public Style.Style AddStyleComponent(Style.Style baseStyle, AbstractStyle newComponent)
 {
     if (newComponent.GetType() == typeof(Style.Style.Border))
     {
         baseStyle.CurrentBorder = (Style.Style.Border)newComponent;
     }
     else if (newComponent.GetType() == typeof(Style.Style.CellXf))
     {
         baseStyle.CurrentCellXf = (Style.Style.CellXf)newComponent;
     }
     else if (newComponent.GetType() == typeof(Style.Style.Fill))
     {
         baseStyle.CurrentFill = (Style.Style.Fill)newComponent;
     }
     else if (newComponent.GetType() == typeof(Style.Style.Font))
     {
         baseStyle.CurrentFont = (Style.Style.Font)newComponent;
     }
     else if (newComponent.GetType() == typeof(Style.Style.NumberFormat))
     {
         baseStyle.CurrentNumberFormat = (Style.Style.NumberFormat)newComponent;
     }
     return(styleManager.AddStyle(baseStyle));
 }
Пример #8
0
 /// <summary>
 /// Sets a formula with style into the current cell and moves the cursor to the next cell (column or row depending on the defined cell direction)
 /// </summary>
 /// <exception cref="WorksheetException">Throws a WorksheetException if no worksheet was defined</exception>
 /// <param name="formula">Formula to set</param>
 /// <param name="style">Style to apply</param>
 public void Formula(string formula, Style.Style style)
 {
     NullCheck();
     currentWorksheet.AddNextCellFormula(formula, style);
 }
Пример #9
0
 /// <summary>
 /// Sets a value with style into the current cell and moves the cursor to the next cell (column or row depending on the defined cell direction)
 /// </summary>
 /// <exception cref="WorksheetException">Throws a WorksheetException if no worksheet was defined</exception>
 /// <param name="value">Value to set</param>
 /// <param name="style">Style to apply</param>
 public void Value(object value, Style.Style style)
 {
     NullCheck();
     currentWorksheet.AddNextCell(value, style);
 }
Пример #10
0
 /// <summary>
 /// Removes the passed style from the style sheet
 /// </summary>
 /// <param name="style">Style to remove</param>
 /// <exception cref="StyleException">Throws an StyleException if the style was not found in the style collection (could not be referenced)</exception>
 public void RemoveStyle(Style.Style style)
 {
     RemoveStyle(style, false);
 }
Пример #11
0
        /// <summary>
        /// Adds a style to the style manager
        /// </summary>
        /// <param name="style">Style to add</param>
        /// <returns>Returns the managed style of the style manager</returns>

        public Style.Style AddStyle(Style.Style style)
        {
            return(styleManager.AddStyle(style));
        }