//create a new workbook var workbook = new GrapeCity.Documents.Excel.Workbook(); IWorksheet worksheet = workbook.Worksheets[0]; //Add custom name style. IStyle style = workbook.Styles.Add("testStyle"); //Config custom name style settings begin. //Border style.Borders[BordersIndex.EdgeLeft].LineStyle = BorderLineStyle.Thin; style.Borders[BordersIndex.EdgeTop].LineStyle = BorderLineStyle.Thick; style.Borders[BordersIndex.EdgeRight].LineStyle = BorderLineStyle.Double; style.Borders[BordersIndex.EdgeBottom].LineStyle = BorderLineStyle.Double; style.Borders.Color = Color.FromArgb(0, 255, 0); //Font style.Font.ThemeColor = ThemeColor.Accent1; style.Font.TintAndShade = 0.8; style.Font.Italic = true; style.Font.Bold = true; style.Font.Name = "LiSu"; style.Font.Size = 28; style.Font.Strikethrough = true; style.Font.Subscript = true; style.Font.Superscript = false; style.Font.Underline = UnderlineType.Double; //Protection style.FormulaHidden = true; style.Locked = false; //Number style.NumberFormat = "#,##0_);[Red](#,##0)"; //Alignment style.HorizontalAlignment = HorizontalAlignment.Right; style.VerticalAlignment = VerticalAlignment.Bottom; style.WrapText = true; style.IndentLevel = 5; style.Orientation = 45; //Fill style.Interior.ColorIndex = 5; style.Interior.Pattern = GrapeCity.Documents.Excel.Pattern.Down; style.Interior.PatternColor = Color.FromArgb(0, 0, 255); style.IncludeAlignment = false; style.IncludeBorder = true; style.IncludeFont = false; style.IncludeNumber = true; style.IncludePatterns = false; style.IncludeProtection = true; //Config custom name style settings end. //Set range's style to custom name style. worksheet.Range["A1"].Value = "My test style"; worksheet.Range["A1"].Style = worksheet.Workbook.Styles["testStyle"]; worksheet.Range["A2"].RowHeightInPixel = 60; worksheet.Range["A2"].ColumnWidthInPixel = 150;
' Create a new Workbook Dim workbook As New Workbook Dim worksheet As IWorksheet = workbook.Worksheets(0) 'Add custom name style. Dim style As IStyle = workbook.Styles.Add("testStyle") 'Config custom name style settings begin. 'Border style.Borders(BordersIndex.EdgeLeft).LineStyle = BorderLineStyle.Thin style.Borders(BordersIndex.EdgeTop).LineStyle = BorderLineStyle.Thick style.Borders(BordersIndex.EdgeRight).LineStyle = BorderLineStyle.Double style.Borders(BordersIndex.EdgeBottom).LineStyle = BorderLineStyle.Double style.Borders.Color = Color.FromArgb(0, 255, 0) 'Font style.Font.ThemeColor = ThemeColor.Accent1 style.Font.TintAndShade = 0.8 style.Font.Italic = True style.Font.Bold = True style.Font.Name = "LiSu" style.Font.Size = 28 style.Font.Strikethrough = True style.Font.Subscript = True style.Font.Superscript = False style.Font.Underline = UnderlineType.Double 'Protection style.FormulaHidden = True style.Locked = False 'Number style.NumberFormat = "#,##0_);[Red](#,##0)" 'Alignment style.HorizontalAlignment = HorizontalAlignment.Right style.VerticalAlignment = VerticalAlignment.Bottom style.WrapText = True style.IndentLevel = 5 style.Orientation = 45 'Fill style.Interior.ColorIndex = 5 style.Interior.Pattern = Pattern.Down style.Interior.PatternColor = Color.FromArgb(0, 0, 255) style.IncludeAlignment = False style.IncludeBorder = True style.IncludeFont = False style.IncludeNumber = True style.IncludePatterns = False style.IncludeProtection = True 'Config custom name style settings end. 'Set range's style to custom name style. worksheet.Range!A1.Value = "My test style" worksheet.Range!A1.Style = worksheet.Workbook.Styles("testStyle") worksheet.Range!A2.RowHeightInPixel = 60 worksheet.Range!A2.ColumnWidthInPixel = 150 ' save to an excel file workbook.Save("CreateCustomStyle.xlsx")