本文整理汇总了C#中Workbook.CreateStyle方法的典型用法代码示例。如果您正苦于以下问题:C# Workbook.CreateStyle方法的具体用法?C# Workbook.CreateStyle怎么用?C# Workbook.CreateStyle使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Workbook
的用法示例。
在下文中一共展示了Workbook.CreateStyle方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Run
public static void Run()
{
// ExStart:ReusingStyleObjects
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
// Create workbook object
Workbook workbook = new Workbook();
// Access the first worksheet
Worksheet worksheet = workbook.Worksheets[0];
// Access cells
Cell cell1 = worksheet.Cells["A1"];
Cell cell2 = worksheet.Cells["B1"];
// Set the styles of both cells to Times New Roman
Style styleObject = workbook.CreateStyle();
styleObject.Font.Color = System.Drawing.Color.Red;
styleObject.Font.Name = "Times New Roman";
cell1.SetStyle(styleObject);
cell2.SetStyle(styleObject);
// Put the values inside the cell
cell1.PutValue("Hello World!");
cell2.PutValue("Hello World!!");
// Save to Pdf without setting PdfSaveOptions.IsFontSubstitutionCharGranularity
workbook.Save(dataDir + "SampleOutput_out.xlsx");
// ExEnd:ReusingStyleObjects
}
示例2: Run
public static void Run()
{
// ExStart:1
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
// Load a template file
Workbook workbook = new Workbook(dataDir + "Book1.xls");
// Get the first worksheet
Worksheet worksheet = workbook.Worksheets[0];
var pivot = workbook.Worksheets[0].PivotTables[0];
pivot.PivotTableStyleType = PivotTableStyleType.PivotTableStyleDark1;
Style style = workbook.CreateStyle();
style.Font.Name = "Arial Black";
style.ForegroundColor = Color.Yellow;
style.Pattern = BackgroundType.Solid;
pivot.FormatAll(style);
// Saving the Excel file
workbook.Save(dataDir + "output.xls");
// ExEnd:1
}
示例3: Run
public static void Run()
{
// ExStart:1
// The path to the documents directory.
string dataDir = RunExamples.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 new Workbook.
Workbook workbook = new Workbook();
// Create a style object .
Style style = workbook.CreateStyle();
// Input a value to A1 cell.
workbook.Worksheets[0].Cells["A1"].PutValue("Test");
// Apply the style to the cell.
workbook.Worksheets[0].Cells["A1"].SetStyle(style);
// Save the Excel 2007 file.
workbook.Save(dataDir + "book1.out.xlsx");
// ExEnd:1
}
示例4: Main
static void Main(string[] args)
{
Workbook myWorkbook = new Workbook(fileName);
Worksheet mySheet = myWorkbook.Worksheets[myWorkbook.Worksheets.ActiveSheetIndex];
Style style = myWorkbook.CreateStyle();
style.VerticalAlignment = TextAlignmentType.Center;
//Setting the horizontal alignment of the text in the "A1" cell
style.HorizontalAlignment = TextAlignmentType.Center;
//Setting the font color of the text in the "A1" cell
style.Font.Color = Color.Green;
//Shrinking the text to fit in the cell
style.ShrinkToFit = true;
//Setting the bottom border color of the cell to red
style.Borders[BorderType.BottomBorder].Color = Color.Red;
//Creating StyleFlag
StyleFlag styleFlag = new StyleFlag();
styleFlag.HorizontalAlignment = true;
styleFlag.VerticalAlignment = true;
styleFlag.ShrinkToFit = true;
styleFlag.Borders = true;
styleFlag.FontColor = true;
//Accessing a row from the Rows collection
Column column = mySheet.Cells.Columns[0];
//Assigning the Style object to the Style property of the row
column.ApplyStyle(style, styleFlag);
myWorkbook.Save(fileName);
}
示例5: Run
public static void Run()
{
// ExStart:1
// The path to the documents directory.
string dataDir = RunExamples.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);
// Instantiating a Workbook object
Workbook workbook = new Workbook();
// Obtaining the reference of the first (default) worksheet by passing its sheet index
Worksheet worksheet = workbook.Worksheets[0];
// Adding a new Style to the styles
Style style = workbook.CreateStyle();
// Setting the vertical alignment of the text in the "A1" cell
style.VerticalAlignment = TextAlignmentType.Center;
// Setting the horizontal alignment of the text in the "A1" cell
style.HorizontalAlignment = TextAlignmentType.Center;
// Setting the font color of the text in the "A1" cell
style.Font.Color = Color.Green;
// Shrinking the text to fit in the cell
style.ShrinkToFit = true;
// Setting the bottom border color of the cell to red
style.Borders[BorderType.BottomBorder].Color = Color.Red;
// Setting the bottom border type of the cell to medium
style.Borders[BorderType.BottomBorder].LineStyle = CellBorderType.Medium;
// Creating StyleFlag
StyleFlag styleFlag = new StyleFlag();
styleFlag.HorizontalAlignment = true;
styleFlag.VerticalAlignment = true;
styleFlag.ShrinkToFit = true;
styleFlag.Borders = true;
styleFlag.FontColor = true;
// Accessing a row from the Rows collection
Row row = worksheet.Cells.Rows[0];
// Assigning the Style object to the Style property of the row
row.ApplyStyle(style, styleFlag);
// Saving the Excel file
workbook.Save(dataDir + "book1.out.xls");
// ExEnd:1
}
示例6: Run
public static void Run()
{
// ExStart:1
// The path to the documents directory.
string dataDir = RunExamples.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 new Workbook.
Workbook workbook = new Workbook();
// Get the first worksheet in the book.
Worksheet WS = workbook.Worksheets[0];
// Create a range of cells.
Aspose.Cells.Range range = WS.Cells.CreateRange(1, 1, 1, 18);
// Name the range.
range.Name = "MyRange";
// Declare a style object.
Style stl;
// Create/add the style object.
stl = workbook.CreateStyle();
// Specify some Font settings.
stl.Font.Name = "Arial";
stl.Font.IsBold = true;
// Set the font text color
stl.Font.Color = Color.Red;
// To Set the fill color of the range, you may use ForegroundColor with
// Solid Pattern setting.
stl.ForegroundColor = Color.Yellow;
stl.Pattern = BackgroundType.Solid;
// Create a StyleFlag object.
StyleFlag flg = new StyleFlag();
// Make the corresponding attributes ON.
flg.Font = true;
flg.CellShading = true;
// Apply the style to the range.
range.ApplyStyle(stl, flg);
// Save the excel file.
workbook.Save(dataDir + "rangestyles.out.xls");
// ExEnd:1
}
示例7: Run
public static void Run()
{
// ExStart:1
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
// Instantiate a workbook object.
// Open an existing excel file.
Workbook workbook = new Workbook(dataDir + "book1.xls");
// Get the named ranges.
Range[] ranges = workbook.Worksheets.GetNamedRanges();
// Create a style object.
Style style = workbook.CreateStyle();
// Set the shading color with solid pattern type.
style.ForegroundColor = Color.Yellow;
style.Pattern = BackgroundType.Solid;
// Create a styleflag object.
StyleFlag flag = new StyleFlag();
// Apply the cellshading.
flag.CellShading = true;
// Creates an arraylist.
ArrayList al = new ArrayList();
// Get the arraylist collection apply the union operation.
al = ranges[0].Union(ranges[1]);
// Define a range object.
Range rng;
int frow, fcol, erow, ecol;
for (int i = 0; i < al.Count; i++)
{
// Get a range.
rng = (Range)al[i];
frow = rng.FirstRow;
fcol = rng.FirstColumn;
erow = rng.RowCount;
ecol = rng.ColumnCount;
// Apply the style to the range.
rng.ApplyStyle(style, flag);
}
// Save the excel file.
workbook.Save(dataDir + "rngUnion.out.xls");
// ExEnd:1
}
示例8: Run
public static void Run()
{
// ExStart:1
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
string filePath = dataDir + "pivotTable_test.xlsx";
// Create workbook object from source file containing pivot table
Workbook workbook = new Workbook(filePath);
// Access the worksheet by its name
Worksheet worksheet = workbook.Worksheets["PivotTable"];
// Access the pivot table
// PivotTable pivotTable = worksheet.PivotTables[0];
// Create a style object with background color light blue
Style style = workbook.CreateStyle();
style.Pattern = BackgroundType.Solid;
style.BackgroundColor = Color.LightBlue;
// Format entire pivot table with light blue color
// worksheet.FormatAll(style);
// Create another style object with yellow color
style = workbook.CreateStyle();
style.Pattern = BackgroundType.Solid;
style.BackgroundColor = Color.Yellow;
// Format the cells of the first row of the pivot table with yellow color
for (int col = 0; col < 5; col++)
{
// worksheet.Format(1, col, style);
}
dataDir = dataDir + "output.out.xlsx";
// Save the workbook object
workbook.Save(dataDir);
// ExEnd:1
Console.WriteLine("\nProcess completed successfully.\nFile saved at " + dataDir);
}
示例9: Run
public static void Run()
{
// ExStart:1
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
// Instantiate a new Workbook.
Workbook workbook = new Workbook();
// Access the cells in the first worksheet.
Cells cells = workbook.Worksheets[0].Cells;
// Create a range of cells.
Range range = cells.CreateRange("A6", "P216");
// Declare style.
Style stl;
// Create the style adding to the style collection.
stl = workbook.CreateStyle();
// Specify the font settings.
stl.Font.Name = "Arial";
stl.Font.IsBold = true;
stl.Font.Color = Color.Blue;
// Set the borders
stl.Borders[BorderType.TopBorder].LineStyle = CellBorderType.Thin;
stl.Borders[BorderType.TopBorder].Color = Color.Blue;
stl.Borders[BorderType.LeftBorder].LineStyle = CellBorderType.Thin;
stl.Borders[BorderType.LeftBorder].Color = Color.Blue;
stl.Borders[BorderType.BottomBorder].LineStyle = CellBorderType.Thin;
stl.Borders[BorderType.BottomBorder].Color = Color.Blue;
stl.Borders[BorderType.RightBorder].LineStyle = CellBorderType.Thin;
stl.Borders[BorderType.RightBorder].Color = Color.Blue;
// Create StyleFlag object.
StyleFlag flg = new StyleFlag();
// Make the corresponding formatting attributes ON.
flg.Font = true;
flg.Borders = true;
// Apply the style with format settings to the range.
range.ApplyStyle(stl, flg);
// Save the excel file.
workbook.Save( dataDir + "output.xls");
// ExEnd:1
}
示例10: Run
public static void Run()
{
// ExStart:1
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
// Create a workbook.
Workbook workbook = new Workbook();
// Create a new style object.
Style style = workbook.CreateStyle();
// Set the number format.
style.Number = 14;
// Set the font color to red color.
style.Font.Color = System.Drawing.Color.Red;
// Name the style.
style.Name = "Date1";
// Get the first worksheet cells.
Cells cells = workbook.Worksheets[0].Cells;
// Specify the style (described above) to A1 cell.
cells["A1"].SetStyle(style);
// Create a range (B1:D1).
Range range = cells.CreateRange("B1", "D1");
// Initialize styleflag object.
StyleFlag flag = new StyleFlag();
// Set all formatting attributes on.
flag.All = true;
// Apply the style (described above)to the range.
range.ApplyStyle(style, flag);
// Modify the style (described above) and change the font color from red to black.
style.Font.Color = System.Drawing.Color.Black;
// Done! Since the named style (described above) has been set to a cell and range,
// The change would be Reflected(new modification is implemented) to cell(A1) and // Range (B1:D1).
style.Update();
// Save the excel file.
workbook.Save(dataDir+ "book_styles.out.xls");
// ExEnd:1
}
示例11: Main
public static void Main()
{
// The path to the documents directory.
string dataDir = Aspose.Cells.Examples.Utils.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
string filePath = dataDir + "pivotTable_test.xlsx";
//Create workbook object from source file containing pivot table
Workbook workbook = new Workbook(filePath);
//Access the worksheet by its name
Worksheet worksheet = workbook.Worksheets["PivotTable"];
//Access the pivot table
PivotTable pivotTable = worksheet.PivotTables[0];
//Create a style object with background color light blue
Style style = workbook.CreateStyle();
style.Pattern = BackgroundType.Solid;
style.BackgroundColor = Color.LightBlue;
//Format entire pivot table with light blue color
pivotTable.FormatAll(style);
//Create another style object with yellow color
style = workbook.CreateStyle();
style.Pattern = BackgroundType.Solid;
style.BackgroundColor = Color.Yellow;
//Format the cells of the first row of the pivot table with yellow color
for (int col = 0; col < 5; col++)
{
pivotTable.Format(1, col, style);
}
//Save the workbook object
workbook.Save(dataDir+ "output.xlsx");
}
示例12: Run
public static void Run()
{
// ExStart:1
// The path to the documents directory.
string dataDir = RunExamples.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 new Workbook.
Workbook wb1 = new Workbook();
// Get the first worksheet in the workbook.
Worksheet worksheet1 = wb1.Worksheets[0];
// Create a range.
Range mrange = worksheet1.Cells.CreateRange("A18", "J18");
// Name the range.
mrange.Name = "Details";
// Merge the cells of the range.
mrange.Merge();
// Get the range.
Range range1 = wb1.Worksheets.GetRangeByName("Details");
// Define a style object.
Style style = wb1.CreateStyle();
// Set the alignment.
style.HorizontalAlignment = TextAlignmentType.Center;
// Create a StyleFlag object.
StyleFlag flag = new StyleFlag();
// Make the relative style attribute ON.
flag.HorizontalAlignment = true;
// Apply the style to the range.
range1.ApplyStyle(style, flag);
// Input data into range.
range1[0, 0].PutValue("Aspose");
// Save the excel file.
wb1.Save(dataDir + "mergingrange.out.xls");
// ExEnd:1
}
示例13: Run
public static void Run()
{
// ExStart:1
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
// Instantiate a workbook object.
// Open an existing excel file.
Workbook workbook = new Workbook(dataDir + "book1.xls");
// Get the named ranges.
Range[] ranges = workbook.Worksheets.GetNamedRanges();
// Check whether the first range intersect the second range.
bool isintersect = ranges[0].IsIntersect(ranges[1]);
// Create a style object.
Style style = workbook.CreateStyle();
// Set the shading color with solid pattern type.
style.ForegroundColor = Color.Yellow;
style.Pattern = BackgroundType.Solid;
// Create a styleflag object.
StyleFlag flag = new StyleFlag();
// Apply the cellshading.
flag.CellShading = true;
// If first range intersects second range.
if (isintersect)
{
// Create a range by getting the intersection.
Range intersection = ranges[0].Intersect(ranges[1]);
// Name the range.
intersection.Name = "Intersection";
// Apply the style to the range.
intersection.ApplyStyle(style, flag);
}
// Save the excel file.
workbook.Save(dataDir + "rngIntersection.out.xls");
// ExEnd:1
}
示例14: Main
static void Main(string[] args)
{
Workbook workbook = new Workbook(); // Creating a Workbook object
workbook.Worksheets.Add();
Worksheet worksheet = workbook.Worksheets[0];
// Style the cell with borders all around.
Style style = workbook.CreateStyle();
style.SetBorder(BorderType.BottomBorder, CellBorderType.Thin, Color.Black);
style.SetBorder(BorderType.LeftBorder, CellBorderType.Thin, Color.Green);
style.SetBorder(BorderType.RightBorder, CellBorderType.Thin, Color.Blue);
style.SetBorder(BorderType.TopBorder, CellBorderType.MediumDashed, Color.Black);
Cell cell = worksheet.Cells["A1"];
cell.SetStyle(style);
workbook.Save("test.xlsx", SaveFormat.Xlsx); //Workbooks can be saved in many formats
}
示例15: Run
public static void Run()
{
// ExStart:1
// The path to the documents directory.
string dataDir = RunExamples.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);
// Instantiating an Workbook object
Workbook workbook = new Workbook();
// Adding Orchid color to the palette at 55th index
workbook.ChangePalette(Color.Orchid, 55);
// Adding a new worksheet to the Excel object
int i = workbook.Worksheets.Add();
// Obtaining the reference of the newly added worksheet by passing its sheet index
Worksheet worksheet = workbook.Worksheets[i];
// Accessing the "A1" cell from the worksheet
Cell cell = worksheet.Cells["A1"];
// Adding some value to the "A1" cell
cell.PutValue("Hello Aspose!");
// Defining new Style object
Style styleObject = workbook.CreateStyle();
// Setting the Orchid (custom) color to the font
styleObject.Font.Color = Color.Orchid;
// Applying the style to the cell
cell.SetStyle(styleObject);
// Saving the Excel file
workbook.Save(dataDir + "book1.out.xls", SaveFormat.Auto);
// ExEnd:1
}