Je sais que ma question sera très similaire à celle des autres déjà demandées, mais comme je ne peux pas trouver une réponse satisfaisante, j'essaie ma chance! P>
Sachez s'il est possible ou non de générer des graphiques dans une feuille de calcul Excel à l'aide du bibliothèque NPOI . < / p>
4 Réponses :
Après plus d'investigation, j'ai eu ma réponse ici: http://npoi.codeplex.com/relases / Voir / 19351 P>
Caractéristiques non supportées: Graphique Excel P> blockQuote>
Ainsi, comme expliqué par Leniel dans son blog, nous devons utiliser une feuille de calcul primaire en tant que modèle. P>
Merci beaucoup Leniel! :) p>
Merci d'avoir fait cette enquête
Maintenant, il est possible d'utiliser NPOI: github.com/tonyqus / NPOI / BLOB / MASTER / Exemples / XSSF / LINCHART / ...
Une autre solution pour créer un graphique sans automatisation consiste à utiliser des composants tiers, par exemple celui-ci SmartXLS pour .NET A >, il peut créer des graphiques / pivottables à partir de zéro. p>
Merci Liya, je vais regarder ça!
Pour l'exemple de NPOI avec graphique Voir: http: //www.zachhunter. COM / 2010/05 / NPOI-Excel-Modèle / P>
Cela ne répond pas aux exigences de la question. La personne qui a posé la question indique même qu'il ne veut pas le faire d'un modèle.
Maintenant, il est possible d'utiliser NPOI: github.com/tonyqus / NPOI / BLOB / MASTER / Exemples / XSSF / LINCHART / ...
J'ai trouvé un moyen autour de cela, car j'ai aussi eu le même problème. Il n'y a pas beaucoup de bons exemples à l'aide du port C # de NPOI pour générer des graphiques. La plupart des gens, je pense utiliser un modèle et une annonce modifier ensuite le résultat.
Selon le type de graphique dont vous avez besoin, différentes méthodologies doivent être utilisées. Mes exemples ont été volés directement à partir de mon propre code qui a fonctionné avec 2.5.2, il se manquait donc de la définition de Vars comme des varès, de sorte que vous aurez besoin de remplir ceux-ci en vous-même. P>
pour les graphiques de barre et de ligne Vous pouvez utiliser quelque chose de simple Les éléments suivants: P>
/* At the end of this step, we have a worksheet with test data, that we want to write into a chart */ /* Create a drawing canvas on the worksheet */ IDrawing drawing = sheet.CreateDrawingPatriarch ( ); /* Define anchor points in the worksheet to position the chart */ IClientAnchor anchor = drawing.CreateAnchor ( 0, 0, 0, 0, 0, 3, 10, 23 ); row = row + 23; /* Create the chart object based on the anchor point */ IChart pieChart = drawing.CreateChart ( anchor ); XSSFChart xssfChart = (XSSFChart) pieChart; MethodInfo dynMethod = xssfChart.GetType ( ).GetMethod ( "GetCTChart", BindingFlags.NonPublic | BindingFlags.Instance ); object oCTChart = dynMethod.Invoke ( xssfChart, null ); CT_Chart ctChart = (CT_Chart) oCTChart; //CT_PlotArea plotArea = xssfChart.GetCTChart ( ).plotArea == null ? xssfChart.GetCTChart ( ).AddNewPlotArea ( ) : xssfChart.GetCTChart ( ).plotArea; CT_PlotArea plotArea = ctChart.plotArea == null ? ctChart.AddNewPlotArea ( ) : ctChart.plotArea; //plotArea. var ctpieChart = plotArea.AddNewPie3DChart ( ); //CT_Pie3DChart ctpieChart = plotArea.AddNewPie3DChart ( ); CT_Boolean bVaryColor = new CT_Boolean ( ); bVaryColor.val = 1; ctpieChart.varyColors = bVaryColor; // .AddNewVaryColors ( ).val = 1;// addNewVaryColors ( ).setVal ( true ); //xssfChart. ( this.title ); IChartDataSource<double> xs = DataSources.FromNumericCellRange ( sheetChart, new CellRangeAddress ( 2, iDataPoints, 0, 0 ) ); //Defines the rows/columns used for the line data IChartDataSource<double> ys1 = DataSources.FromNumericCellRange ( sheetChart, new CellRangeAddress ( 2, iDataPoints, 1, 1 ) ); String axisDataRange = new CellRangeAddress ( 2, iDataPoints, 0, 0 ).FormatAsString ( sheetChart.SheetName, true ); String numDataRange = new CellRangeAddress ( 2, iDataPoints, 1, 1 ).FormatAsString ( sheetChart.SheetName, true ); CT_UnsignedInt uIval = new CT_UnsignedInt ( ); uIval.val = 0; //Pie Chart Series ctpieChart.ser = new List<CT_PieSer> ( ); CT_PieSer ser = new CT_PieSer ( ); //.AddNewSer ( ); ser.idx = uIval; ser.order = uIval; //Create category section ser.cat = new CT_AxDataSource ( ); ser.cat.strRef = new CT_StrRef ( ); ser.cat.strRef.strCache = new CT_StrData ( ); ser.cat.strRef.f = axisDataRange; CT_UnsignedInt uIRange = new CT_UnsignedInt ( ); uIRange.val = (uint) dataSet.Tables[ "_CHART" ].Rows.Count; ser.cat.strRef.strCache.ptCount = uIRange; //Create value section ser.val = new CT_NumDataSource ( ); ser.val.numRef = new CT_NumRef ( ); ser.val.numRef.f = numDataRange; ser.val.numRef.numCache = new CT_NumData ( ); ser.val.numRef.numCache.formatCode = "General"; ser.val.numRef.numCache.ptCount = uIRange; //Create Pts array ser.dPt = new List<CT_DPt> ( ); //Create Category Pts ser.cat.strRef.strCache.pt = new List<CT_StrVal> ( ); //Create Value Pts ser.val.numRef.numCache.pt = new List<CT_NumVal> ( ); //Create Chart Styles/Settings ser.dLbls = new CT_DLbls ( ); ser.dLbls.spPr = new CT_ShapeProperties ( ); ser.dLbls.spPr.noFill = new NPOI.OpenXmlFormats.Dml.CT_NoFillProperties ( ); ser.dLbls.spPr.ln = new NPOI.OpenXmlFormats.Dml.CT_LineProperties ( ); ser.dLbls.spPr.ln.noFill = new NPOI.OpenXmlFormats.Dml.CT_NoFillProperties ( ); ser.dLbls.showSerName = new CT_Boolean ( ) { val = 0 }; ser.dLbls.showPercent = new CT_Boolean ( ) { val = 0 }; //Add the series ctpieChart.ser.Add ( ser ); //Loop through points and add to arrays for ( int iPt = 0; iPt < dataSet.Tables[ "_CHART" ].Rows.Count; iPt++ ) { CT_UnsignedInt uIPt = new CT_UnsignedInt ( ); uIPt.val = (uint) iPt; //Create Pt CT_DPt oPt = new CT_DPt ( ); oPt.idx = uIPt; ser.dPt.Add ( oPt ); //Create Label Pt CT_StrVal cPt = new CT_StrVal ( ); cPt.idx = (uint) iPt; cPt.v = dataSet.Tables[ "_CHART" ].Rows[ iPt ][ "Label" ].ToString ( ); ser.cat.strRef.strCache.pt.Add ( cPt ); //Create Value Pt CT_NumVal vPt = new CT_NumVal ( ); vPt.idx = (uint) iPt; vPt.v = dataSet.Tables[ "_CHART" ].Rows[ iPt ][ "Value" ].ToString ( ); ser.val.numRef.numCache.pt.Add ( vPt ); }
Maintenant, il est possible d'utiliser NPOI: github.com/tonyqus / NPOI / BLOB / MASTER / Exemples / XSSF / LINCHART / ...