Esempio n. 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);
        }
Esempio n. 2
0
        public static void Main(string[] args)
        {
            //ExStart:1
            // The path to the documents directory.
            string dataDir = Aspose.Cells.Examples.Utils.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

            // Create directory if it is not already present.
            bool IsExists = System.IO.Directory.Exists(dataDir);

            if (!IsExists)
            {
                System.IO.Directory.CreateDirectory(dataDir);
            }

            //Instantiate a Workbook.
            Workbook workbook = new Workbook();

            //Get cells collection in the first (default) worksheet.
            Cells cells = workbook.Worksheets[0].Cells;

            //Get the D3 cell.
            Aspose.Cells.Cell c = cells["D3"];

            //Get the style of the cell.
            Style s = c.GetStyle();

            //Set foreground color for the cell from the default theme Accent2 color.
            s.ForegroundThemeColor = new ThemeColor(ThemeColorType.Accent2, 0.5);

            //Set the pattern type.
            s.Pattern = BackgroundType.Solid;

            //Get the font for the style.
            Aspose.Cells.Font f = s.Font;

            //Set the theme color.
            f.ThemeColor = new ThemeColor(ThemeColorType.Accent4, 0.1);

            //Apply style.
            c.SetStyle(s);

            //Put a value.
            c.PutValue("Testing1");

            //Save the excel file.
            workbook.Save(dataDir + "output.out.xlsx");
            //ExEnd:1
        }