コード例 #1
0
        private void builWorkBook(Xls.Workbook workBook, IEnumerable <ChartInfo> graphs)
        {
            Xls.Chart     graphTemplate     = workBook.Sheets[1];
            Xls.Worksheet dataSheet         = workBook.Sheets[2];
            int           chartsCounter     = 1;
            int           currentDataColumn = 1;

            try
            {
                foreach (var graph in graphs)
                {
                    int dataColumnsWritten;
                    graphTemplate.Copy(dataSheet);
                    workBook.Sheets[workBook.Sheets.Count - 1].Name = string.Format(Strings.ExcelChartSheetName, chartsCounter++);
                    buildXlsChart(workBook.Sheets[workBook.Sheets.Count - 1], dataSheet, graph, currentDataColumn, out dataColumnsWritten);
                    currentDataColumn += dataColumnsWritten;
                }

                graphTemplate.Delete();
            }
            finally
            {
                if (dataSheet != null)
                {
                    Marshal.FinalReleaseComObject(dataSheet);
                }

                Marshal.FinalReleaseComObject(graphTemplate);
            }
        }
コード例 #2
0
        private void ExportChart(Excel.Chart chart)
        {
            chart.Export($@"{destinationFolder}\{chartNumber} - {chart.ChartTitle.Text}.png", "PNG");
            chartNumber++;
            chart.Delete();

            ChartCreated?.Invoke(this, $"{chart.ChartTitle.Text} created");
        }