Example #1
0
        private void ProceedProductMonthCharts(Excel.Worksheet productSheet, SalesReportProduct itemProduct)
        {
            double chartTop    = productSheet.Rows[15].Top;
            double chartWidth  = productSheet.Columns[14].Left;
            double chartHeight = productSheet.Rows[30].Top - productSheet.Rows[15].Top;

            Excel.ChartObject chartMonths = productSheet.ChartObjects().Add(1, chartTop, chartWidth, chartHeight);
            chartMonths.Chart.SetSourceData(productSheet.get_Range("$A9:$M12"));

            chartTop    = productSheet.Rows[31].Top;
            chartWidth  = productSheet.Columns[14].Left;
            chartHeight = productSheet.Rows[40].Top - productSheet.Rows[33].Top;
            Excel.ChartObject chartCountMonths = productSheet.ChartObjects().Add(1, chartTop, chartWidth, chartHeight);
            chartCountMonths.Chart.ChartType = XlChartType.xlLine;
            chartCountMonths.Chart.SetSourceData(productSheet.get_Range("$A13:$M13"));

            double chartLeft = productSheet.Columns[15].Left;

            chartTop    = productSheet.Rows[15].Top;
            chartWidth  = productSheet.Columns[19].Left - productSheet.Columns[15].Left;
            chartHeight = productSheet.Rows[30].Top - productSheet.Rows[15].Top;
            Excel.ChartObject chartCountYears = productSheet.ChartObjects().Add(chartLeft, chartTop, chartWidth, chartHeight);
            chartCountYears.Chart.ChartType = XlChartType.xlCylinderColClustered;
            chartCountYears.Chart.SetSourceData(productSheet.get_Range("$O9:$P12"));
        }
Example #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            // start excel and turn off msg boxes
            _excelApplication = new Excel.Application();
            _excelApplication.DisplayAlerts = false;

            // add a new workbook
            Excel.Workbook  workBook  = _excelApplication.Workbooks.Add();
            Excel.Worksheet workSheet = workBook.Worksheets[1];

            // we need some data to display
            Excel.Range dataRange = PutSampleData(workSheet);

            // create a nice diagram
            Excel.ChartObject chart = workSheet.ChartObjects().Add(70, 100, 375, 225);
            chart.Chart.SetSourceData(dataRange);

            // save the book
            string fileExtension = GetDefaultExtension(_excelApplication);
            string workbookFile  = string.Format("{0}\\Example05{1}", Environment.CurrentDirectory, fileExtension);

            workBook.SaveAs(workbookFile);

            // close excel and dispose reference
            _excelApplication.Quit();
            _excelApplication.Dispose();

            FinishDialog fDialog = new FinishDialog("Workbook saved.", workbookFile);

            fDialog.ShowDialog(this);
        }
Example #3
0
        private void ProceedSummaryWorksheetCharts(Excel.Worksheet summarySheet, int countOfProducts)
        {
            string captionRangeAdress = "$A2:$" + Helper.ToCellAdress(1, 1 + countOfProducts);
            string fieldRangeAdress   = "$C2:$" + Helper.ToCellAdress(3, 1 + countOfProducts);

            double chartTopPosition = summarySheet.Rows[countOfProducts + 5].Top;
            double chartWidth       = summarySheet.Columns[13].Left;

            Excel.ChartObject chartSummary = summarySheet.ChartObjects().Add(1, chartTopPosition, chartWidth, 260);
            chartSummary.Chart.SetSourceData(summarySheet.get_Range(captionRangeAdress + ";" + fieldRangeAdress));

            fieldRangeAdress = "$D2:$" + Helper.ToCellAdress(4, 1 + countOfProducts);
            chartTopPosition = summarySheet.Rows[2].Top;
            double chartLeftPosition = summarySheet.Columns[8].Left;
            double chartHeight       = summarySheet.Rows[countOfProducts + 3].Top - chartTopPosition;

            chartWidth = summarySheet.Columns[13].Left - summarySheet.Columns[8].Left;

            Excel.ChartObject chartPercentOutcome = summarySheet.ChartObjects().Add(chartLeftPosition, chartTopPosition, chartWidth, chartHeight);
            chartPercentOutcome.Chart.ChartType = XlChartType.xlPie;
            chartPercentOutcome.Chart.SetSourceData(summarySheet.get_Range(captionRangeAdress + ";" + fieldRangeAdress));
        }