public static void SheetHeadStyle(IWorkbook workBook) { Style SheetHeadStyle = workBook.Styles.Add("SheetHeadStyle"); //SheetHeadStyle.CopyFrom(BuiltInStyleId.Accent6); SheetHeadStyle.BeginUpdate(); try { SheetHeadStyle.Borders.TopBorder.Color = Color.FromArgb(166, 166, 166); SheetHeadStyle.Borders.BottomBorder.Color = Color.FromArgb(166, 166, 166); SheetHeadStyle.Borders.LeftBorder.Color = Color.White; SheetHeadStyle.Borders.RightBorder.Color = Color.White; SheetHeadStyle.Fill.BackgroundColor = Color.FromArgb(242, 242, 242); SheetHeadStyle.Alignment.Horizontal = SpreadsheetHorizontalAlignment.Center; SheetHeadStyle.Alignment.Vertical = SpreadsheetVerticalAlignment.Center; SheetHeadStyle.Font.Size = 11; SheetHeadStyle.Font.Color = Color.FromArgb(52, 150, 151); } finally { SheetHeadStyle.EndUpdate(); } }
static void CreateModifyStyle(IWorkbook workbook) { #region CreateNewStyle Style myStyle = workbook.Styles.Add("My Style"); myStyle.BeginUpdate(); try { myStyle.Font.Color = Color.Blue; myStyle.Font.Size = 12; myStyle.Alignment.Horizontal = DevExpress.Spreadsheet.SpreadsheetHorizontalAlignment.Center; myStyle.Fill.BackgroundColor = Color.LightBlue; myStyle.Fill.PatternType = PatternType.LightGray; myStyle.Fill.PatternColor = Color.Yellow; } finally { myStyle.EndUpdate(); } #endregion CreateNewStyle #region DuplicateExistingStyle Style myGoodStyle = workbook.Styles.Add("My Good Style"); myGoodStyle.CopyFrom(BuiltInStyleId.Good); #endregion DuplicateExistingStyle #region ModifyExistingStyle Style customStyle = workbook.Styles["Custom Style"]; customStyle.BeginUpdate(); try { customStyle.Fill.BackgroundColor = Color.Gold; } finally { customStyle.EndUpdate(); } #endregion ModifyExistingStyle }
static void CreateModifyStyle(Workbook workbook) { #region #CreateNewStyle // Add a new style under the "My Style" name to the workbook's style collection. Style myStyle = workbook.Styles.Add("My Style"); // Specify formatting characteristics for the style. myStyle.BeginUpdate(); try { // Specify the font color. myStyle.Font.Color = Color.Blue; // Specify the font size. myStyle.Font.Size = 12; // Specify the horizontal alignment. myStyle.Alignment.Horizontal = SpreadsheetHorizontalAlignment.Center; // Set the background. myStyle.Fill.BackgroundColor = Color.LightBlue; myStyle.Fill.PatternType = PatternType.LightGray; myStyle.Fill.PatternColor = Color.Yellow; } finally { myStyle.EndUpdate(); } #endregion #CreateNewStyle #region #DuplicateExistingStyle // Add a new style under the "My Good Style" name to the workbook's style collection. Style myGoodStyle = workbook.Styles.Add("My Good Style"); // Copy all format settings from the built-in Good style. myGoodStyle.CopyFrom(BuiltInStyleId.Good); // Modify the required formatting characteristics if needed. // ... #endregion #DuplicateExistingStyle #region #ModifyExistingStyle // Access the style to be modified. Style customStyle = workbook.Styles["Custom Style"]; // Change the required formatting characteristics of the style. customStyle.BeginUpdate(); try { customStyle.Fill.BackgroundColor = Color.Gold; // ... } finally { customStyle.EndUpdate(); } #endregion #ModifyExistingStyle }
public static void SheetNormalStyle(IWorkbook workBook) { Style SheetNormalStyle = workBook.Styles.Add("SheetNormalStyle"); SheetNormalStyle.CopyFrom(BuiltInStyleId.Normal); SheetNormalStyle.BeginUpdate(); try { SheetNormalStyle.Font.Size = 11; SheetNormalStyle.Alignment.Horizontal = SpreadsheetHorizontalAlignment.Center; SheetNormalStyle.Alignment.Vertical = SpreadsheetVerticalAlignment.Center; } finally { SheetNormalStyle.EndUpdate(); } }
public static void SheetTitleStyle(IWorkbook workBook) { Style SheetTitleStyle = workBook.Styles.Add("SheetTitleStyle"); //SheetTitleStyle.CopyFrom(BuiltInStyleId.Heading2); SheetTitleStyle.BeginUpdate(); try { SheetTitleStyle.Font.Name = "宋体"; SheetTitleStyle.Font.Size = 18; SheetTitleStyle.Font.Color = Color.FromArgb(52, 150, 151); SheetTitleStyle.Alignment.Horizontal = SpreadsheetHorizontalAlignment.Left; SheetTitleStyle.Alignment.Vertical = SpreadsheetVerticalAlignment.Center; } finally { SheetTitleStyle.EndUpdate(); } }
public static void SheetSumTotalStyle(IWorkbook workBook) { Style SheetSumTotalStyle = workBook.Styles.Add("SheetSumTotalStyle"); SheetSumTotalStyle.CopyFrom(BuiltInStyleId.Input); SheetSumTotalStyle.BeginUpdate(); try { SheetSumTotalStyle.Font.Size = 12; SheetSumTotalStyle.Font.Bold = true; SheetSumTotalStyle.Borders.SetAllBorders(Color.White, BorderLineStyle.None); SheetSumTotalStyle.Alignment.Horizontal = SpreadsheetHorizontalAlignment.Center; SheetSumTotalStyle.Alignment.Vertical = SpreadsheetVerticalAlignment.Center; } finally { SheetSumTotalStyle.EndUpdate(); } }
static void CreateModifyApplyStyle(IWorkbook workbook) { workbook.BeginUpdate(); try { Worksheet worksheet = workbook.Worksheets[0]; #region #CreateNewStyle // Add a new style under the "My Style" name to the Styles collection of the workbook. Style myStyle = workbook.Styles.Add("My Style"); // Specify formatting characteristics for the style. myStyle.BeginUpdate(); try { // Set the font color to Blue. myStyle.Font.Color = Color.Blue; // Set the font size to 12. myStyle.Font.Size = 12; // Set the horizontal alignment to Center. myStyle.Alignment.Horizontal = SpreadsheetHorizontalAlignment.Center; // Set the background. myStyle.Fill.BackgroundColor = Color.LightBlue; } finally { myStyle.EndUpdate(); } #endregion #CreateNewStyle #region #DuplicateExistingStyle // Add a new style under the "My Good Style" name to the Styles collection. Style myGoodStyle = workbook.Styles.Add("My Good Style"); // Copy all format settings from the built-in Good style. myGoodStyle.CopyFrom(BuiltInStyleId.Good); #endregion #DuplicateExistingStyle #region #ModifyExistingStyle // Change the required formatting characteristics of the style. myGoodStyle.BeginUpdate(); try { myGoodStyle.Fill.BackgroundColor = Color.LightYellow; // ... } finally { myGoodStyle.EndUpdate(); } #endregion #ModifyExistingStyle #region #ApplyStyles // Access the built-in "Good" MS Excel style from the Styles collection of the workbook. Style styleGood = workbook.Styles[BuiltInStyleId.Good]; // Apply the "Good" style to a range of cells. worksheet.Range["A1:C4"].Style = styleGood; // Access a custom style that has been previously created in the loaded document by its name. Style customStyle = workbook.Styles["Custom Style"]; // Apply the custom style to the cell. worksheet.Cells["D6"].Style = customStyle; // Apply the "Good" style to the eighth row. worksheet.Rows[7].Style = styleGood; // Apply the custom style to the "H" column. worksheet.Columns["H"].Style = customStyle; #endregion #ApplyStyles } finally { workbook.EndUpdate(); } }