Пример #1
0
        /// <summary>
        /// This is a base style for CNE reports, other styles extends this by assigning any amount of following params with different values.
        /// </summary>
        /// <param name="style">This is a must provide value, others are optional.</param>
        private static Style GetStyle(Style style, TextAlignmentType horizontalAlignment = TextAlignmentType.Right, TextAlignmentType verticalAlignment = TextAlignmentType.Center,
                                      string fontName = "Calibri", int fontSize = 11, int styleNumber = 0, bool setBorders = true)
        {
            style.HorizontalAlignment = horizontalAlignment;
            style.VerticalAlignment   = verticalAlignment;

            Aspose.Cells.Font font = style.Font;

            //Set the name.
            font.Name = fontName;

            //Set the font size.
            font.Size = fontSize;

            style.Number = styleNumber;

            if (setBorders)
            {
                style.Borders[BorderType.BottomBorder].LineStyle = CellBorderType.Thin;
                style.Borders[BorderType.TopBorder].LineStyle    = CellBorderType.Thin;
                style.Borders[BorderType.LeftBorder].LineStyle   = CellBorderType.Thin;
                style.Borders[BorderType.RightBorder].LineStyle  = CellBorderType.Thin;
            }

            return(style);
        }
Пример #2
0
            public static void HorizontalAlignment(Cell cell, TextAlignmentType horizonltal_alignment)
            {
                Style style = cell.GetStyle();

                style.HorizontalAlignment = horizonltal_alignment;
                cell.SetStyle(style);
            }
Пример #3
0
        public static Cell SetVerticalAlignment(this Cell cell, TextAlignmentType value)
        {
            var style = cell.GetStyle();

            style.VerticalAlignment = value;
            cell.SetStyle(style);
            return(cell);
        }
Пример #4
0
        public static Column SetVerticalAlignment(this Column column, TextAlignmentType value)
        {
            var style = column.Style;

            style.VerticalAlignment = value;
            column.ApplyStyle(style, new StyleFlag {
                VerticalAlignment = true
            });
            return(column);
        }
Пример #5
0
        public static Cells SetVerticalAlignment(this Cells cells, TextAlignmentType value)
        {
            var style = new Style();

            style.VerticalAlignment = value;
            cells.ApplyStyle(style, new StyleFlag {
                VerticalAlignment = true
            });
            return(cells);
        }
Пример #6
0
        public static Row SetVerticalAlignment(this Row row, TextAlignmentType value)
        {
            var style = row.Style;

            style.VerticalAlignment = value;
            row.ApplyStyle(style, new StyleFlag {
                VerticalAlignment = true
            });
            return(row);
        }
Пример #7
0
        public static Range SetVerticalAlignment(this Range range, TextAlignmentType value)
        {
            var style = new Style();

            style.VerticalAlignment = value;
            range.ApplyStyle(style, new StyleFlag {
                VerticalAlignment = true
            });
            return(range);
        }
Пример #8
0
        /// <summary>
        ///   Align column data to [Right] or [Left].
        /// </summary>
        /// <param name="worksheet"> worksheet number to use.</param>
        /// <param name="columnNumber">column number to apply alignment.</param>
        /// <param name="textAlignmentType">type of alignment [Left] [Right].</param>
        private void AlignWorkSheetColumnData(Worksheet worksheet, int columnNumber, TextAlignmentType textAlignmentType)
        {
            Cells cells = worksheet.Cells;

            // Get current style & adjust alignment
            Style style = cells.Columns[columnNumber].Style;

            style.HorizontalAlignment = textAlignmentType;
            cells.Columns[columnNumber].ApplyStyle(style, new StyleFlag {
                HorizontalAlignment = true
            });
        }
Пример #9
0
        /// <summary>
        /// 创建标题样式
        /// </summary>
        /// <param name="workbook"></param>
        /// <param name="AlignmentType"></param>
        /// <returns></returns>
        private Style CreateStyle(Workbook workbook, TextAlignmentType AlignmentType = TextAlignmentType.Center)
        {
            Aspose.Cells.Style style = workbook.Styles[workbook.Styles.Add()];
            Color c = Color.Gray;

            style.ForegroundColor     = c;
            style.Pattern             = BackgroundType.Solid;
            style.Font.Color          = Color.White;
            style.Font.IsBold         = true;
            style.HorizontalAlignment = AlignmentType;
            SetBorder(style);
            return(style);
        }
Пример #10
0
        internal static TextAlignment GetTextAlignment(OnPlatformTextAlignment platformTextAlignment)
        {
            TextAlignment retVal = TextAlignment.Start;

            TextAlignmentType textAlignmentType = TextAlignmentType.NotSet;

            Device.OnPlatform(
                Android: () =>
            {
                textAlignmentType = OnPlatformTextAlignment.GetAndroidValue(platformTextAlignment);
            },
                iOS: () =>
            {
                textAlignmentType = OnPlatformTextAlignment.GetiOSValue(platformTextAlignment);
            },
                WinPhone: () =>
            {
                textAlignmentType = OnPlatformTextAlignment.GetWinPhoneValue(platformTextAlignment);
            }
                );


            switch (textAlignmentType)
            {
            case TextAlignmentType.Start:
                retVal = TextAlignment.Start;
                break;

            case TextAlignmentType.Center:
                retVal = TextAlignment.Center;
                break;

            case TextAlignmentType.End:
                retVal = TextAlignment.End;
                break;
            }

            return(retVal);
        }
Пример #11
0
 public static IList <Column> SetVerticalAlignment(this IList <Column> columns, TextAlignmentType value, params int[] columnIndexes)
 {
     foreach (var i in columnIndexes)
     {
         columns[i].SetVerticalAlignment(value);
     }
     return(columns);
 }
Пример #12
0
        /// <summary>
        /// Sets a cell style
        /// </summary>
        /// <param name="style">The cell style</param>
        /// <param name="fontName">The font name</param>
        /// <param name="fontSize">The font size</param>
        /// <param name="fontColor">The font colour</param>
        /// <param name="isBold">Whether to bold text</param>
        /// <param name="verticalAlignment">The vertical alignment</param>
        /// <param name="horizontalAlignment">The horizontal alignment</param>
        /// <param name="foregroundColor">The foreground colour</param>
        /// <param name="borderColor">The border colour</param>
        /// <returns>The cell style with applied styles</returns>
        private Aspose.Cells.Style SetCellStyle(
            Aspose.Cells.Style style, 
            string fontName, 
            int fontSize, 
            Color fontColor, 
            bool isBold,
            TextAlignmentType verticalAlignment, 
            TextAlignmentType horizontalAlignment, 
            Color foregroundColor,
             Color borderColor)
        {
            style.Font.Name = fontName;
            style.Font.Size = fontSize;
            style.Font.Color = fontColor;
            style.Font.IsBold = isBold;
            style.VerticalAlignment = verticalAlignment;
            style.HorizontalAlignment = horizontalAlignment;
            style.ForegroundColor = foregroundColor;

            style.Pattern = BackgroundType.Solid;

            // set border colours
            style.Borders[BorderType.RightBorder].LineStyle = CellBorderType.Thin;
            style.Borders[BorderType.RightBorder].Color = borderColor;

            style.Borders[BorderType.LeftBorder].LineStyle = CellBorderType.Thin;
            style.Borders[BorderType.LeftBorder].Color = borderColor;

            if (foregroundColor != Color.White)
            {
                style.Borders[BorderType.TopBorder].LineStyle = CellBorderType.Thin;
                style.Borders[BorderType.TopBorder].Color = borderColor;

                style.Borders[BorderType.BottomBorder].LineStyle = CellBorderType.Thin;
                style.Borders[BorderType.BottomBorder].Color = borderColor;
            }

            return style;
        }
        /// <summary>
        /// Conver Excel HorizontalAlignment to Word ParagraphAlignment
        /// </summary>
        /// <param name="alignmentType">Excel AlignmentType</param>
        /// <returns>Word ParagraphAlignment</returns>
        private ParagraphAlignment ConvertHorizontalAlignment(TextAlignmentType alignmentType)
        {
            ParagraphAlignment wordsAlignment = ParagraphAlignment.Left;

            switch (alignmentType)
            {
                case TextAlignmentType.Center:
                    {
                        wordsAlignment = ParagraphAlignment.Center;
                        break;
                    }
                case TextAlignmentType.Distributed:
                    {
                        wordsAlignment = ParagraphAlignment.Distributed;
                        break;
                    }
                case TextAlignmentType.Justify:
                    {
                        wordsAlignment = ParagraphAlignment.Justify;
                        break;
                    }
                case TextAlignmentType.Left:
                    {
                        wordsAlignment = ParagraphAlignment.Left;
                        break;
                    }
                case TextAlignmentType.Right:
                    {
                        wordsAlignment = ParagraphAlignment.Right;
                        break;
                    }
                default:
                    {
                        wordsAlignment = ParagraphAlignment.Left;
                        break;
                    }
            }

            return wordsAlignment;
        }
Пример #14
0
 public static void HorizontalAlignment(Cell cell, TextAlignmentType horizonltal_alignment)
 {
     Style style = cell.GetStyle();
     style.HorizontalAlignment = horizonltal_alignment;
     cell.SetStyle(style);
 }
Пример #15
0
        /// <summary>
        /// 設定 Worksheet 的 欄位寬度
        /// </summary>
        /// <param name="sheet">綁定 DataTable 的 Worksheet </param>
        /// <param name="columnInfos">item1:Column Name, item2:Column Width</param>
        private static void ChangedSheetColumnStyle(Worksheet sheet, Dictionary <string, Tuple <string, double, Style> > columnInfos, TextAlignmentType headerHorizontalAlignment)
        {
            //change columnName
            if (columnInfos != null)
            {
                var columnIndex = 0;
                foreach (KeyValuePair <string, Tuple <string, double, Style> > columnInfo in columnInfos)
                {
                    if (columnInfo.Value.Item2 > -1)
                    {
                        sheet.Cells.SetColumnWidth(columnIndex, columnInfo.Value.Item2);
                    }

                    if (columnInfo.Value.Item3 != null)
                    {
                        var styleFlag = new StyleFlag();
                        styleFlag.NumberFormat        = true;
                        styleFlag.HorizontalAlignment = true;
                        sheet.Cells.Columns[columnIndex].ApplyStyle(columnInfo.Value.Item3, styleFlag);
                    }

                    //設定 header 列
                    var cellStyle     = sheet.Cells[columnIndex, 0].GetStyle();
                    var cellStyleFlag = new StyleFlag();
                    cellStyleFlag.HorizontalAlignment = true;
                    cellStyle.HorizontalAlignment     = headerHorizontalAlignment;
                    sheet.Cells[0, columnIndex].SetStyle(cellStyle, cellStyleFlag);
                    columnIndex++;
                }
            }
        }
        /// <summary>
        /// Conver Excel VerticalAlignment to Word CellVerticalAlignment
        /// </summary>
        /// <param name="alignmentType">Excel AlignmentType</param>
        /// <returns>Word CellVerticalAlignment</returns>
        private CellVerticalAlignment ConvertVerticalAlignment(TextAlignmentType alignmentType)
        {
            CellVerticalAlignment wordsAlignment = CellVerticalAlignment.Top;

            switch (alignmentType)
            {
                case TextAlignmentType.Bottom:
                    {
                        wordsAlignment = CellVerticalAlignment.Bottom;
                        break;
                    }
                case TextAlignmentType.Center:
                    {
                        wordsAlignment = CellVerticalAlignment.Center;
                        break;
                    }
                case TextAlignmentType.Top:
                    {
                        wordsAlignment = CellVerticalAlignment.Top;
                        break;
                    }
                default:
                    {
                        wordsAlignment = CellVerticalAlignment.Top;
                        break;
                    }
            }

            return wordsAlignment;
        }
Пример #17
0
 public static Style SetHorizontalAlignment(this Style style, TextAlignmentType value)
 {
     style.HorizontalAlignment = value;
     return(style);
 }
Пример #18
0
 public static Style SetVerticalAlignment(this Style style, TextAlignmentType value)
 {
     style.VerticalAlignment = value;
     return(style);
 }