예제 #1
0
        private XF GetDataCellXF(int sheetIndex, Type dataType, int excelRowIndex, int excelColumnIndex, HorizontalAlignments?h, VerticalAlignments?v, bool?hasBorder)
        {
            HorizontalAlignments h1 = h.GetValueOrDefault(SetDefaultHorizontalAlignmentsForType(dataType));
            VerticalAlignments   v1 = v.GetValueOrDefault(VerticalAlignments.Centered);
            bool   hasBorder1       = hasBorder.GetValueOrDefault(true);
            string key = "Cell" + h1.ToString() + v1.ToString() + (hasBorder1 ? "Y" : "N") + sheetIndex;

            if (!this.m_xlsXFs.ContainsKey(key))
            {
                XF xf = this.m_xlsDocument.NewXF();
                xf.HorizontalAlignment = h1;
                xf.VerticalAlignment   = v1;
                xf.Font.Height         = (ushort)(10 * this.FONT_HEIGHT_SCALE);
                if (hasBorder1)
                {
                    xf.LeftLineStyle   = 1;
                    xf.LeftLineColor   = Colors.Black;
                    xf.TopLineStyle    = 1;
                    xf.TopLineColor    = Colors.Black;
                    xf.RightLineStyle  = 1;
                    xf.RightLineColor  = Colors.Black;
                    xf.BottomLineStyle = 1;
                    xf.BottomLineColor = Colors.Black;
                    xf.TextWrapRight   = true;
                }
                SetXFForDataCell(sheetIndex, excelRowIndex, excelColumnIndex, xf);
                this.m_xlsXFs.Add(key, xf);
                return(xf);
            }
            return(this.m_xlsXFs[key]);
        }
예제 #2
0
        internal XF GetDataCellXF(XlsDocument xls, Type dataType)
        {
            if (m_XF == null)
            {
                VerticalAlignments v1 = ConvertAlignments(VerticalAlignment).GetValueOrDefault(VerticalAlignments.Centered);
                bool hasBorder1       = HasBorder.GetValueOrDefault(true);

                XF xf = xls.NewXF();
                xf.VerticalAlignment = v1;
                xf.Font.Height       = (ushort)(10 * this.FONT_HEIGHT_SCALE);
                if (hasBorder1)
                {
                    xf.LeftLineStyle   = 1;
                    xf.LeftLineColor   = Colors.Black;
                    xf.TopLineStyle    = 1;
                    xf.TopLineColor    = Colors.Black;
                    xf.RightLineStyle  = 1;
                    xf.RightLineColor  = Colors.Black;
                    xf.BottomLineStyle = 1;
                    xf.BottomLineColor = Colors.Black;
                    xf.TextWrapRight   = true;
                }
                m_XF = xf;
            }
            HorizontalAlignments h1 = ConvertAlignments(HorizontalAlignment).GetValueOrDefault(SetDefaultHorizontalAlignmentsForType(dataType));

            m_XF.HorizontalAlignment = h1;
            return(m_XF);
        }
예제 #3
0
        public TextCellVM()
        {
            //Background
            Type typeBackground = typeof(System.Drawing.Color);

            PropertyInfo[] colorInfo = typeBackground.GetProperties(BindingFlags.Public |
                                                                    BindingFlags.Static);
            foreach (PropertyInfo info in colorInfo)
            {
                Colors.Add(info.Name);
            }
            //HorizontalAlignment
            foreach (var item in Enum.GetValues(typeof(HorizontalAlignment)))
            {
                HorizontalAlignments.Add((HorizontalAlignment)item);
            }
            //VerticalAlignment
            foreach (var item in Enum.GetValues(typeof(VerticalAlignment)))
            {
                VerticalAlignments.Add((VerticalAlignment)item);
            }
            //FontFamily
            foreach (var fontFamily in Fonts.SystemFontFamilies)
            {
                FontFamils.Add(fontFamily);
            }
            FontFamily = new FontFamily("Times New Roman");
            FontSize   = 12;
        }
 private void SelectMode(StretchModeItem mode)
 {
     _suspend = true;
     stretchModes.SelectedIndex    = StretchModes.Select(m => m.Tag).IndexOf(mode.Stretch);
     horizontalModes.SelectedIndex = HorizontalAlignments.Select(m => m.Tag).IndexOf(mode.HorizontalAlignment);
     verticalModes.SelectedIndex   = VerticalAlignments.Select(m => m.Tag).IndexOf(mode.VerticalAlignment);
     _suspend = false;
     OnSelectionChanged(null, null);
 }
예제 #5
0
        /// <summary>
        /// Creates the new cell in the specified worksheet.
        /// </summary>
        /// <param name="sheet">The worksheet in which to create the cell.</param>
        /// <param name="row">Row number.</param>
        /// <param name="col">Column number.</param>
        /// <param name="fontWeight">The font weight.</param>
        /// <param name="border">The border.</param>
        /// <param name="backgroundColor">Color of the background.</param>
        /// <param name="horizontalAlignment">Cell's content horizontal alignment.</param>
        /// <param name="italic">if set to <c>true</c> font will be italic.</param>
        /// <param name="underlineType">Type of the underline style.</param>
        /// <param name="struckOut">if set to <c>true</c> font will be struck out.</param>
        /// <param name="color">The color of font.</param>
        /// <param name="fontName">Name of the font.</param>
        /// <param name="fontSize">Size of the font.</param>
        /// <returns>Created cell.</returns>
        private static Cell CreateNewCell(Worksheet sheet, int row, int col, FontWeight?fontWeight, ushort border, Color backgroundColor,
                                          HorizontalAlignments horizontalAlignment, bool italic, UnderlineTypes?underlineType, bool struckOut, FontColor color,
                                          string fontName, ushort?fontSize)
        {
            if (sheet == null)
            {
                throw new ArgumentNullException("sheet", "sheet cannot be null");
            }

            Cell cell = sheet.Cells.Add(row, col, String.Empty);

            if (border > 0)
            {
                cell.RightLineStyle  = border;
                cell.LeftLineStyle   = border;
                cell.TopLineStyle    = border;
                cell.BottomLineStyle = border;
                cell.UseBorder       = true;
            }

            if (backgroundColor != null)
            {
                cell.PatternColor = backgroundColor;
                cell.Pattern      = 1;
            }

            if (fontWeight != null)
            {
                cell.Font.Weight = fontWeight.Value;
            }

            cell.Font.Italic = italic;

            if (underlineType != null)
            {
                cell.Font.Underline = underlineType.Value;
            }

            cell.Font.StruckOut = struckOut;

            if (fontName != null)
            {
                cell.Font.FontName = fontName;
            }

            if (fontSize != null)
            {
                cell.Font.Height = (ushort)(fontSize.Value * 20);
            }

            cell.HorizontalAlignment = horizontalAlignment;

            cell.Font.ColorIndex = (ushort)color;

            return(cell);
        }
예제 #6
0
 public AnchorPosition(HorizontalAlignments _horizontalAlignment, VerticalAlignments _verticalAlignment, bool _positionXAsPercent, bool _positionYAsPercent, bool _centerX, bool _centerY, Vector2 _screenPosition)
 {
     horizontalAlignment = _horizontalAlignment;
     verticalAlignment   = _verticalAlignment;
     positionXAsPercent  = _positionXAsPercent;
     positionYAsPercent  = _positionYAsPercent;
     centerX             = _centerX;
     centerY             = _centerY;
     screenPosition      = _screenPosition;
 }
예제 #7
0
        private XF GetCellStyle(bool isBold, HorizontalAlignments align)
        {
            XF xf = xls.NewXF();

            xf.HorizontalAlignment = align;
            xf.VerticalAlignment   = VerticalAlignments.Centered;
            xf.Format        = StandardFormats.General;
            xf.Font.Bold     = isBold;
            xf.TextWrapRight = true;
            return(xf);
        }
        private IEnumerable <StretchModeItem> GetAllModes()
        {
            var index = 0;

            foreach (var stretch in StretchModes.Select(m => m.Tag).OfType <Stretch>())
            {
                foreach (var horizontalAlignment in HorizontalAlignments.Select(m => m.Tag).OfType <HorizontalAlignment>())
                {
                    foreach (var verticalAlignment in VerticalAlignments.Select(m => m.Tag).OfType <VerticalAlignment>())
                    {
                        yield return(new StretchModeItem(index++, stretch, horizontalAlignment, verticalAlignment));
                    }
                }
            }
        }
예제 #9
0
        /// <summary>
        /// 设置单元格的样式
        /// </summary>
        /// <param name="data"></param>
        private void SetCellStyleByCellData(string data)
        {
            if (data.Contains("(?!bold)"))
            {
                this.cellStyle.Font.Bold = true;
            }
            else
            {
                this.cellStyle.Font.Bold = false;
            }
            this.cellStyle.HorizontalAlignment = HorizontalAlignments.Centered;
            Match match = Regex.Match(data, @"\(\?!(?<align>left|right|center)\)", RegexOptions.IgnoreCase);

            if (match.Success)
            {
                string align = match.Groups["align"].Value.ToString().ToLower();
                HorizontalAlignments hAlign = (align == "left" ? HorizontalAlignments.Left : (align == "right" ? HorizontalAlignments.Right : HorizontalAlignments.Centered));
                cellStyle.HorizontalAlignment = hAlign;
            }
        }
예제 #10
0
        private XF GetDataHeaderXF(int sheetIndex, int excelColumnIndex, HorizontalAlignments?h, VerticalAlignments?v, bool?hasBorder)
        {
            HorizontalAlignments h1 = h.GetValueOrDefault(HorizontalAlignments.Centered);
            VerticalAlignments   v1 = v.GetValueOrDefault(VerticalAlignments.Centered);
            bool   hasBorder1       = hasBorder.GetValueOrDefault(true);
            string key = "Header" + h1.ToString() + v1.ToString() + (hasBorder1 ? "Y" : "N") + sheetIndex;

            if (!this.m_xlsXFs.ContainsKey(key))
            {
                XF xf = this.m_xlsDocument.NewXF();
                xf.HorizontalAlignment = h1;
                xf.VerticalAlignment   = v1;
                xf.Font.Height         = (ushort)(10 * this.FONT_HEIGHT_SCALE);
                xf.Font.Weight         = FontWeight.Bold;
                if (hasBorder1)
                {
                    xf.Pattern         = 1;
                    xf.PatternColor    = Colors.White;
                    xf.LeftLineStyle   = 1;
                    xf.LeftLineColor   = Colors.Black;
                    xf.TopLineStyle    = 1;
                    xf.TopLineColor    = Colors.Black;
                    xf.RightLineStyle  = 1;
                    xf.RightLineColor  = Colors.Black;
                    xf.BottomLineStyle = 1;
                    xf.BottomLineColor = Colors.Black;
                }
                else
                {
                    xf.Pattern      = 2;
                    xf.PatternColor = Colors.White;
                }

                SetXFForHeader(sheetIndex, excelColumnIndex, xf);
                this.m_xlsXFs.Add(key, xf);
                return(xf);
            }
            return(this.m_xlsXFs[key]);
        }
예제 #11
0
		public AnchorPosition (HorizontalAlignments _horizontalAlignment, VerticalAlignments _verticalAlignment, bool _positionXAsPercent, bool _positionYAsPercent, bool _centerX, bool _centerY, Vector2 _screenPosition) {
			horizontalAlignment = _horizontalAlignment;
			verticalAlignment = _verticalAlignment;
			positionXAsPercent = _positionXAsPercent;
			positionYAsPercent = _positionYAsPercent;
			centerX = _centerX;
			centerY = _centerY;
			screenPosition = _screenPosition;
		}
예제 #12
0
 /// <summary>
 /// Set the horizontal (X) Alignment for this text
 /// </summary>
 /// <param name="alignment">Alignment type</param>
 public void SetAlignment(HorizontalAlignments alignment)
 {
     this.Alignment = alignment;
     ProcessText();
 }
예제 #13
0
        /// <summary>
        /// Creates the new cell in the specified worksheet.
        /// </summary>
        /// <param name="sheet">The worksheet in which to create the cell.</param>
        /// <param name="row">Row number.</param>
        /// <param name="col">Column number.</param>
        /// <param name="configurationElement">Element that contains configuration for the cell.</param>
        /// <returns>Created cell.</returns>
        private static Cell CreateNewCell(Worksheet sheet, int row, int col, XElement configurationElement)
        {
            if (sheet == null)
            {
                throw new ArgumentNullException("sheet", "sheet cannot be null");
            }

            if (configurationElement == null)
            {
                throw new ArgumentNullException("configurationElement", "configurationElement cannot be null");
            }

            Color backgroundColor = null;

            if (configurationElement.Attribute("backgroundColor") != null)
            {
                backgroundColor = Utils.ParseColor(configurationElement.Attribute("backgroundColor").Value);
            }

            FontWeight?fontWeight = null;

            if (configurationElement.Attribute("fontWeight") != null)
            {
                fontWeight = (FontWeight)Enum.Parse(typeof(FontWeight), configurationElement.Attribute("fontWeight").Value, true);
            }

            ushort border = 0;

            if (configurationElement.Attribute("border") != null)
            {
                border = Convert.ToUInt16(configurationElement.Attribute("border").Value, CultureInfo.InvariantCulture);
            }

            HorizontalAlignments horizontalAlignment = HorizontalAlignments.Default;

            if (configurationElement.Attribute("horizontalAlignment") != null)
            {
                horizontalAlignment = (HorizontalAlignments)Enum.Parse(typeof(HorizontalAlignments), configurationElement.Attribute("horizontalAlignment").Value, true);
            }

            bool           italic        = false;
            UnderlineTypes?underlineType = null;
            bool           struckOut     = false;

            if (configurationElement.Attribute("italic") != null && configurationElement.Attribute("italic").Value == "true")
            {
                italic = true;
            }

            if (configurationElement.Attribute("underline") != null)
            {
                underlineType = (UnderlineTypes)Enum.Parse(typeof(UnderlineTypes), configurationElement.Attribute("underline").Value, true);
            }

            if (configurationElement.Attribute("struckOut") != null && configurationElement.Attribute("struckOut").Value == "true")
            {
                struckOut = true;
            }

            FontColor color = FontColor.Black;

            if (configurationElement.Attribute("color") != null)
            {
                color = (FontColor)Enum.Parse(typeof(FontColor), configurationElement.Attribute("color").Value, true);
            }

            string fontName = null;

            if (configurationElement.Attribute("fontName") != null)
            {
                fontName = configurationElement.Attribute("fontName").Value;
            }

            ushort?fontSize = null;

            if (configurationElement.Attribute("fontSize") != null)
            {
                fontSize = Convert.ToUInt16(configurationElement.Attribute("fontSize").Value, CultureInfo.InvariantCulture);
            }

            return(MakoPrintXls.CreateNewCell(sheet, row, col, fontWeight, border, backgroundColor, horizontalAlignment, italic, underlineType, struckOut, color, fontName, fontSize));
        }
예제 #14
0
파일: XF.cs 프로젝트: shi5588/shi5588
        private void SetDefaults()
        {
            _font = new Font(_doc, this);
            _format = Formats.Default;
            _style = new Style(_doc, this);

            _horizontalAlignment = HorizontalAlignments.Default;
            _textWrapRight = false;
            _verticalAlignment = VerticalAlignments.Default;
            _rotation = 0;
            _indentLevel = 0;
            _shrinkToCell = false;
            _textDirection = TextDirections.Default;
            _cellLocked = false; //NOTE: Unsure about this default (compare to Commented XF String in BinData)
            _formulaHidden = false; //NOTE: Unsure about this default (compare to Commented XF String in BinData)
            _isStyleXF = false; //NOTE: Unsure about this default (compare to Commented XF String in BinData)
            _useNumber = true;
            _useFont = true;
            _useMisc = true;
            _useBorder = true;
            _useBackground = true;
            _useProtection = true; //You should ALWAYS use protection ;-)
            _leftLineStyle = 0;
            _rightLineStyle = 0;
            _topLineStyle = 0;
            _bottomLineStyle = 0;
            _leftLineColor = Colors.DefaultLineColor;
            _rightLineColor = Colors.DefaultLineColor;
            _diagonalDescending = false;
            _diagonalAscending = false;
            _topLineColor = Colors.DefaultLineColor;
            _bottomLineColor = Colors.DefaultLineColor;
            _diagonalLineColor = Colors.DefaultLineColor;
            _diagonalLineStyle = LineStyle.None;
            _pattern = 0;
            _patternColor = Colors.DefaultPatternColor;
            _patternBackgroundColor = Colors.DefaultPatternBackgroundColor;

            OnChange();
        }