1 и 3 сданы, 2 чуток на переделку
This commit is contained in:
parent
230c2cb0c7
commit
f98f8af0ab
@ -13,10 +13,6 @@ namespace COPWinForms
|
||||
{
|
||||
private string _fileName;
|
||||
|
||||
// private WordprocessingDocument? _wordDocument;
|
||||
|
||||
// private Body? _docBody;
|
||||
|
||||
public string FileName
|
||||
{
|
||||
set
|
||||
|
@ -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; }
|
||||
}
|
||||
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
||||
//СДЕЛАТЬ ПРОВЕРКУ!!!!!!
|
||||
|
||||
}
|
||||
}
|
||||
|
14
COPWinForms/DiagramData.cs
Normal file
14
COPWinForms/DiagramData.cs
Normal file
@ -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;
|
||||
}
|
||||
}
|
@ -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<DiagramData> 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<DiagramData> diagramDatas, string[] category)
|
||||
{
|
||||
FilePath = filePath;
|
||||
DocumentTitle = documentTitle;
|
||||
ChartTitle = chartTitle;
|
||||
Categories = categories;
|
||||
SeriesName = seriesName;
|
||||
Data = data;
|
||||
LegendPosition = legendPosition;
|
||||
DiagramDatas = diagramDatas;
|
||||
Category = category;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -10,27 +10,19 @@ namespace COPWinForms
|
||||
public class TableWord
|
||||
{
|
||||
public string FilePath = string.Empty;
|
||||
|
||||
public string DocumentTitle = string.Empty;
|
||||
|
||||
public List<ColumnDefinition> ColumnDefinitions;
|
||||
public List<ColumnDefinition2> ColumnDefinitions2;
|
||||
|
||||
public List<ColumnDefinition> ColumnDefinitions2;
|
||||
public List<object> Data;
|
||||
|
||||
public List<int[]> MergedColumns;
|
||||
public List<int[]> MergedColumns2;
|
||||
public List<int> WeightColumn;
|
||||
public TableWord(string filePath, string documentTitle, List<ColumnDefinition> columnDefinitions, List<ColumnDefinition2> columnDefinitions2, List<object> data, List<int[]> mergedColumns, List<int[]> mergedColumns2, List<int> weightColumn)
|
||||
public TableWord(string filePath, string documentTitle, List<ColumnDefinition> columnDefinitions, List<ColumnDefinition> columnDefinitions2, List<object> data, List<int[]> mergedColumns)
|
||||
{
|
||||
FilePath = filePath;
|
||||
DocumentTitle = documentTitle;
|
||||
ColumnDefinitions = columnDefinitions;
|
||||
ColumnDefinitions2 = columnDefinitions2;
|
||||
Data = data;
|
||||
MergedColumns = mergedColumns;
|
||||
ColumnDefinitions2 = columnDefinitions2;
|
||||
MergedColumns2 = mergedColumns2;
|
||||
WeightColumn = weightColumn;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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> diagramData = new List<DiagramData>
|
||||
{
|
||||
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<int[]> mergedColumns2 = new()
|
||||
{
|
||||
//new int[] { 0, 1 } // Ïðèìåð îáúåäèíåíèÿ ñòîëáöîâ 0 è 1
|
||||
};
|
||||
|
||||
List<int> weightColumn = new() { 11, 11, 78};
|
||||
|
||||
|
||||
List<ColumnDefinition> columnDefinitions = new List<ColumnDefinition>
|
||||
{
|
||||
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<ColumnDefinition2> columnDefinitions2 = new List<ColumnDefinition2>
|
||||
List<ColumnDefinition> columnDefinitions2 = new List<ColumnDefinition>
|
||||
{
|
||||
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<object> data = new List<object>
|
||||
@ -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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user