Вроде третий компонент.

This commit is contained in:
ElEgEv 2023-10-06 21:29:34 +04:00
parent 74c7c849f2
commit f1dbb5e420
9 changed files with 238 additions and 13 deletions

View File

@ -32,12 +32,16 @@
componentWord = new VisualComponentsLib.Components.ComponentWord(components);
buttonFirstTask = new Button();
groupBox1 = new GroupBox();
groupBox2 = new GroupBox();
buttonThirdTask = new Button();
componentWordHistogram = new VisualComponentsLib.Components.ComponentWordHistogram(components);
groupBox1.SuspendLayout();
groupBox2.SuspendLayout();
SuspendLayout();
//
// buttonFirstTask
//
buttonFirstTask.Location = new Point(55, 40);
buttonFirstTask.Location = new Point(22, 32);
buttonFirstTask.Name = "buttonFirstTask";
buttonFirstTask.Size = new Size(75, 23);
buttonFirstTask.TabIndex = 0;
@ -48,22 +52,44 @@
// groupBox1
//
groupBox1.Controls.Add(buttonFirstTask);
groupBox1.Location = new Point(45, 12);
groupBox1.Location = new Point(12, 12);
groupBox1.Name = "groupBox1";
groupBox1.Size = new Size(200, 100);
groupBox1.Size = new Size(120, 79);
groupBox1.TabIndex = 1;
groupBox1.TabStop = false;
groupBox1.Text = "Простая таблица";
//
// groupBox2
//
groupBox2.Controls.Add(buttonThirdTask);
groupBox2.Location = new Point(154, 12);
groupBox2.Name = "groupBox2";
groupBox2.Size = new Size(129, 79);
groupBox2.TabIndex = 2;
groupBox2.TabStop = false;
groupBox2.Text = "Третье задание";
//
// buttonThirdTask
//
buttonThirdTask.Location = new Point(27, 32);
buttonThirdTask.Name = "buttonThirdTask";
buttonThirdTask.Size = new Size(75, 23);
buttonThirdTask.TabIndex = 0;
buttonThirdTask.Text = "Создать";
buttonThirdTask.UseVisualStyleBackColor = true;
buttonThirdTask.Click += ButtonThirdTask_Click;
//
// FormWord
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(295, 123);
ClientSize = new Size(295, 103);
Controls.Add(groupBox2);
Controls.Add(groupBox1);
Name = "FormWord";
Text = "Невизуальные компоненты";
groupBox1.ResumeLayout(false);
groupBox2.ResumeLayout(false);
ResumeLayout(false);
}
@ -72,5 +98,8 @@
private VisualComponentsLib.Components.ComponentWord componentWord;
private Button buttonFirstTask;
private GroupBox groupBox1;
private GroupBox groupBox2;
private Button buttonThirdTask;
private VisualComponentsLib.Components.ComponentWordHistogram componentWordHistogram;
}
}

View File

@ -8,13 +8,14 @@ using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using VisualComponentsLib.Components.SupportClasses;
using VisualComponentsLib.Components.SupportClasses.Enums;
using static System.Windows.Forms.VisualStyles.VisualStyleElement.Window;
namespace VisualComponentsForm
{
public partial class FormWord : Form
{
SimpleTable simpleTable;
SimpleTable table;
string[,] first = {
{ "Первый", "Второй" }
@ -28,6 +29,8 @@ namespace VisualComponentsForm
{ "Пятый", "Шестой" }
};
SimpleHistogram histogram;
public FormWord()
{
InitializeComponent();
@ -45,9 +48,37 @@ namespace VisualComponentsForm
{
try
{
simpleTable = new(dialog.FileName, "Первое задание", new List<string[,]> { first, second, third });
table = new(dialog.FileName, "Первое задание", new List<string[,]> { first, second, third });
componentWord.CreateDoc(simpleTable);
componentWord.CreateDoc(table);
MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
private void ButtonThirdTask_Click(object sender, EventArgs e)
{
//фильтрация файлов для диалогового окна
using var dialog = new SaveFileDialog
{
Filter = "docx|*.docx"
};
if (dialog.ShowDialog() == DialogResult.OK)
{
try
{
histogram = new(dialog.FileName, "Третье задание", "Гистограмма", EnumAreaLegend.Right, new List<DataHistogram> {
new DataHistogram("Доход", "Январь", "300"), new DataHistogram("Доход", "Апрель", "600"),
new DataHistogram("Доход", "Июль", "400"), new DataHistogram("Доход", "Октябрь", "200")
});
componentWordHistogram.AddHistogram(histogram);
MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information);
}

View File

@ -120,4 +120,7 @@
<metadata name="componentWord.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
<metadata name="componentWordHistogram.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>162, 17</value>
</metadata>
</root>

View File

@ -8,6 +8,10 @@
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Aspose.Words" Version="23.10.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\VisualComponentsLib\VisualComponentsLib.csproj" />
</ItemGroup>

View File

@ -1,10 +1,9 @@
using System;
using System.Collections.Generic;
using Aspose.Words;
using Aspose.Words.Drawing;
using Aspose.Words.Drawing.Charts;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using VisualComponentsLib.Components.SupportClasses;
namespace VisualComponentsLib.Components
{
@ -21,5 +20,85 @@ namespace VisualComponentsLib.Components
InitializeComponent();
}
//создание таблицы
public void AddHistogram(SimpleHistogram simpleHistogram)
{
if (!CheckData(simpleHistogram.DataList))
{
throw new Exception("Не данные заполнены");
}
// Initialize document
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Specify font formatting
Aspose.Words.Font font = builder.Font;
font.Size = 24;
font.Bold = true;
font.Color = System.Drawing.Color.Black;
font.Name = "Times New Roman";
// Specify paragraph formatting
ParagraphFormat paragraphFormat = builder.ParagraphFormat;
paragraphFormat.FirstLineIndent = 8;
paragraphFormat.SpaceAfter = 24;
paragraphFormat.Alignment = ParagraphAlignment.Center;
paragraphFormat.KeepTogether = true;
builder.Writeln(simpleHistogram.FileName);
// Добавьте диаграмму с данными по умолчанию. Вы можете указать различные типы и размеры диаграмм.
Shape shape = builder.InsertChart(ChartType.Column, 500, 270);
// Свойство диаграммы формы содержит все параметры, связанные с диаграммой.
Chart chart = shape.Chart;
chart.Title.Text = simpleHistogram.HistogramName;
// Получите коллекцию серий диаграмм.
ChartSeriesCollection seriesColl = chart.Series;
// Проверьте количество серий.
Console.WriteLine(seriesColl.Count);
// Удалить серию, сгенерированную по умолчанию.
seriesColl.Clear();
// Создайте массив имен категорий
string[] categories = new string[] { simpleHistogram.DataList[0].NameSeries };
// Добавление новых серий. Обратите внимание, что массивы данных не должны быть пустыми, а массивы должны быть одного размера.
foreach (var data in simpleHistogram.DataList)
{
seriesColl.Add(data.NameData, categories, new double[] { double.Parse(data.Data) });
}
// Move the chart's legend to the top right corner.
ChartLegend legend = chart.Legend;
legend.Position = (LegendPosition)simpleHistogram.AreaLegend;
// Give other chart elements, such as the graph, more room by allowing them to overlap the legend.
legend.Overlay = true;
// Сохраните документ
doc.Save(simpleHistogram.FilePath);
}
//проверка заполненности входных значений
static bool CheckData(List<DataHistogram> data)
{
foreach (var _data in data)
{
if(string.IsNullOrEmpty(_data.NameSeries) || string.IsNullOrEmpty(_data.Data))
{
return false;
}
}
return true;
}
}
}

View File

@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace VisualComponentsLib.Components.SupportClasses
{
public class DataHistogram
{
public string NameSeries { get; set; } = string.Empty;
public string NameData { get; set; } = string.Empty;
public string Data { get; set; } = string.Empty;
public DataHistogram(string nameSeries, string nameData, string data)
{
NameSeries = nameSeries;
NameData = nameData;
Data = data;
}
}
}

View File

@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace VisualComponentsLib.Components.SupportClasses.Enums
{
public enum EnumAreaLegend
{
None,
Left,
Top,
Right,
Bottom,
TopRight,
}
}

View File

@ -0,0 +1,31 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using VisualComponentsLib.Components.SupportClasses.Enums;
namespace VisualComponentsLib.Components.SupportClasses
{
public class SimpleHistogram
{
public string FilePath = string.Empty;
public string FileName = string.Empty;
public string HistogramName = string.Empty;
public EnumAreaLegend AreaLegend;
public List<DataHistogram> DataList = new();
public SimpleHistogram(string filePath, string fileName, string histogramName, EnumAreaLegend areaLegend, List<DataHistogram> dataList)
{
FilePath = filePath;
FileName = fileName;
HistogramName = histogramName;
AreaLegend = areaLegend;
DataList = dataList;
}
}
}

View File

@ -9,6 +9,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Aspose.Words" Version="23.10.0" />
<PackageReference Include="DocumentFormat.OpenXml" Version="2.20.0" />
<PackageReference Include="FreeSpire.Doc" Version="11.6.0" />
</ItemGroup>