private static void WriteChart(XmlDocument dChart,ChartRenderingJob job)
        {
            XmlNamespaceManager nsMan = new XmlNamespaceManager(dChart.NameTable);
            foreach (XmlAttribute a in dChart.DocumentElement.Attributes)
            {
                if (a.Prefix == "xmlns")
                {
                    nsMan.AddNamespace(a.LocalName, a.Value);
                }
            }
            if (!string.IsNullOrWhiteSpace(job.Title))
            {
                // /c:chartSpace/c:chart/c:title/c:tx/c:rich/a:p/a:r
                dChart["c:chartSpace"]["c:chart"]["c:title"]["c:tx"]["c:rich"]["a:p"]["a:r"]["a:t"].InnerText = job.Title;
            }
            
            //write out the series, we make an assumption that there are enough defined (this is not going to be true

            var series = new Queue<XmlElement>(
                dChart.SelectNodes("/c:chartSpace/c:chart/c:plotArea/*/c:ser",nsMan).Cast<XmlElement>());
            
            foreach (var seriesJob in job.Series)
            {
                var seriesTemplate = series.Dequeue();
                
                UpdateLiteralValues(seriesTemplate["c:val"],seriesJob.Values);
                UpdateLiteralValues(seriesTemplate["c:cat"], job.CategoryHeadings);
            }
        }
 public static void RenderChart(ChartRenderingJob job, Stream input, Stream Output)
 {
     XmlDocument doc = new XmlDocument();
     
     doc.Load(input);
     WriteChart(doc,job);
     doc.Save(Output);
 }
            public static void Process( ZipFile zip, ChartRenderingJob chart)
            {
                TemporaryDataSource tds = new TemporaryDataSource(){ ms = new MemoryStream()};
                var currentEntry = zip.GetEntry(chart.TemplatePath);
                using( var input = zip.GetInputStream(currentEntry))
                {
                    ChartWriter.RenderChart(chart,input,tds.ms);
                }
                zip.BeginUpdate();
                zip.Add(tds, currentEntry.Name,currentEntry.CompressionMethod,currentEntry.IsUnicodeText);
                zip.CommitUpdate();

                
            }
Exemple #4
0
        static void Main(string[] args)
        {
            
            Random r = new Random();
           
            var seriesDefs = new List<ChartSeriesJob>();
            for (int i = 0; i < 4; i++)
            {
                

                string Name = "This is series " + i;
                var lValues = new List<string>();
                while (lValues.Count < 10)
                    lValues.Add(r.Next().ToString());

                seriesDefs.Add(new ChartSeriesJob()
                {
                    Name = Name,
                    Values = lValues
                });
               
            }
            var catHeadings = new List<string>();
            while (catHeadings.Count< 10)
                catHeadings.Add("Category " + catHeadings.Count);
           
            ChartRenderingJob job = new ChartRenderingJob(){
                TemplatePath = "xl/charts/chart1.xml",
                Title = "Hello World",
                Series = seriesDefs,
                CategoryHeadings = catHeadings};

            WorkbookJob bookjob = new WorkbookJob()
            {
                Path = "Workbook.xlsx",
                ChartJobs = new ChartRenderingJob[] { job }
            };

           WorkbookWriter.UpdateWorkbook(bookjob);
             
        }