public void TestAddChartsToNewWorkbook() { XSSFWorkbook wb = new XSSFWorkbook(); XSSFSheet s1 = (XSSFSheet)wb.CreateSheet(); XSSFDrawing d1 = (XSSFDrawing)s1.CreateDrawingPatriarch(); XSSFClientAnchor a1 = new XSSFClientAnchor(0, 0, 0, 0, 1, 1, 10, 30); XSSFChart c1 = (XSSFChart)d1.CreateChart(a1); Assert.AreEqual(1, d1.GetCharts().Count); Assert.IsNotNull(c1.GetGraphicFrame()); Assert.IsNotNull(c1.GetOrCreateLegend()); XSSFClientAnchor a2 = new XSSFClientAnchor(0, 0, 0, 0, 1, 11, 10, 60); XSSFChart c2 = (XSSFChart)d1.CreateChart(a2); Assert.IsNotNull(c2); Assert.AreEqual(2, d1.GetCharts().Count); Assert.IsNotNull(XSSFTestDataSamples.WriteOutAndReadBack(wb)); }
public void TestGetChartAxisBug57362() { //Load existing excel with some chart on it having primary and secondary axis. IWorkbook workbook = XSSFTestDataSamples.OpenSampleWorkbook("57362.xlsx"); ISheet sh = workbook.GetSheetAt(0); XSSFSheet xsh = (XSSFSheet)sh; XSSFDrawing Drawing = xsh.CreateDrawingPatriarch() as XSSFDrawing; XSSFChart chart = Drawing.GetCharts()[(0)]; List <IChartAxis> axisList = chart.GetAxis(); Assert.AreEqual(4, axisList.Count); Assert.IsNotNull(axisList[(0)]); Assert.IsNotNull(axisList[(1)]); Assert.IsNotNull(axisList[(2)]); Assert.IsNotNull(axisList[(3)]); }
/** * Gets the first chart from the named sheet in the workbook. */ private XSSFChart GetChartFromWorkbook(IWorkbook wb, String sheetName) { ISheet sheet = wb.GetSheet(sheetName); if (sheet is XSSFSheet) { XSSFSheet xsheet = (XSSFSheet)sheet; XSSFDrawing drawing = xsheet.CreateDrawingPatriarch() as XSSFDrawing; if (drawing != null) { List <XSSFChart> charts = drawing.GetCharts(); if (charts != null && charts.Count > 0) { return(charts[0]); } } } return(null); }