本文整理汇总了C#中Workbook.ChangePalette方法的典型用法代码示例。如果您正苦于以下问题:C# Workbook.ChangePalette方法的具体用法?C# Workbook.ChangePalette怎么用?C# Workbook.ChangePalette使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Workbook
的用法示例。
在下文中一共展示了Workbook.ChangePalette方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
static void Main(string[] args)
{
Workbook workbook = new Workbook(); // Creating a Workbook object
workbook.Worksheets.Add();
Worksheet worksheet = workbook.Worksheets[0];
//Accessing cell from the worksheet
Cell cell = worksheet.Cells["B2"];
Style style = cell.GetStyle();
//Setting the foreground color to yellow
style.BackgroundColor = Color.Yellow;
//Setting the background pattern to vertical stripe
style.Pattern = BackgroundType.VerticalStripe;
//Saving the modified style to the "B2" cell.
cell.SetStyle(style);
// === Setting Foreground ===
//Adding custom color to the palette at 55th index
Color color = Color.FromArgb(212, 213, 0);
workbook.ChangePalette(color, 55);
//Accessing cell from the worksheet
cell = worksheet.Cells["B3"];
//Adding some value to the cell
cell.PutValue("Hello Aspose!");
workbook.Save("test.xlsx", SaveFormat.Xlsx); //Workbooks can be saved in many formats
}
示例2: CreateSalesReport
private static void CreateSalesReport(string filename)
{
// Uncomment the code below when you have purchased license
// for Aspose.Cells. You need to deploy the license in the
// same folder as your executable, alternatively you can add
// the license file as an embedded resource to your project.
//
// // Set license for Aspose.Cells
// Aspose.Cells.License cellsLicense = new
// Aspose.Cells.License();
// cellsLicense.SetLicense("Aspose.Cells.lic");
//Create a new Workbook.
Workbook workbook = new Workbook();
//Note: Since Excel color palette has 56 colors on it.
//The colors are indexed 0-55.
//Please check: http://www.aspose.com/Products/Aspose.Cells/Api/Aspose.Cells.Workbook.ChangePalette.html
//If a color is not present on the palette, we have to add it
//to the palette, so that we may use.
//Add a few custom colors to the palette.
workbook.ChangePalette(Color.FromArgb(155, 204, 255), 55);
workbook.ChangePalette(Color.FromArgb(0, 51, 105), 54);
workbook.ChangePalette(Color.FromArgb(250, 250, 200), 53);
workbook.ChangePalette(Color.FromArgb(124, 199, 72), 52);
CreateReportData(workbook);
CreateCellsFormatting(workbook);
//Get the first worksheet in the book.
Worksheet worksheet = workbook.Worksheets[0];
//Name the worksheet.
worksheet.Name = "Sales Report";
//Save the excel file.
workbook.Save(filename);
}
示例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);
// 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
}
示例4: Main
public static void Main(string[] args)
{
// The path to the documents directory.
string dataDir = Path.GetFullPath("../../../Data/");
// 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.Styles[workbook.Styles.Add()];
//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.xls", SaveFormat.Auto);
}
示例5: GenerateChartSheet
private void GenerateChartSheet(Workbook workbook, DataSet ds)
{
//Generate the second chart sheet
int sheetIndex = workbook.Worksheets.Add(SheetType.Chart);
Worksheet sheet2 = workbook.Worksheets[sheetIndex];
//Name the sheet
sheet2.Name = "Pareto Chart";
//Set chart index
int chartIndex = sheet2.Charts.Add(ChartType.Column, 0, 0, 0, 0);
//Get chart type
Chart chart = sheet2.Charts[chartIndex];
//Set chart title text
chart.Title.Text = "Cost Center";
//Set chart title font
chart.Title.TextFont.IsBold = true;
chart.Title.TextFont.Size = 16;
//Set series
string series = "Cost Data!B2:B" + (ds.Tables[0].Rows.Count + 1);
//Series add in chart
chart.NSeries.Add(series, true);
//Set series name
chart.NSeries[0].Name = "Annual Cost";
//Set category
chart.NSeries.CategoryData = "Cost Data!A2:A" + (ds.Tables[0].Rows.Count + 1);
//Legend not shown
chart.ShowLegend = false;
//Set chart style
workbook.ChangePalette(Color.FromArgb(255, 255, 200), 53);
//Set plot area foreground color
chart.PlotArea.Area.ForegroundColor = Color.FromArgb(255, 255, 200);
//Set major grid line color
workbook.ChangePalette(Color.FromArgb(121, 117, 200), 54);
chart.CategoryAxis.MajorGridLines.Color = Color.FromArgb(121, 117, 200);
//Set series each point color
for (int i = 0; i < chart.NSeries[0].Points.Count; i++)
{
workbook.ChangePalette(Color.FromArgb(10, 100, 180), 55);
chart.NSeries[0].Points[i].Area.ForegroundColor = Color.FromArgb(10, 100, 180);
workbook.ChangePalette(Color.FromArgb(255, 255, 200), 53);
chart.NSeries[0].Points[i].Border.Color = Color.FromArgb(255, 255, 200);
}
}
示例6: GenerateDataSheet
private void GenerateDataSheet(Workbook workbook, DataSet ds)
{
//Write data to first data sheet
Worksheet sheet1 = workbook.Worksheets[0];
//Name the sheet
sheet1.Name = "Cost Data";
//Write sheet1 cells data to cells object
Cells cells = sheet1.Cells;
//Import data into cells
cells.ImportDataTable(ds.Tables[0], true, 0, 0, ds.Tables[0].Rows.Count, ds.Tables[0].Columns.Count);
//Set header style with specific formatting attributes
StyleCollection styles = workbook.Styles;
//Set style index
int styleIndex = styles.Add();
//Set style attribute using style index
Style style = styles[styleIndex];
//Set font size
style.Font.Size = 10;
//Set font color to white
style.Font.Color = Color.White;
//Set font to bold
style.Font.IsBold = true;
//Set font name to Verdana
style.Font.Name = "Verdana";
//Locked style
style.IsLocked = true;
//Set vertical alignment
style.VerticalAlignment = TextAlignmentType.Center;
//Set horizontal alignment
style.HorizontalAlignment = TextAlignmentType.Left;
//Set indent level
style.IndentLevel = 1;
//Set top, bottom, left and right borders style
style.Borders[BorderType.BottomBorder].LineStyle = CellBorderType.Thick;
style.Borders[BorderType.TopBorder].LineStyle = CellBorderType.Thin;
style.Borders[BorderType.LeftBorder].LineStyle = CellBorderType.Thin;
style.Borders[BorderType.RightBorder].LineStyle = CellBorderType.Thin;
//Change the palette for the spreadsheet in the specified index
workbook.ChangePalette(Color.FromArgb(10, 100, 180), 50);
//Change foreground color
style.ForegroundColor = Color.FromArgb(10, 100, 180);
//Set background style pattern
style.Pattern = BackgroundType.Solid;
//Set first two column's widths and set the height of the first row
cells.SetColumnWidth(0, 25);
cells.SetColumnWidth(1, 18);
cells.SetRowHeight(0, 30);
//Apply the style to A1 cell
cells[0, 0].SetStyle(style);
//Add a new style
styleIndex = styles.Add();
Style style1 = styles[styleIndex];
//Copy above created style to it
style1.Copy(style);
//Set horizontal alignment and indentation
style1.HorizontalAlignment = TextAlignmentType.Right;
style1.IndentLevel = 0;
//Apply the style to B1 cell
cells[0, 1].SetStyle(style1);
//Set current row to 1
int currentRow = 1;
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
//Set row height and color
cells.SetRowHeight(currentRow, 20);
Color color = Color.FromArgb(255, 255, 255);
//Change palette color of workbook
workbook.ChangePalette(color, 51);
//Change color of even number rows
if (currentRow % 2 == 0)
{
//Set color
color = Color.FromArgb(250, 250, 200);
//.........这里部分代码省略.........
示例7: CreateCatalog
public Workbook CreateCatalog()
{
try
{
DBInit();
}
catch
{
}
//Open a template file
string designerFile = MapPath("~/Designer/Northwind.xls");
Workbook workbook = new Workbook(designerFile);
ReadCategory();
//Create a new datatable
DataTable dataTable2 = new DataTable();
//Get a worksheet
Worksheet sheet = workbook.Worksheets["Sheet2"];
//Name the sheet
sheet.Name = "Catalog";
//Get the worksheet cells
Cells cells = sheet.Cells;
int currentRow = 55;
//Add LightGray color to color palette
workbook.ChangePalette(Color.LightGray, 55);
//Get the workbook's styles collection
StyleCollection styles = workbook.Styles;
//Set CategoryName style with formatting attributes
int styleIndex = styles.Add();
Style styleCategoryName = styles[styleIndex];
styleCategoryName.Font.Size = 14;
styleCategoryName.Font.Color = Color.Blue;
styleCategoryName.Font.IsBold = true;
styleCategoryName.Font.Name = "Times New Roman";
//Set Description style with formatting attributes
styleIndex = styles.Add();
Style styleDescription = styles[styleIndex];
styleDescription.Font.Name = "Times New Roman";
styleDescription.Font.Color = Color.Blue;
styleDescription.Font.IsItalic = true;
//Set ProductName style with formatting attributes
styleIndex = styles.Add();
Style styleProductName = styles[styleIndex];
styleProductName.Font.IsBold = true;
//Set Title style with formatting attributes
styleIndex = styles.Add();
Style styleTitle = styles[styleIndex];
styleTitle.Font.IsBold = true;
styleTitle.Font.IsItalic = true;
styleTitle.ForegroundColor = Color.LightGray;
styleIndex = styles.Add();
Style styleNumber = styles[styleIndex];
styleNumber.Font.Name = "Times New Roman";
styleNumber.Number = 8;
//Create the styleflag struct
StyleFlag styleflag = new StyleFlag();
styleflag.All = true;
//Get the horizontal page breaks collection
HorizontalPageBreakCollection hPageBreaks = sheet.HorizontalPageBreaks;
//Specify SQL for the command
string cmd = "SELECT ProductName, ProductID, QuantityPerUnit, " +
"UnitPrice FROM Products";
for (int i = 0; i < this.dataTable1.Rows.Count; i++)
{
currentRow += 2;
cells.SetRowHeight(currentRow, 20);
cells[currentRow, 1].SetStyle(styleCategoryName);
DataRow categoriesRow = this.dataTable1.Rows[i];
//Write CategoryName
cells[currentRow, 1].PutValue((string)categoriesRow["CategoryName"]);
//Write Description
currentRow++;
cells[currentRow, 1].PutValue((string)categoriesRow["Description"]);
cells[currentRow, 1].SetStyle(styleDescription);
dataTable2.Clear();
//Execuate command and fill the datatable
try
{
this.oleDbDataAdapter2 = new OleDbDataAdapter();
string cmdText = cmd + " where categoryid = "
+ categoriesRow["CategoryID"].ToString();
this.oleDbDataAdapter2.SelectCommand = new OleDbCommand(cmdText, this.oleDbConnection1);
this.oleDbConnection1.Open();
oleDbDataAdapter2.Fill(dataTable2);
}
catch
{
//.........这里部分代码省略.........
示例8: SetInvoiceStyles
private void SetInvoiceStyles(Workbook workbook)
{
//Add LightBlue and DarkBlue colors to color palette
workbook.ChangePalette(Color.LightBlue, 54);
workbook.ChangePalette(Color.DarkBlue, 55);
//Create a style with specific formatting attributes
Style style;
int styleIndex = workbook.Styles.Add();
style = workbook.Styles[styleIndex];
style.Font.Size = 12;
style.Font.IsBold = true;
style.Font.Color = Color.White;
style.ForegroundColor = Color.LightBlue;
style.Pattern = BackgroundType.Solid;
style.HorizontalAlignment = TextAlignmentType.Center;
style.Name = "Font12Center";
//Create a style with specific formatting attributes
styleIndex = workbook.Styles.Add();
style = workbook.Styles[styleIndex];
style.Font.Size = 12;
style.Font.IsBold = true;
style.Font.Color = Color.White;
style.ForegroundColor = Color.LightBlue;
style.Pattern = BackgroundType.Solid;
style.HorizontalAlignment = TextAlignmentType.Left;
style.Name = "Font12Left";
//Create a style with specific formatting attributes
styleIndex = workbook.Styles.Add();
style = workbook.Styles[styleIndex];
style.Font.Size = 12;
style.Font.IsBold = true;
style.Font.Color = Color.White;
style.ForegroundColor = Color.LightBlue;
style.Pattern = BackgroundType.Solid;
style.HorizontalAlignment = TextAlignmentType.Right;
style.Name = "Font12Right";
//Create a style with specific formatting attributes
styleIndex = workbook.Styles.Add();
style = workbook.Styles[styleIndex];
style.Number = 7;
style.Name = "Number7";
//Create a style with specific formatting attributes
styleIndex = workbook.Styles.Add();
style = workbook.Styles[styleIndex];
style.Number = 9;
style.Name = "Number9";
//Create a style with specific formatting attributes
styleIndex = workbook.Styles.Add();
style = workbook.Styles[styleIndex];
style.HorizontalAlignment = TextAlignmentType.Center;
style.Name = "Center";
//Create a style with specific formatting attributes
styleIndex = workbook.Styles.Add();
style = workbook.Styles[styleIndex];
style.Font.Size = 16;
style.Font.IsBold = true;
style.Font.Color = Color.DarkBlue;
style.Name = "Darkblue";
//Create a style with specific formatting attributes
styleIndex = workbook.Styles.Add();
style = workbook.Styles[styleIndex];
style.Font.Size = 12;
style.Font.IsBold = true;
style.Font.Color = Color.DarkBlue;
style.Name = "Darkblue12";
//Create a style with specific formatting attributes
styleIndex = workbook.Styles.Add();
style = workbook.Styles[styleIndex];
style.Font.IsItalic = true;
style.Font.Color = Color.DarkBlue;
style.Name = "DarkblueItalic";
//Create a style with specific formatting attributes
styleIndex = workbook.Styles.Add();
style = workbook.Styles[styleIndex];
style.Borders[BorderType.BottomBorder].Color = Color.Black;
style.Borders[BorderType.BottomBorder].LineStyle = CellBorderType.Medium;
style.Name = "BlackMedium";
}