This project has moved and is read-only. For the latest updates, please go here.

Statistics sheet

The statistics sheet contains some data and graphs calculated from the content of the directory.
First we set the Top Header. It merges some cells and styles them...

            //Set the first header and format it
            ws.Cells["A1"].Value = header;
            using (ExcelRange r = ws.Cells["A1:N1"])
                r.Merge = true;
                r.Style.Font.SetFromFont(new Font("Arial", 22, FontStyle.Italic));
                r.Style.HorizontalAlignment = OfficeOpenXml.Style.ExcelHorizontalAlignment.CenterContinuous;
                r.Style.Fill.PatternType = OfficeOpenXml.Style.ExcelFillStyle.Solid;
                r.Style.Fill.BackgroundColor.SetColor(Color.FromArgb(23, 55, 93));

Then add the pie chart. You can add all charttypes except Bubble-, Radar-, Stock- or Surface charts. 

            //Add the piechart
            var pieChart = ws.Drawings.AddChart("crtExtensionsSize", eChartType.PieExploded3D) as ExcelPieChart;
            //Set top left corner to row 1 column 2
            pieChart.SetPosition(1, 0, 2, 0);
            pieChart.SetSize(400, 400);
            pieChart.Series.Add(ExcelRange.GetAddress(4, 2, row-1, 2), ExcelRange.GetAddress(4, 1, row-1, 1));

            pieChart.Title.Text = "Extension Size";
            //Set datalabels and remove the legend
            pieChart.DataLabel.ShowCategory = true;
            pieChart.DataLabel.ShowPercent = true;
            pieChart.DataLabel.ShowLeaderLines = true;

Check out sample 6 in the sample project for the full code.

Last edited Dec 23, 2010 at 8:37 AM by akronite, version 2