diff --git a/COPWinForms/ComponentWord1.cs b/COPWinForms/ComponentWord1.cs index f77206d..09eb116 100644 --- a/COPWinForms/ComponentWord1.cs +++ b/COPWinForms/ComponentWord1.cs @@ -13,10 +13,6 @@ namespace COPWinForms { private string _fileName; - // private WordprocessingDocument? _wordDocument; - - // private Body? _docBody; - public string FileName { set diff --git a/COPWinForms/ComponentWord2.cs b/COPWinForms/ComponentWord2.cs index b617c26..93e364f 100644 --- a/COPWinForms/ComponentWord2.cs +++ b/COPWinForms/ComponentWord2.cs @@ -14,6 +14,22 @@ namespace COPWinForms { public partial class ComponentWord2 : Component { + private string _fileName; + public string FileName + { + set + { + if (string.IsNullOrEmpty(value)) + { + return; + } + if (!value.EndsWith(".docx")) + { + throw new ArgumentException("No docx file"); + } + _fileName = value; + } + } public ComponentWord2() { InitializeComponent(); @@ -150,12 +166,8 @@ namespace COPWinForms { public string Header { get; set; } public string PropertyName { get; set; } - } + public int Width { get; set; } - public class ColumnDefinition2 - { - public string Header { get; set; } - public string PropertyName { get; set; } } diff --git a/COPWinForms/ComponentWord3.cs b/COPWinForms/ComponentWord3.cs index 54f3f4b..9e144cf 100644 --- a/COPWinForms/ComponentWord3.cs +++ b/COPWinForms/ComponentWord3.cs @@ -5,6 +5,7 @@ using System.Collections.Generic; using System.ComponentModel; using System.Diagnostics; using Aspose.Words.Drawing; +using DocumentFormat.OpenXml.Office2010.Excel; namespace COPWinForms { @@ -41,18 +42,7 @@ namespace COPWinForms public void CreateLineChart(DiagramWord diagramWord) { - // Проверка наличия данных, названий серий и категорий - if (diagramWord.Data == null || diagramWord.SeriesName == null || diagramWord.Categories == null) - { - throw new ArgumentException("Data, series names, or categories are null"); - } - - // Проверка соответствия количества серий данных - if (diagramWord.SeriesName.Length != diagramWord.Data.Length) - { - throw new ArgumentException("Number of series names does not match the number of data series"); - } - // Проверка наличия заголовка диаграммы + // Проверка наличия заголовка, пути и названия диаграммы if (string.IsNullOrEmpty(diagramWord.ChartTitle) || string.IsNullOrEmpty(diagramWord.FilePath) || string.IsNullOrEmpty(diagramWord.DocumentTitle)) { throw new ArgumentException("Chart title is null or empty"); @@ -78,22 +68,20 @@ namespace COPWinForms title.Text = diagramWord.ChartTitle; ChartSeriesCollection seriesColl = chart.Series; - seriesColl.Clear(); // Очищаем существующие серии перед добавлением новых - - // Добавление данных в диаграмму - for (int i = 0; i < diagramWord.SeriesName.Length; i++) - { - seriesColl.Add(diagramWord.SeriesName[i], diagramWord.Categories, diagramWord.Data[i]); - } + seriesColl.Clear(); + // Создание и заполнение коллекции категорий + foreach (var diagramDatas in diagramWord.DiagramDatas) + { + seriesColl.Add(diagramDatas.Seria, diagramWord.Category, diagramDatas.Data); + } + + chart.Legend.Position = (Aspose.Words.Drawing.Charts.LegendPosition)diagramWord.LegendPosition; // Сохранение документа в файл document.Save(diagramWord.FilePath); } - - - //СДЕЛАТЬ ПРОВЕРКУ!!!!!! } } diff --git a/COPWinForms/DiagramData.cs b/COPWinForms/DiagramData.cs new file mode 100644 index 0000000..f82c71e --- /dev/null +++ b/COPWinForms/DiagramData.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace COPWinForms +{ + public class DiagramData + { + public string Seria = string.Empty; + public double[] Data; + } +} diff --git a/COPWinForms/DiagramWord.cs b/COPWinForms/DiagramWord.cs index e7487de..e298ec0 100644 --- a/COPWinForms/DiagramWord.cs +++ b/COPWinForms/DiagramWord.cs @@ -13,20 +13,19 @@ namespace COPWinForms public string DocumentTitle = string.Empty; public string ChartTitle = string.Empty; - public string[] Categories; - public string[] SeriesName; - public double[][] Data; + public LegendPosition LegendPosition; + public List DiagramDatas; + public string[] Category; - public DiagramWord(string filePath, string documentTitle, string chartTitle, string[] categories, string[] seriesName, double[][] data, LegendPosition legendPosition) + public DiagramWord(string filePath, string documentTitle, string chartTitle, LegendPosition legendPosition, List diagramDatas, string[] category) { FilePath = filePath; DocumentTitle = documentTitle; ChartTitle = chartTitle; - Categories = categories; - SeriesName = seriesName; - Data = data; LegendPosition = legendPosition; + DiagramDatas = diagramDatas; + Category = category; } } } diff --git a/COPWinForms/TableWord.cs b/COPWinForms/TableWord.cs index 259ad41..692b5d5 100644 --- a/COPWinForms/TableWord.cs +++ b/COPWinForms/TableWord.cs @@ -10,27 +10,19 @@ namespace COPWinForms public class TableWord { public string FilePath = string.Empty; - public string DocumentTitle = string.Empty; - public List ColumnDefinitions; - public List ColumnDefinitions2; - + public List ColumnDefinitions2; public List Data; - public List MergedColumns; - public List MergedColumns2; - public List WeightColumn; - public TableWord(string filePath, string documentTitle, List columnDefinitions, List columnDefinitions2, List data, List mergedColumns, List mergedColumns2, List weightColumn) + public TableWord(string filePath, string documentTitle, List columnDefinitions, List columnDefinitions2, List data, List mergedColumns) { FilePath = filePath; DocumentTitle = documentTitle; ColumnDefinitions = columnDefinitions; + ColumnDefinitions2 = columnDefinitions2; Data = data; MergedColumns = mergedColumns; - ColumnDefinitions2 = columnDefinitions2; - MergedColumns2 = mergedColumns2; - WeightColumn = weightColumn; } } } diff --git a/WinFormsTest/FormTestApp.cs b/WinFormsTest/FormTestApp.cs index 21915c6..61f4016 100644 --- a/WinFormsTest/FormTestApp.cs +++ b/WinFormsTest/FormTestApp.cs @@ -119,12 +119,13 @@ namespace WinFormsTest private void button2_Click(object sender, EventArgs e) { ComponentWord3 chartComponent = new ComponentWord3(); - string[] categories = new string[] { "Category1", "Category2", "Category3" }; - string[] seriesName = new string[] { "Series1", "Series2" }; - double[][] data = new double[][] + string[] categories = new string[] { "Category1", "Category2"}; + + List diagramData = new List { - new double[] { 10, 20, 30 }, - new double[] { 15, 25, 35 } + new DiagramData { Seria = "Seria1", Data = new double[]{ 1, 20}}, + new DiagramData { Seria = "Seria2", Data = new double[]{ 10, 17}}, + new DiagramData { Seria = "Seria3", Data = new double[]{ 12, 14}} }; // using var dialog = new SaveFileDialog @@ -135,7 +136,7 @@ namespace WinFormsTest { try { - DiagramWord diagramWord = new(dialog.FileName, " 3", " ", categories, seriesName, data, LegendPosition.Right); + DiagramWord diagramWord = new(dialog.FileName, " 3", " ", LegendPosition.Right, diagramData, categories); componentWord31.CreateLineChart(diagramWord); MessageBox.Show(" ", "", MessageBoxButtons.OK, MessageBoxIcon.Information); } @@ -153,26 +154,20 @@ namespace WinFormsTest { new int[] { 0, 1 } // 0 1 }; - List mergedColumns2 = new() - { - //new int[] { 0, 1 } // 0 1 - }; - - List weightColumn = new() { 11, 11, 78}; List columnDefinitions = new List { - new ColumnDefinition { Header = " ", PropertyName = "PersonalData" }, - new ColumnDefinition { Header = "", PropertyName = "PersonalData1" }, - new ColumnDefinition { Header = "Group", PropertyName = "Group" } + new ColumnDefinition { Header = " ", PropertyName = "PersonalData", Width = 11 }, + new ColumnDefinition { Header = "", PropertyName = "PersonalData1", Width = 70 }, + new ColumnDefinition { Header = "Group", PropertyName = "Group", Width = 21 } }; - List columnDefinitions2 = new List + List columnDefinitions2 = new List { - new ColumnDefinition2 { Header = "FIO", PropertyName = "FIO" }, - new ColumnDefinition2 { Header = "Email", PropertyName = "Email" }, - new ColumnDefinition2 { Header = "Group", PropertyName = "Group" } + new ColumnDefinition { Header = "FIO", PropertyName = "FIO", Width = 11 }, + new ColumnDefinition { Header = "Email", PropertyName = "Email", Width = 70 }, + new ColumnDefinition { Header = "Group", PropertyName = "Group", Width = 21 } }; List data = new List @@ -191,8 +186,7 @@ namespace WinFormsTest { try { - TableWord tableWord = new(dialog.FileName, " 2", columnDefinitions, columnDefinitions2, data, mergedColumns, mergedColumns2, weightColumn); - tableWord.WeightColumn = weightColumn; + TableWord tableWord = new(dialog.FileName, " 2", columnDefinitions, columnDefinitions2, data, mergedColumns); componentWord21.CreateTable(tableWord); MessageBox.Show(" ", "", MessageBoxButtons.OK, MessageBoxIcon.Information); }