Rendu graphique

Graphiques de rendu

Prise en charge des API Aspose.Cells pour convertir les graphiques Excel en images et formats PDF sans nécessiter d’outils ou d’applications supplémentaires. Afin de fournir un support de rendu, leGraphique la classe a exposéVersImage & VersPdfméthodes avec une multitude de surcharges pour répondre au mieux aux exigences de l’application.

Rendu des graphiques en images

LeChart.ToImageChart.ToImage & VersPdf La méthode a une vérité de surcharges pour prendre en charge le rendu simple et avancé. Si l’exigence de l’application est de rendre le graphique dans ses dimensions par défaut, nous vous suggérons d’utiliser leChart.ToImageChart.ToImageméthode comme suit.

// 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);
// Instantiating a Workbook object
Workbook workbook = new Workbook();
// Adding a new worksheet to the Workbook
int sheetIndex = workbook.Worksheets.Add();
// Obtaining the reference of the newly added worksheet by passing its index to WorksheetCollection
Worksheet worksheet = workbook.Worksheets[sheetIndex];
// Adding sample values to cells
worksheet.Cells["A1"].PutValue(50);
worksheet.Cells["A2"].PutValue(100);
worksheet.Cells["A3"].PutValue(150);
worksheet.Cells["B1"].PutValue(4);
worksheet.Cells["B2"].PutValue(20);
worksheet.Cells["B3"].PutValue(50);
// Adding a chart to the worksheet
int chartIndex = worksheet.Charts.Add(Aspose.Cells.Charts.ChartType.Column, 5, 0, 15, 5);
// Accessing the instance of the newly added chart
Aspose.Cells.Charts.Chart chart = worksheet.Charts[chartIndex];
// Adding Series Collection (chart data source) to the chart ranging from "A1" cell to "B3"
chart.NSeries.Add("A1:B3", true);
// Converting chart to image
chart.ToImage(dataDir + "chartEMF_out.emf", ImageType.Emf);
// Converting chart to Bitmap
System.Drawing.Bitmap bitmap = chart.ToImage();
bitmap.Save(dataDir + "chartBMP_out.bmp", System.Drawing.Imaging.ImageFormat.Bmp);

Il est également possible de rendre les graphiques en images avec des paramètres avancés. Aspose.Cells Les API ont exposé une version de surcharge deChart.ToImageChart.ToImage méthode qui pourrait accepter une instance deOptions d’image ou d’impression, tout en permettant de spécifier des paramètres tels que la résolution, le mode de lissage, le format d’image, etc.

// 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);
// Instantiating a Workbook object
Workbook workbook = new Workbook();
// Adding a new worksheet to the Workbook
int sheetIndex = workbook.Worksheets.Add();
// Obtaining the reference of the newly added worksheet by passing its index to WorksheetCollection
Worksheet worksheet = workbook.Worksheets[sheetIndex];
// Adding sample values to cells
worksheet.Cells["A1"].PutValue(50);
worksheet.Cells["A2"].PutValue(100);
worksheet.Cells["A3"].PutValue(150);
worksheet.Cells["B1"].PutValue(4);
worksheet.Cells["B2"].PutValue(20);
worksheet.Cells["B3"].PutValue(50);
// Adding a chart to the worksheet
int chartIndex = worksheet.Charts.Add(Aspose.Cells.Charts.ChartType.Column, 5, 0, 15, 5);
// Accessing the instance of the newly added chart
Aspose.Cells.Charts.Chart chart = worksheet.Charts[chartIndex];
// Adding Series Collection (chart data source) to the chart ranging from "A1" cell to "B3"
chart.NSeries.Add("A1:B3", true);
// Create an instance of ImageOrPrintOptions and set a few properties
ImageOrPrintOptions options = new ImageOrPrintOptions()
{
VerticalResolution = 300,
HorizontalResolution = 300,
SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias
};
// Convert chart to image with additional settings
chart.ToImage(dataDir + "chartPNG_out.png", options);

Tableau de rendu au PDF

Afin de rendre le graphique au format PDF, les API Aspose.Cells ont exposé leGraphique.VersPdfméthode avec la possibilité de stocker le PDF résultant sur le chemin du disque ou Stream.

// 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);
// Instantiating a Workbook object
Workbook workbook = new Workbook();
// Adding a new worksheet to the Workbook
int sheetIndex = workbook.Worksheets.Add();
// Obtaining the reference of the newly added worksheet by passing its index to WorksheetCollection
Worksheet worksheet = workbook.Worksheets[sheetIndex];
// Adding sample values to cells
worksheet.Cells["A1"].PutValue(50);
worksheet.Cells["A2"].PutValue(100);
worksheet.Cells["A3"].PutValue(150);
worksheet.Cells["B1"].PutValue(4);
worksheet.Cells["B2"].PutValue(20);
worksheet.Cells["B3"].PutValue(50);
// Adding a chart to the worksheet
int chartIndex = worksheet.Charts.Add(Aspose.Cells.Charts.ChartType.Column, 5, 0, 15, 5);
// Accessing the instance of the newly added chart
Aspose.Cells.Charts.Chart chart = worksheet.Charts[chartIndex];
// Adding Series Collection (chart data source) to the chart ranging from "A1" cell to "B3"
chart.NSeries.Add("A1:B3", true);
// Converting chart to PDF
chart.ToPdf(dataDir + "chartPDF_out.pdf");

Types de graphiques pris en charge pour le rendu

Il existe quelques types de graphiques qui ne sont actuellement pas pris en charge pour le rendu. Ces types de graphiques contiennent** N ** dans le**Colonne Pris en charge** du tableau ci-dessous.

Type de graphique Sous-type de graphique Prise en charge
Colonne Colonne O
Colonneempilée O
Colonne100PercentStacked O
Colonne3DCluster O
Colonne3DSempilé O
Column3D100PercentStacked O
Colonne3D O
Bar Bar O
Barreempilée O
Barre100PercentStacked O
Bar3DCluster O
Bar3DStacked O
Barre3D100Pourcentage empilé O
La ligne La ligne O
Ligneempilée O
Line100PercentStacked O
LineWithDataMarkers O
LineStackedWithDataMarkers O
Line100PercentStackedWithDataMarkers O
Ligne3D O
Tarte Tarte O
Pie3D O
TarteTarte O
TarteExplosée O
Tarte3DÉclaté O
PieBar O
Dispersion Dispersion O
ScatterConnectedByCurvesWithDataMarker O
ScatterConnectedByCurvesWithoutDataMarker O
ScatterConnectedByLinesWithDataMarker O
ScatterConnectedByLinesWithoutDataMarker O
Surface Surface O
Zoneempilée O
Area100PercentStacked O
Zone3D O
Area3DStacked O
Area3D100PercentStacked O
Donut Donut O
BeignetÉclaté O
Radar Radar O
RadarAvecMarqueursDeDonnées O
Radar Rempli O
Surface Surface3D N
SurfaceWireframe3D N
Contour de surface N
SurfaceContourWireframe N
Bulle Bulle O
Bulle3D N
Stocker StockHautBasFermer O
StockOuvertHautBasFermer O
StockVolumeHautBasFermer O
StockVolumeOuvertHautBasFermer O
Cylindre Cylindre O
CylindreEmpilé O
Cylindre100PercentStacked O
CylindriqueBar O
CylindriqueBarEmpilés O
CylindriqueBar100PercentStacked O
CylindriqueColonne3D O
Cône Cône O
ConeStacked O
Cône100PercentStacked O
Barre conique O
ConiqueBarEmpilés O
ConicalBar100PercentStacked O
ConicalColumn3D O
Pyramide Pyramide O
PyramideEmpilés O
Pyramid100PercentStacked O
PyramidBar O
PyramideBarEmpilés O
PyramidBar100PercentStacked O
PyramideColonne3D O
BoxWhisker BoxWhisker Oui
Entonnoir Entonnoir O
Ligne de Pareto Ligne de Pareto O
Coup de soleil Coup de soleil O
Treemap Treemap O
Cascade Cascade O
Histogramme Histogramme Oui
Carte Carte N

Sujets avancés