예제 #1
0
        public void TestGetCharts()
        {
            XSSFWorkbook wb = XSSFTestDataSamples.OpenSampleWorkbook("WithThreeCharts.xlsx");

            XSSFSheet s1 = (XSSFSheet)wb.GetSheetAt(0);
            XSSFSheet s2 = (XSSFSheet)wb.GetSheetAt(1);
            XSSFSheet s3 = (XSSFSheet)wb.GetSheetAt(2);

            Assert.AreEqual(0, (s1.CreateDrawingPatriarch() as XSSFDrawing).GetCharts().Count);
            Assert.AreEqual(2, (s2.CreateDrawingPatriarch() as XSSFDrawing).GetCharts().Count);
            Assert.AreEqual(1, (s3.CreateDrawingPatriarch() as XSSFDrawing).GetCharts().Count);

            // Check the titles
            XSSFChart chart = (s2.CreateDrawingPatriarch() as XSSFDrawing).GetCharts()[(0)];

            Assert.AreEqual(null, chart.Title);

            chart = (s2.CreateDrawingPatriarch() as XSSFDrawing).GetCharts()[(1)];
            Assert.AreEqual("Pie Chart Title Thingy", chart.Title.String);

            chart = (s3.CreateDrawingPatriarch() as XSSFDrawing).GetCharts()[(0)];
            Assert.AreEqual("Sheet 3 Chart with Title", chart.Title.String);

            Assert.IsNotNull(XSSFTestDataSamples.WriteOutAndReadBack(wb));
        }
예제 #2
0
        /**
         * Assign a DrawingML chart to the graphic frame.
         */
        internal void SetChart(XSSFChart chart, String relId)
        {
            CT_GraphicalObjectData data = graphicFrame.graphic.AddNewGraphicData();

            AppendChartElement(data, relId);
            chart.SetGraphicFrame(this);
            return;
        }
예제 #3
0
        public IChart CreateChart(IClientAnchor anchor)
        {
            int       idx          = this.GetPackagePart().Package.GetPartsByContentType(XSSFRelation.CHART.ContentType).Count + 1;
            XSSFChart relationship = (XSSFChart)this.CreateRelationship((POIXMLRelation)XSSFRelation.CHART, (POIXMLFactory)XSSFFactory.GetInstance(), idx);
            string    id           = relationship.GetPackageRelationship().Id;

            this.CreateGraphicFrame((XSSFClientAnchor)anchor).SetChart(relationship, id);
            return((IChart)relationship);
        }
예제 #4
0
        public void TestGetCharts()
        {
            XSSFWorkbook wb = XSSFTestDataSamples.OpenSampleWorkbook("chart_sheet.xlsx");

            XSSFSheet      ns = (XSSFSheet)wb.GetSheetAt(0);
            XSSFChartSheet cs = (XSSFChartSheet)wb.GetSheetAt(2);

            Assert.AreEqual(0, (ns.CreateDrawingPatriarch() as XSSFDrawing).GetCharts().Count);
            Assert.AreEqual(1, (cs.CreateDrawingPatriarch() as XSSFDrawing).GetCharts().Count);

            XSSFChart chart = (cs.CreateDrawingPatriarch() as XSSFDrawing).GetCharts()[0];

            Assert.AreEqual(null, chart.Title);
        }
예제 #5
0
        /// <summary>
        /// Creates a chart.
        /// </summary>
        /// <param name="anchor">the client anchor describes how this chart is attached to</param>
        /// <returns>the newly created chart</returns>
        public IChart CreateChart(IClientAnchor anchor)
        {
            int chartNumber = GetPackagePart().Package.
                              GetPartsByContentType(XSSFRelation.CHART.ContentType).Count + 1;

            XSSFChart chart = (XSSFChart)CreateRelationship(
                XSSFRelation.CHART, XSSFFactory.GetInstance(), chartNumber);
            String chartRelId = chart.GetPackageRelationship().Id;

            XSSFGraphicFrame frame = CreateGraphicFrame((XSSFClientAnchor)anchor);

            frame.SetChart(chart, chartRelId);

            return(chart);
        }
예제 #6
0
        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)]);
        }
예제 #7
0
        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.AreEqual(2, d1.GetCharts().Count);
        }
예제 #8
0
 /**
  * Assign a DrawingML chart to the graphic frame.
  */
 internal void SetChart(XSSFChart chart, String relId)
 {
     CT_GraphicalObjectData data = graphicFrame.graphic.AddNewGraphicData();
     AppendChartElement(data, relId);
     chart.SetGraphicFrame(this);
     return;
 }
예제 #9
0
 internal void SetChart(XSSFChart chart, string relId)
 {
     this.AppendChartElement(this.graphicFrame.graphic.AddNewGraphicData(), relId);
     chart.SetGraphicFrame(this);
 }