public static void SaveQuestionInfoExcel(ExcelQuestion excelQuestion, ExcelProfile excelProfile, ExcelDocument document, string filePath) { using (ExcelPackage excelPackage = new ExcelPackage()) { var questionInfo = ProccesingDataService.GetQuestionInfo(excelQuestion, excelProfile, document); var points = questionInfo.Item1; var respondedCount = questionInfo.Item2; var questionedCount = questionInfo.Item3; excelPackage.Workbook.Properties.Author = "User"; excelPackage.Workbook.Properties.Title = excelQuestion.GetForSeries(); excelPackage.Workbook.Properties.Created = DateTime.Now; ExcelWorksheet infoSheet = excelPackage.Workbook.Worksheets.Add("Результаты"); int rowInfoNumber = 1; infoSheet.Cells[rowInfoNumber, 1].Value = excelProfile.Name; rowInfoNumber++; int column = WriteRowExcel(new string[] { "Номер вопроса", "Вопрос", "Число ответивших", "Число прошедших" }, points.Keys.ToArray(), infoSheet, 1, rowInfoNumber); if (points.ContainsKey("другое")) { var questionOpenInfo = ProccesingDataService.GetOpenInfo(excelQuestion, excelProfile, document);; var openPoints = questionOpenInfo.Item1; WriteRowExcel(new string[] { }, openPoints.Keys.ToArray(), infoSheet, column, rowInfoNumber); } rowInfoNumber++; //----------------------------------------------- string[] pointsValue = points.Values.Select(x => x.ToString()).ToArray(); column = WriteRowExcel(new string[] { excelQuestion.Id.ToString(), excelQuestion.GetForSeries(), respondedCount.ToString(), questionedCount.ToString() }, pointsValue, infoSheet, 1, rowInfoNumber); if (points.ContainsKey("другое")) { var questionOpenInfo = ProccesingDataService.GetOpenInfo(excelQuestion, excelProfile, document);; var openPoints = questionOpenInfo.Item1; string[] openPointsValue = openPoints.Values.Select(x => x.ToString()).ToArray(); column = WriteRowExcel(new string[] { }, openPointsValue, infoSheet, column, rowInfoNumber); } infoSheet.Cells[infoSheet.Dimension.Address].AutoFitColumns(); infoSheet.Column(2).Width = 125; infoSheet.Column(2).Style.WrapText = true; FileInfo fi = new FileInfo(filePath); excelPackage.SaveAs(fi); } }
public static Chart CreateDefaultChart(Chart currentChart, Tuple <Dictionary <string, int>, int, int> questionInfo, ExcelQuestion excelQuestion, SeriesChartType seriesType, bool add = false) { string question = excelQuestion.GetForSeries(); Dictionary <string, int> points = questionInfo.Item1; int respondedCount = questionInfo.Item2; currentChart.Series.Add(question); currentChart.Series[question].ChartType = seriesType; currentChart.Series[question].Color = Form1.CompanyColor.Values.ToList()[0]; if (!add) { currentChart.Titles.Add(CommonService.CreateTitle("mainTitle", question)); currentChart.Titles.Add(CommonService.CreateTitle("allTitle", "Всего " + respondedCount + " ответивших участников")); } foreach (var item in points) { currentChart.Series[question].Points.AddXY(item.Key, item.Value); } if (currentChart.Series[question].ChartType == SeriesChartType.Pie || currentChart.Series[question].ChartType == SeriesChartType.Doughnut) { int colorIndex = 0; foreach (var item in currentChart.Series[question].Points) { if (item.YValues[0] == 0) { item.LabelForeColor = Color.Transparent; } item.Color = Form1.CompanyColor.Values.ToList()[colorIndex]; colorIndex++; } currentChart.Series[question].LabelForeColor = Color.White; } else { currentChart.Series[question].LabelForeColor = Color.Black; } if (!add) { Legend legend = CommonService.CreateLegend(currentChart.Series[question], "mainLegend"); currentChart.Legends.Add(legend); } return(currentChart); }