Created
December 19, 2019 06:51
-
-
Save b2977053/741ef53c0b6c5ef3de781146449f665c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Aspose.Cells; | |
using System; | |
using System.Drawing; | |
namespace test_Aspose_Cells | |
{ | |
internal class Aspose_Cell_Style | |
{ | |
internal void Background() | |
{ | |
CstWorkbook wb = new CstWorkbook(); | |
Worksheet sheet = wb.CreateWorksheet(); | |
string[] Background_Patterns = { "DiagonalCrosshatch", "DiagonalStripe", "Gray6", "Gray12", "Gray25", "Gray50", "Gray75", "HorizontalStripe", "None", "ReverseDiagonalStripe", "Solid", "ThickDiagonalCrosshatch", "ThinDiagonalCrosshatch", "ThinDiagonalStripe", "ThinHorizontalCrosshatch", "ThinHorizontalStripe", "ThinReverseDiagonalStripe", "ThinVerticalStripe", "VerticalStripe" }; | |
string[] Descriptions = { "Represents diagonal crosshatch pattern", | |
"Represents diagonal stripe pattern", | |
"Represents 6.25% gray pattern", | |
"Represents 12.5% gray pattern", | |
"Represents 25% gray pattern", | |
"Represents 50% gray pattern", | |
"Represents 75% gray pattern", | |
"Represents horizontal stripe pattern", | |
"Represents no background", | |
"Represents reverse diagonal stripe pattern", | |
"Represents solid pattern", | |
"Represents thick diagonal crosshatch pattern", | |
"Represents thin diagonal crosshatch pattern", | |
"Represents thin diagonal stripe pattern", | |
"Represents thin horizontal crosshatch pattern", | |
"Represents thin horizontal stripe pattern", | |
"Represents thin reverse diagonal stripe pattern", | |
"Represents thin vertical stripe pattern", | |
"Represents vertical stripe pattern" }; | |
BackgroundType[] BackgroundTypes = { BackgroundType.DiagonalCrosshatch, | |
BackgroundType.DiagonalStripe, | |
BackgroundType.Gray6, | |
BackgroundType.Gray12, | |
BackgroundType.Gray25, | |
BackgroundType.Gray50, | |
BackgroundType.Gray75, | |
BackgroundType.HorizontalStripe, | |
BackgroundType.None, | |
BackgroundType.ReverseDiagonalStripe, | |
BackgroundType.Solid, | |
BackgroundType.ThickDiagonalCrosshatch, | |
BackgroundType.ThinDiagonalCrosshatch, | |
BackgroundType.ThinDiagonalStripe, | |
BackgroundType.ThinHorizontalCrosshatch, | |
BackgroundType.ThinHorizontalStripe, | |
BackgroundType.ThinReverseDiagonalStripe, | |
BackgroundType.ThinVerticalStripe, | |
BackgroundType.VerticalStripe }; | |
for (int i = 0; i < 19; i++) | |
{ | |
setBackgrounds(sheet, Background_Patterns, Descriptions, BackgroundTypes, i); | |
} | |
sheet.AutoFitColumns(); // 寬度自動調整 | |
wb.NewFilleName = "Aspose_Cell_Style"; | |
wb.SaveFile_xlsx(); | |
} | |
private static void setBackgrounds(Worksheet sheet, string[] Background_Patterns, string[] Descriptions, BackgroundType[] BackgroundTypes, int i) | |
{ | |
Cell cell_1 = sheet.Cells["A" + (i + 1)]; | |
cell_1.Value = Background_Patterns[i]; | |
Cell cell_2 = sheet.Cells["B" + (i + 1)]; | |
cell_2.Value = Descriptions[i]; | |
Cell cell_3 = sheet.Cells["C" + (i + 1)]; | |
Style style = cell_3.GetStyle(); | |
style.BackgroundColor = Color.Yellow; | |
style.Pattern = BackgroundTypes[i]; | |
style.ForegroundColor = Color.Black; | |
cell_3.SetStyle(style); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment