Använda Sparklines och inställningar 3D-format

Använder Sparklines

Microsoft Excel 2010 kan analysera information på fler sätt än någonsin tidigare. Det låter användare spåra och lyfta fram viktiga datatrender med nya verktyg för dataanalys och visualisering. Sparklines är minidiagram som du kan placera inuti celler så att du kan se data och diagram på samma tabell. När sparklines används på rätt sätt går dataanalysen snabbare och mer rakt på sak. De ger också en enkel bild av information, och undviker överfulla kalkylblad med många upptagna diagram.

Aspose.Cells tillhandahåller en API för att manipulera sparklines i kalkylblad.

Sparklines i Microsoft Excel

Så här infogar du sparklines i Microsoft Excel 2010:

  1. Markera cellerna där du vill att gnistlinjerna ska visas. För att göra dem enkla att se, markera celler vid sidan av data.
  2. KlickFöra in på bandet och välj sedankolumn iSparklines grupp.
  3. Välj eller ange cellintervallet i kalkylbladet som innehåller källdata. Diagrammen kommer att visas.

Sparklines hjälper dig att se trender, till exempel vinst- eller förlustrekord för en softballliga. Sparklines kan till och med summera hela säsongen för varje lag i ligan.

Sparklines med Aspose.Cells

Utvecklare kan skapa, ta bort eller läsa sparklines (i mallfilen) med hjälp av API från Aspose.Cells. Klasserna som hanterar sparklines finns iAspose.Cells.Chartsnamnutrymme så du måste importera detta namnutrymme innan du använder dessa funktioner.

Genom att lägga till anpassad grafik för ett givet dataintervall har utvecklarna friheten att lägga till olika typer av små diagram till utvalda cellområden.

Exemplet nedan visar Sparklines-funktionen. Exemplet visar hur man:

  1. Öppna en enkel mallfil.
  2. Läs sparklines-information för ett kalkylblad.
  3. Lägg till nya sparklines för ett givet dataintervall till ett cellområde.
  4. Spara Excel-filen på disk.
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
// Instantiate a Workbook
// Open a template file
Workbook book = new Workbook(dataDir + "Book1.xlsx");
// Get the first worksheet
Worksheet sheet = book.Worksheets[0];
// Use the following lines if you need to read the Sparklines
// Read the Sparklines from the template file (if it has)
foreach (SparklineGroup g in sheet.SparklineGroups)
{
// Display the Sparklines group information e.g type, number of sparklines items
Console.WriteLine("sparkline group: type:" + g.Type + ", sparkline items count:" + g.Sparklines.Count);
foreach (Sparkline s in g.Sparklines)
{
// Display the individual Sparkines and the data ranges
Console.WriteLine("sparkline: row:" + s.Row + ", col:" + s.Column + ", dataRange:" + s.DataRange);
}
}
// Add Sparklines
// Define the CellArea D2:D10
CellArea ca = new CellArea();
ca.StartColumn = 4;
ca.EndColumn = 4;
ca.StartRow = 1;
ca.EndRow = 7;
// Add new Sparklines for a data range to a cell area
int idx = sheet.SparklineGroups.Add(SparklineType.Column, "Sheet1!B2:D8", false, ca);
SparklineGroup group = sheet.SparklineGroups[idx];
// Create CellsColor
CellsColor clr = book.CreateCellsColor();
clr.Color = Color.Orange;
group.SeriesColor = clr;
// Save the excel file
book.Save(dataDir + "Book1.out.xlsx");

Ställa in 3D-format

Du kanske behöver 3D-diagramstilar så att du kan få precis resultaten för ditt scenario. Aspose.Cells tillhandahåller relevant API för att tillämpa Microsoft Excel 2007 3D-formatering.

Ett komplett exempel ges nedan för att visa hur man skapar ett diagram och tillämpar Microsoft Excel 2007 3D-formatering. Efter exekvering av exempelkoden kommer ett kolumndiagram (med 3D-effekter) att läggas till i kalkylbladet.

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// 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 book = new Workbook();
// Add a Data Worksheet
Worksheet dataSheet = book.Worksheets.Add("DataSheet");
// Add Chart Worksheet
Worksheet sheet = book.Worksheets.Add("MyChart");
// Put some values into the cells in the data worksheet
dataSheet.Cells["B1"].PutValue(1);
dataSheet.Cells["B2"].PutValue(2);
dataSheet.Cells["B3"].PutValue(3);
dataSheet.Cells["A1"].PutValue("A");
dataSheet.Cells["A2"].PutValue("B");
dataSheet.Cells["A3"].PutValue("C");
// Define the Chart Collection
ChartCollection charts = sheet.Charts;
// Add a Column chart to the Chart Worksheet
int chartSheetIdx = charts.Add(ChartType.Column, 5, 0, 25, 15);
// Get the newly added Chart
Aspose.Cells.Charts.Chart chart = book.Worksheets[2].Charts[0];
// Set the background/foreground color for PlotArea/ChartArea
chart.PlotArea.Area.BackgroundColor = Color.White;
chart.ChartArea.Area.BackgroundColor = Color.White;
chart.PlotArea.Area.ForegroundColor = Color.White;
chart.ChartArea.Area.ForegroundColor = Color.White;
// Hide the Legend
chart.ShowLegend = false;
// Add Data Series for the Chart
chart.NSeries.Add("DataSheet!B1:B3", true);
// Specify the Category Data
chart.NSeries.CategoryData = "DataSheet!A1:A3";
// Get the Data Series
Aspose.Cells.Charts.Series ser = chart.NSeries[0];
// Apply the 3-D formatting
ShapePropertyCollection spPr = ser.ShapeProperties;
Format3D fmt3d = spPr.Format3D;
// Specify Bevel with its height/width
Bevel bevel = fmt3d.TopBevel;
bevel.Type = BevelPresetType.Circle;
bevel.Height = 2;
bevel.Width = 5;
// Specify Surface material type
fmt3d.SurfaceMaterialType = PresetMaterialType.WarmMatte;
// Specify surface lighting type
fmt3d.SurfaceLightingType = LightRigType.ThreePoint;
// Specify lighting angle
fmt3d.LightingAngle = 20;
// Specify Series background/foreground and line color
ser.Area.BackgroundColor = Color.Maroon;
ser.Area.ForegroundColor = Color.Maroon;
ser.Border.Color = Color.Maroon;
// Save the Excel file
book.Save(dataDir + "3d_format.out.xlsx");