public InsertChartAt ( string cellName, |
||
cellName | string | |
chart | ||
리턴 | void |
public void CreateNewChart() { SpreadsheetDocument doc = new SpreadsheetDocument (); doc.New (); Table table = new Table (doc,"tab1","tab1"); for(int i=1; i<=1; i++) { for(int j=1; j<=6;j++) { Cell cell = table.CreateCell (); cell.OfficeValueType ="float"; Paragraph paragraph = new Paragraph (doc); string text= (j+i-1).ToString(); paragraph.TextContent .Add (new SimpleText ( doc,text)); cell.Content.Add(paragraph); cell.OfficeValueType = "string"; cell.OfficeValue = text; table.InsertCellAt (i, j, cell); } } Chart chart=ChartBuilder.CreateChartByAxisName (table,ChartTypes.bar ,"A1:E4","years","dollars"); Assert.AreEqual(7, table.Rows[1].Cells.Count); Assert.AreEqual(6, table.Rows[2].Cells.Count); Assert.AreEqual(6, table.Rows[3].Cells.Count); Assert.AreEqual(6, table.Rows[4].Cells.Count); /*Chart chart = new Chart (table,"ch1"); chart.ChartType=ChartTypes.bar .ToString () ; chart.XAxisName ="yeer"; chart.YAxisName ="dollar"; chart.CreateFromCellRange ("A1:E4"); chart.EndCellAddress ="tab1.K17";*/ table.InsertChartAt ("G2",chart); doc.Content .Add (table); doc.SaveTo(Path.Combine(AARunMeFirstAndOnce.outPutFolder, @"NewChartOne.ods")); }
public void NewBasicChartThenSetTitle() { string expected="Basic Chart"; SpreadsheetDocument doc = new SpreadsheetDocument(); doc.New(); Table table = new Table(doc, "tab1", "tab1"); for (int i = 1; i <= 1; i++) { for (int j = 1; j <= 6; j++) { Cell cell = table.CreateCell(); cell.OfficeValueType = "float"; Paragraph paragraph = new Paragraph(doc); string text = (j + i - 1).ToString(); paragraph.TextContent.Add(new SimpleText(doc, text)); cell.Content.Add(paragraph); cell.OfficeValueType = "string"; cell.OfficeValue = text; table.InsertCellAt(i, j, cell); } } Chart basicChart = ChartBuilder.CreateChart(table, ChartTypes.line, "A4:F8"); ChartTitle ct = new ChartTitle(basicChart); //ct.InitTitle(); ct.SetTitle(expected); Assert.AreEqual(expected, ((Paragraph)ct.Content[0]).TextContent[0].Text); basicChart.ChartTitle = ct; IContent chartTitleContent = null; chartTitleContent=basicChart.Content.Find(o => o is ChartTitle); if (chartTitleContent == null) { foreach (IContent iContent in basicChart.Content) { if (iContent is ChartTitle) chartTitleContent = iContent; } } Assert.AreEqual(expected, ((Paragraph)((ChartTitle)chartTitleContent).Content[0]).TextContent[0].Text); table.InsertChartAt("H2", basicChart); doc.TableCollection.Add(table); doc.SaveTo(Path.Combine(AARunMeFirstAndOnce.outPutFolder,"BasicChartWithTitlesetafterwards.ods")); }