public void TestAccessMethods() { XSSFWorkbook wb = new XSSFWorkbook(); XSSFSheet sheet = wb.CreateSheet() as XSSFSheet; XSSFDrawing Drawing = sheet.CreateDrawingPatriarch() as XSSFDrawing; XSSFClientAnchor anchor = Drawing.CreateAnchor(0, 0, 0, 0, 1, 1, 10, 30) as XSSFClientAnchor; XSSFChart chart = Drawing.CreateChart(anchor) as XSSFChart; XSSFCategoryAxis axis = chart.ChartAxisFactory.CreateCategoryAxis(AxisPosition.Bottom) as XSSFCategoryAxis; axis.Crosses = (AxisCrosses.AutoZero); Assert.AreEqual(axis.Crosses, AxisCrosses.AutoZero); Assert.AreEqual(chart.GetAxis().Count, 1); }
static void CreateChart(ISheet sheet) { XSSFDrawing drawing = (XSSFDrawing)sheet.CreateDrawingPatriarch(); XSSFClientAnchor anchor = (XSSFClientAnchor)drawing.CreateAnchor(0, 0, 0, 0, 3, 0, 10, 15); IChart chart = drawing.CreateChart(anchor); IChartLegend legend = chart.GetOrCreateLegend(); legend.Position = LegendPosition.Bottom; IBarChartData <string, double> data = chart.ChartDataFactory.CreateBarChartData <string, double>(); IChartAxis bottomAxis = chart.ChartAxisFactory.CreateCategoryAxis(AxisPosition.Bottom); bottomAxis.MajorTickMark = AxisTickMark.None; IValueAxis leftAxis = chart.ChartAxisFactory.CreateValueAxis(AxisPosition.Left); leftAxis.Crosses = AxisCrosses.AutoZero; leftAxis.SetCrossBetween(AxisCrossBetween.Between); IChartDataSource <string> categories = DataSources.FromStringCellRange(sheet, new CellRangeAddress(0, GetPracas().Count() - 1, 0, 0)); // Abono IChartDataSource <double> xAbono = DataSources.FromNumericCellRange(sheet, new CellRangeAddress(0, GetPracas().Count() - 1, 1, 1)); // Isento IChartDataSource <double> xIsento = DataSources.FromNumericCellRange(sheet, new CellRangeAddress(0, GetPracas().Count() - 1, 2, 2)); // Violação IChartDataSource <double> xViolacao = DataSources.FromNumericCellRange(sheet, new CellRangeAddress(0, GetPracas().Count() - 1, 3, 3)); var s1 = data.AddSeries(categories, xAbono); s1.SetTitle("Abono"); var s2 = data.AddSeries(categories, xIsento); s2.SetTitle("Isento"); var s3 = data.AddSeries(categories, xViolacao); s3.SetTitle("Violação"); chart.Plot(data, bottomAxis, leftAxis); }
static void Main(string[] args) { IWorkbook wb = new XSSFWorkbook(); ISheet sheet = wb.CreateSheet(); // Create a row and put some cells in it. Rows are 0 based. IRow row; ICell cell; for (int rowIndex = 0; rowIndex < NUM_OF_ROWS; rowIndex++) { row = sheet.CreateRow((short)rowIndex); for (int colIndex = 0; colIndex < NUM_OF_COLUMNS; colIndex++) { cell = row.CreateCell((short)colIndex); if (colIndex == 0) { cell.SetCellValue("X" + rowIndex); } else { var x = colIndex * (rowIndex + 1); cell.SetCellValue(x * x + 2 * x + 1); } } } XSSFDrawing drawing = (XSSFDrawing)sheet.CreateDrawingPatriarch(); XSSFClientAnchor anchor = (XSSFClientAnchor)drawing.CreateAnchor(0, 0, 0, 0, 3, 3, 10, 12); CreateChart(sheet, drawing, anchor, "s1", 0, 9, 1); using (FileStream fs = File.Create("test.xlsx")) { wb.Write(fs); } }
private XSSFWorkbook CreateBarchart() { XSSFWorkbook workbook = new XSSFWorkbook(); XSSFSheet sheet = (XSSFSheet)workbook.CreateSheet("WorkForceAnalytics"); XSSFCellStyle styleHeader = (XSSFCellStyle)workbook.CreateCellStyle(); styleHeader.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Center; //styleHeader.SetFont(getNewXSSFFont(workbook, styleHeader)); XSSFCellStyle style = (XSSFCellStyle)workbook.CreateCellStyle(); style.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Left; XSSFRow row1 = (XSSFRow)sheet.CreateRow(0); row1.CreateCell(0).SetCellValue(""); List <string> lstdatase = new List <string>(4) { "A1", "B1", "C1", "D1", "E1" }; for (int i = 1; i < 5; i++) { row1.CreateCell(i).SetCellValue(lstdatase[i - 1].ToString()); row1.GetCell(i).CellStyle = styleHeader; } int rowvalue = 1; List <string> lstdata = new List <string>(8) { "A", "B", "C", "D", "E", "F", "G", "H" }; int d = 10; XSSFDrawing drawing = (XSSFDrawing)sheet.CreateDrawingPatriarch(); XSSFClientAnchor anchor = (XSSFClientAnchor)drawing.CreateAnchor(0, 0, 0, 0, 6, 1, 15, 18); IChart chart = drawing.CreateChart(anchor); IChartLegend legend = chart.GetOrCreateLegend(); legend.Position = (LegendPosition.Bottom); IBarChartData <string, double> data = chart.ChartDataFactory.CreateBarChartData <string, double>(); IChartAxis bottomAxis = chart.ChartAxisFactory.CreateCategoryAxis(AxisPosition.Bottom); IValueAxis leftAxis = chart.ChartAxisFactory.CreateValueAxis(AxisPosition.Left); leftAxis.Crosses = AxisCrosses.AutoZero; leftAxis.SetCrossBetween(AxisCrossBetween.Between); IChartDataSource <string> xs = DataSources.FromStringCellRange(sheet, new NPOI.SS.Util.CellRangeAddress(0, 0, 1, 5 - 1)); for (int ii = 0; ii < 8; ii++) { XSSFRow rownew = (XSSFRow)sheet.CreateRow(rowvalue); rownew.CreateCell(0).SetCellValue(lstdata[ii].ToString()); for (int i = 1; i < 5; i++) { rownew.CreateCell(i).SetCellValue(d * 0.1); d++; rownew.GetCell(i).CellStyle = style; } rowvalue++; IChartDataSource <double> ys = DataSources.FromNumericCellRange(sheet, new NPOI.SS.Util.CellRangeAddress(ii + 1, ii + 1, 1, 5 - 1)); data.AddSeries(xs, ys).SetTitle(lstdata[ii].ToString()); } chart.Plot(data, bottomAxis, leftAxis); sheet.ForceFormulaRecalculation = true; return(workbook); }