Не работают картинки.
This commit is contained in:
parent
2bfe317437
commit
4a5e7f9c0d
36
WinFormsProject/WinFormsLibrary/CircleDiagram.Designer.cs
generated
Normal file
36
WinFormsProject/WinFormsLibrary/CircleDiagram.Designer.cs
generated
Normal file
@ -0,0 +1,36 @@
|
||||
namespace WinFormsLibrary
|
||||
{
|
||||
partial class CircleDiagram
|
||||
{
|
||||
/// <summary>
|
||||
/// Обязательная переменная конструктора.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Освободить все используемые ресурсы.
|
||||
/// </summary>
|
||||
/// <param name="disposing">истинно, если управляемый ресурс должен быть удален; иначе ложно.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Код, автоматически созданный конструктором компонентов
|
||||
|
||||
/// <summary>
|
||||
/// Требуемый метод для поддержки конструктора — не изменяйте
|
||||
/// содержимое этого метода с помощью редактора кода.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
components = new System.ComponentModel.Container();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
93
WinFormsProject/WinFormsLibrary/CircleDiagram.cs
Normal file
93
WinFormsProject/WinFormsLibrary/CircleDiagram.cs
Normal file
@ -0,0 +1,93 @@
|
||||
using Aspose.Words.Drawing.Charts;
|
||||
using Aspose.Words;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using WinFormsLibrary.SupportClasses;
|
||||
using Aspose.Words.Drawing;
|
||||
|
||||
namespace WinFormsLibrary
|
||||
{
|
||||
public partial class CircleDiagram : Component
|
||||
{
|
||||
public CircleDiagram()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
public CircleDiagram(IContainer container)
|
||||
{
|
||||
container.Add(this);
|
||||
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
public void AddCircleDiagram(SimpleCircleDiagram simpleCircleDiagram)
|
||||
{
|
||||
if (!CheckData(simpleCircleDiagram.DataList))
|
||||
{
|
||||
throw new Exception("Данные не заполнены");
|
||||
}
|
||||
|
||||
Document doc = new Document();
|
||||
DocumentBuilder builder = new DocumentBuilder(doc);
|
||||
|
||||
Aspose.Words.Font font = builder.Font;
|
||||
font.Size = 24;
|
||||
font.Bold = true;
|
||||
font.Color = Color.Black;
|
||||
font.Name = "Times New Roman";
|
||||
|
||||
ParagraphFormat paragraphFormat = builder.ParagraphFormat;
|
||||
paragraphFormat.FirstLineIndent = 8;
|
||||
paragraphFormat.SpaceAfter = 24;
|
||||
paragraphFormat.Alignment = ParagraphAlignment.Center;
|
||||
paragraphFormat.KeepTogether = true;
|
||||
|
||||
builder.Writeln(simpleCircleDiagram.FileHeader);
|
||||
|
||||
Shape shape = builder.InsertChart(ChartType.Pie, 500, 270);
|
||||
|
||||
Chart chart = shape.Chart;
|
||||
|
||||
chart.Title.Text = simpleCircleDiagram.CircleDiagramName;
|
||||
|
||||
ChartSeries series = chart.Series[0];
|
||||
|
||||
ChartSeriesCollection seriesColl = chart.Series;
|
||||
|
||||
Console.WriteLine(seriesColl.Count);
|
||||
|
||||
seriesColl.Clear();
|
||||
|
||||
foreach (var data in simpleCircleDiagram.DataList)
|
||||
{
|
||||
seriesColl.Add(data.NameSeries, data.NameData, data.Data);
|
||||
}
|
||||
|
||||
ChartLegend legend = chart.Legend;
|
||||
|
||||
legend.Position = (LegendPosition)simpleCircleDiagram.AreaLegend;
|
||||
|
||||
legend.Overlay = true;
|
||||
|
||||
doc.Save(simpleCircleDiagram.FilePath);
|
||||
}
|
||||
|
||||
static bool CheckData(List<DataCircleDiagram> data)
|
||||
{
|
||||
foreach (var _data in data)
|
||||
{
|
||||
if (string.IsNullOrEmpty(_data.NameData.ToString()) || string.IsNullOrEmpty(_data.Data.ToString()))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
36
WinFormsProject/WinFormsLibrary/DocumentWithImage.Designer.cs
generated
Normal file
36
WinFormsProject/WinFormsLibrary/DocumentWithImage.Designer.cs
generated
Normal file
@ -0,0 +1,36 @@
|
||||
namespace WinFormsLibrary
|
||||
{
|
||||
partial class DocumentWithImage
|
||||
{
|
||||
/// <summary>
|
||||
/// Обязательная переменная конструктора.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Освободить все используемые ресурсы.
|
||||
/// </summary>
|
||||
/// <param name="disposing">истинно, если управляемый ресурс должен быть удален; иначе ложно.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Код, автоматически созданный конструктором компонентов
|
||||
|
||||
/// <summary>
|
||||
/// Требуемый метод для поддержки конструктора — не изменяйте
|
||||
/// содержимое этого метода с помощью редактора кода.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
components = new System.ComponentModel.Container();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
151
WinFormsProject/WinFormsLibrary/DocumentWithImage.cs
Normal file
151
WinFormsProject/WinFormsLibrary/DocumentWithImage.cs
Normal file
@ -0,0 +1,151 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using DocumentFormat.OpenXml;
|
||||
using DocumentFormat.OpenXml.Drawing;
|
||||
using DocumentFormat.OpenXml.Packaging;
|
||||
using DocumentFormat.OpenXml.Wordprocessing;
|
||||
using A = DocumentFormat.OpenXml.Drawing;
|
||||
using DW = DocumentFormat.OpenXml.Drawing.Wordprocessing;
|
||||
using PIC = DocumentFormat.OpenXml.Drawing.Pictures;
|
||||
using Paragraph = DocumentFormat.OpenXml.Wordprocessing.Paragraph;
|
||||
using Text = DocumentFormat.OpenXml.Wordprocessing.Text;
|
||||
using Run = DocumentFormat.OpenXml.Wordprocessing.Run;
|
||||
using WinFormsLibrary.SupportClasses;
|
||||
|
||||
namespace WinFormsLibrary
|
||||
{
|
||||
public partial class DocumentWithImage : Component
|
||||
{
|
||||
private WordprocessingDocument? _wordDocument;
|
||||
|
||||
private Body? _docBody;
|
||||
|
||||
public DocumentWithImage()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
public DocumentWithImage(IContainer container)
|
||||
{
|
||||
container.Add(this);
|
||||
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
public void CreateDocument(ImageClass imageClass)
|
||||
{
|
||||
// Проверка наличия данных
|
||||
if (string.IsNullOrEmpty(imageClass.Path) || string.IsNullOrEmpty(imageClass.Title) || imageClass.Files.Count == 0)
|
||||
{
|
||||
throw new Exception("Не все данные заполнены");
|
||||
}
|
||||
|
||||
// Создаем Word-документ
|
||||
using (WordprocessingDocument wordDocument = WordprocessingDocument.Create(imageClass.Path, WordprocessingDocumentType.Document))
|
||||
{
|
||||
MainDocumentPart mainPart = wordDocument.AddMainDocumentPart();
|
||||
mainPart.Document = new Document();
|
||||
Body body = new Body();
|
||||
|
||||
// Добавляем заголовок
|
||||
Paragraph titleParagraph = new Paragraph(new Run(new Text(imageClass.Title)));
|
||||
body.Append(titleParagraph);
|
||||
|
||||
// Добавляем изображения
|
||||
foreach (string imagePath in imageClass.Files)
|
||||
{
|
||||
if (File.Exists(imagePath))
|
||||
{
|
||||
ImagePart imagePart = mainPart.AddImagePart(ImagePartType.Jpeg);
|
||||
using (FileStream stream = new FileStream(imagePath, FileMode.Open))
|
||||
{
|
||||
imagePart.FeedData(stream);
|
||||
}
|
||||
|
||||
AddImageToBody(wordDocument, mainPart.GetIdOfPart(imagePart));
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine($"Изображение '{imagePath}' не найдено.");
|
||||
}
|
||||
}
|
||||
|
||||
mainPart.Document.Append(body);
|
||||
Console.WriteLine($"Word-документ успешно создан в файле '{imageClass.Path}'.");
|
||||
}
|
||||
}
|
||||
|
||||
private void AddImageToBody(WordprocessingDocument wordDoc, string relationshipId)
|
||||
{
|
||||
var element =
|
||||
new Drawing(
|
||||
new DW.Inline(
|
||||
new DW.Extent() { Cx = 990000L, Cy = 792000L },
|
||||
new DW.EffectExtent()
|
||||
{
|
||||
LeftEdge = 0L,
|
||||
TopEdge = 0L,
|
||||
RightEdge = 0L,
|
||||
BottomEdge = 0L
|
||||
},
|
||||
new DW.DocProperties()
|
||||
{
|
||||
Id = (UInt32Value)1U,
|
||||
Name = "Picture 1"
|
||||
},
|
||||
new DW.NonVisualGraphicFrameDrawingProperties(
|
||||
new A.GraphicFrameLocks() { NoChangeAspect = true }),
|
||||
new A.Graphic(
|
||||
new A.GraphicData(
|
||||
new PIC.Picture(
|
||||
new PIC.NonVisualPictureProperties(
|
||||
new PIC.NonVisualDrawingProperties()
|
||||
{
|
||||
Id = (UInt32Value)0U,
|
||||
Name = "New Bitmap Image.jpg"
|
||||
},
|
||||
new PIC.NonVisualPictureDrawingProperties()),
|
||||
new PIC.BlipFill(
|
||||
new A.Blip(
|
||||
new A.BlipExtensionList(
|
||||
new A.BlipExtension()
|
||||
{
|
||||
Uri =
|
||||
"{28A0092B-C50C-407E-A947-70E740481C1C}"
|
||||
})
|
||||
)
|
||||
{
|
||||
Embed = relationshipId,
|
||||
CompressionState =
|
||||
A.BlipCompressionValues.Print
|
||||
},
|
||||
new A.Stretch(
|
||||
new A.FillRectangle())),
|
||||
new PIC.ShapeProperties(
|
||||
new A.Transform2D(
|
||||
new A.Offset() { X = 0L, Y = 0L },
|
||||
new A.Extents() { Cx = 990000L, Cy = 792000L }),
|
||||
new A.PresetGeometry(
|
||||
new A.AdjustValueList()
|
||||
) { Preset = A.ShapeTypeValues.Rectangle }))
|
||||
) { Uri = "http://schemas.openxmlformats.org/drawingml/2006/picture" })
|
||||
)
|
||||
{
|
||||
DistanceFromTop = (UInt32Value)0U,
|
||||
DistanceFromBottom = (UInt32Value)0U,
|
||||
DistanceFromLeft = (UInt32Value)0U,
|
||||
DistanceFromRight = (UInt32Value)0U,
|
||||
EditId = "50D07946"
|
||||
});
|
||||
|
||||
// Append the reference to the body. The element should be in
|
||||
// a DocumentFormat.OpenXml.Wordprocessing.Run.
|
||||
wordDoc.MainDocumentPart.Document.Body.AppendChild(new Paragraph(new Run(element)));
|
||||
}
|
||||
}
|
||||
}
|
31
WinFormsProject/WinFormsLibrary/SupportClasses/BigTable.cs
Normal file
31
WinFormsProject/WinFormsLibrary/SupportClasses/BigTable.cs
Normal file
@ -0,0 +1,31 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace WinFormsLibrary.SupportClasses
|
||||
{
|
||||
public class BigTable<T>
|
||||
{
|
||||
public string FilePath = string.Empty;
|
||||
|
||||
public string DocumentTitle = string.Empty;
|
||||
|
||||
public List<ColumnDefinition> ColumnDefinitions;
|
||||
public List<ColumnDefinition> ColumnDefinitions2;
|
||||
|
||||
public List<T> Data;
|
||||
|
||||
public List<int[]> MergedColumns;
|
||||
public BigTable(string filePath, string documentTitle, List<ColumnDefinition> columnDefinitions, List<ColumnDefinition> columnDefinitions2, List<T> data, List<int[]> mergedColumns)
|
||||
{
|
||||
FilePath = filePath;
|
||||
DocumentTitle = documentTitle;
|
||||
ColumnDefinitions = columnDefinitions;
|
||||
Data = data;
|
||||
MergedColumns = mergedColumns;
|
||||
ColumnDefinitions2 = columnDefinitions2;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace WinFormsLibrary.SupportClasses
|
||||
{
|
||||
public class ColumnDefinition
|
||||
{
|
||||
public string Header;
|
||||
public string PropertyName;
|
||||
public double Weight;
|
||||
}
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace WinFormsLibrary.SupportClasses
|
||||
{
|
||||
public class DataCircleDiagram
|
||||
{
|
||||
public string NameSeries { get; set; } = string.Empty;
|
||||
public string[] NameData { get; set; }
|
||||
public double[] Data { get; set; }
|
||||
|
||||
public DataCircleDiagram(string nameSeries, string[] nameData, double[] data)
|
||||
{
|
||||
NameSeries = nameSeries;
|
||||
NameData = nameData;
|
||||
Data = data;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace WinFormsLibrary.SupportClasses.Enums
|
||||
{
|
||||
public enum EnumAreaLegend
|
||||
{
|
||||
None,
|
||||
|
||||
Left,
|
||||
|
||||
Top,
|
||||
|
||||
Right,
|
||||
|
||||
Bottom,
|
||||
|
||||
TopRight
|
||||
}
|
||||
}
|
26
WinFormsProject/WinFormsLibrary/SupportClasses/ImageClass.cs
Normal file
26
WinFormsProject/WinFormsLibrary/SupportClasses/ImageClass.cs
Normal file
@ -0,0 +1,26 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace WinFormsLibrary.SupportClasses
|
||||
{
|
||||
public class ImageClass
|
||||
{
|
||||
private string path;
|
||||
private string title;
|
||||
private List<string> files;
|
||||
public string Path { get { return path; } set { path = value; } }
|
||||
public string Title { get { return title; } set { title = value; } }
|
||||
public List<string> Files { get { return files; } set { files = value; } }
|
||||
public ImageClass() { }
|
||||
|
||||
public ImageClass(string filePath, string documentTitle, List<string> textData)
|
||||
{
|
||||
Path = filePath;
|
||||
Title = documentTitle;
|
||||
Files = textData;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using WinFormsLibrary.SupportClasses.Enums;
|
||||
|
||||
namespace WinFormsLibrary.SupportClasses
|
||||
{
|
||||
public class SimpleCircleDiagram
|
||||
{
|
||||
public string FileHeader { get; set; } = string.Empty;
|
||||
public string CircleDiagramName { get; set; } = string.Empty;
|
||||
public List<DataCircleDiagram> DataList { get; set; } = new();
|
||||
public string FilePath { get; set; } = string.Empty;
|
||||
public EnumAreaLegend AreaLegend { get; set; }
|
||||
|
||||
public SimpleCircleDiagram(string filePath, string fileHeader, string circleDiagramName, EnumAreaLegend areaLegend, List<DataCircleDiagram> dataList)
|
||||
{
|
||||
FilePath = filePath;
|
||||
FileHeader = fileHeader;
|
||||
CircleDiagramName = circleDiagramName;
|
||||
AreaLegend = areaLegend;
|
||||
DataList = dataList;
|
||||
}
|
||||
}
|
||||
}
|
27
WinFormsProject/WinFormsLibrary/SupportClasses/Student.cs
Normal file
27
WinFormsProject/WinFormsLibrary/SupportClasses/Student.cs
Normal file
@ -0,0 +1,27 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace WinFormsLibrary.SupportClasses
|
||||
{
|
||||
public class Student
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public string Group { get; set; }
|
||||
public string Faculty { get; set; }
|
||||
public int Course { get; set; }
|
||||
|
||||
public Student(string name, string group, string faculty, int course)
|
||||
{
|
||||
Name = name;
|
||||
Group = group;
|
||||
Faculty = faculty;
|
||||
Course = course;
|
||||
}
|
||||
public Student()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
36
WinFormsProject/WinFormsLibrary/Table2column.Designer.cs
generated
Normal file
36
WinFormsProject/WinFormsLibrary/Table2column.Designer.cs
generated
Normal file
@ -0,0 +1,36 @@
|
||||
namespace WinFormsLibrary
|
||||
{
|
||||
partial class Table2column
|
||||
{
|
||||
/// <summary>
|
||||
/// Обязательная переменная конструктора.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Освободить все используемые ресурсы.
|
||||
/// </summary>
|
||||
/// <param name="disposing">истинно, если управляемый ресурс должен быть удален; иначе ложно.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Код, автоматически созданный конструктором компонентов
|
||||
|
||||
/// <summary>
|
||||
/// Требуемый метод для поддержки конструктора — не изменяйте
|
||||
/// содержимое этого метода с помощью редактора кода.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
components = new System.ComponentModel.Container();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
134
WinFormsProject/WinFormsLibrary/Table2column.cs
Normal file
134
WinFormsProject/WinFormsLibrary/Table2column.cs
Normal file
@ -0,0 +1,134 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Aspose.Words;
|
||||
using Aspose.Words.Tables;
|
||||
using WinFormsLibrary.SupportClasses;
|
||||
|
||||
namespace WinFormsLibrary
|
||||
{
|
||||
public partial class Table2column : Component
|
||||
{
|
||||
public Table2column()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
public Table2column(IContainer container)
|
||||
{
|
||||
container.Add(this);
|
||||
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
public void CreateTable<T>(BigTable<T> bigTable)
|
||||
{
|
||||
if (bigTable.Data == null)
|
||||
{
|
||||
throw new ArgumentException("Не заданы все данные");
|
||||
}
|
||||
|
||||
foreach (var columnDefinition in bigTable.ColumnDefinitions)
|
||||
{
|
||||
if (string.IsNullOrEmpty(columnDefinition.PropertyName))
|
||||
{
|
||||
throw new ArgumentException($"Не задано свойство столбца: {columnDefinition.Header}");
|
||||
}
|
||||
}
|
||||
|
||||
Document document = new Document();
|
||||
DocumentBuilder builder = new DocumentBuilder(document);
|
||||
|
||||
Style titleStyle = builder.Document.Styles.Add(StyleType.Paragraph, "Title");
|
||||
titleStyle.Font.Size = 16;
|
||||
titleStyle.Font.Bold = true;
|
||||
|
||||
builder.ParagraphFormat.Style = titleStyle;
|
||||
builder.Writeln(bigTable.DocumentTitle);
|
||||
|
||||
Table table = builder.StartTable();
|
||||
|
||||
|
||||
foreach (var columnDefinition in bigTable.ColumnDefinitions)
|
||||
{
|
||||
builder.InsertCell();
|
||||
builder.CellFormat.PreferredWidth = PreferredWidth.FromPoints(columnDefinition.Weight);
|
||||
builder.ParagraphFormat.Alignment = ParagraphAlignment.Center;
|
||||
builder.CellFormat.VerticalAlignment = CellVerticalAlignment.Center;
|
||||
builder.Write(columnDefinition.Header);
|
||||
}
|
||||
|
||||
foreach (var mergedColumn in bigTable.MergedColumns)
|
||||
{
|
||||
int startCellIndex = mergedColumn[0];
|
||||
int endCellIndex = mergedColumn[mergedColumn.Length - 1];
|
||||
|
||||
for (int i = startCellIndex; i <= endCellIndex; i++)
|
||||
{
|
||||
table.Rows[0].Cells[i].CellFormat.HorizontalMerge = CellMerge.First;
|
||||
table.Rows[0].Cells[i].CellFormat.VerticalMerge = CellMerge.First;
|
||||
}
|
||||
|
||||
for (int i = startCellIndex + 1; i <= endCellIndex; i++)
|
||||
{
|
||||
table.Rows[0].Cells[i].CellFormat.HorizontalMerge = CellMerge.Previous;
|
||||
table.Rows[0].Cells[i].CellFormat.VerticalMerge = CellMerge.First;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
builder.EndRow();
|
||||
|
||||
foreach (var columnDefinition2 in bigTable.ColumnDefinitions2)
|
||||
{
|
||||
builder.InsertCell();
|
||||
builder.CellFormat.PreferredWidth = PreferredWidth.FromPoints(columnDefinition2.Weight);
|
||||
builder.Write(columnDefinition2.Header);
|
||||
}
|
||||
|
||||
builder.EndRow();
|
||||
|
||||
int columnIndex;
|
||||
foreach (var columnDefinition in bigTable.ColumnDefinitions)
|
||||
{
|
||||
string currentPropertyName = columnDefinition.PropertyName;
|
||||
columnIndex = 0;
|
||||
foreach (var columnDefinition2 in bigTable.ColumnDefinitions2)
|
||||
{
|
||||
string currentPropertyName1 = columnDefinition2.PropertyName;
|
||||
|
||||
if (currentPropertyName == currentPropertyName1)
|
||||
{
|
||||
table.Rows[0].Cells[columnIndex].CellFormat.VerticalMerge = CellMerge.First;
|
||||
table.Rows[1].Cells[columnIndex].CellFormat.VerticalMerge = CellMerge.Previous;
|
||||
|
||||
}
|
||||
columnIndex++;
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var item in bigTable.Data)
|
||||
{
|
||||
foreach (var columnDefinition2 in bigTable.ColumnDefinitions2)
|
||||
{
|
||||
builder.InsertCell();
|
||||
var propertyValue = item.GetType()
|
||||
.GetProperty(columnDefinition2.PropertyName)?
|
||||
.GetValue(item)?.ToString();
|
||||
|
||||
builder.Write(propertyValue ?? "");
|
||||
}
|
||||
|
||||
builder.EndRow();
|
||||
}
|
||||
|
||||
builder.EndTable();
|
||||
|
||||
document.Save(bigTable.FilePath);
|
||||
}
|
||||
}
|
||||
}
|
@ -7,4 +7,9 @@
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Aspose.Words" Version="23.10.0" />
|
||||
<PackageReference Include="DocumentFormat.OpenXml" Version="2.20.0" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
@ -7,7 +7,7 @@ namespace WinFormsProject
|
||||
public Form1()
|
||||
{
|
||||
InitializeComponent();
|
||||
customCheckedListBox1.FillCheckedListBox(list);
|
||||
//customCheckedListBox1.FillCheckedListBox(list);
|
||||
customCheckedListBox1.ValueChanged += CustomEventHandler;
|
||||
}
|
||||
|
||||
@ -23,7 +23,7 @@ namespace WinFormsProject
|
||||
|
||||
private void Button_Fill_Click(object sender, EventArgs e)
|
||||
{
|
||||
customCheckedListBox1.FillCheckedListBox(list);
|
||||
// customCheckedListBox1.FillCheckedListBox(list);
|
||||
}
|
||||
|
||||
private void Button_GetChosenValues_Click(object sender, EventArgs e)
|
||||
|
128
WinFormsProject/WinFormsProject/Form2.Designer.cs
generated
Normal file
128
WinFormsProject/WinFormsProject/Form2.Designer.cs
generated
Normal file
@ -0,0 +1,128 @@
|
||||
namespace WinFormsProject
|
||||
{
|
||||
partial class Form2
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.groupBox1 = new System.Windows.Forms.GroupBox();
|
||||
this.button1 = new System.Windows.Forms.Button();
|
||||
this.groupBox2 = new System.Windows.Forms.GroupBox();
|
||||
this.button2 = new System.Windows.Forms.Button();
|
||||
this.groupBox3 = new System.Windows.Forms.GroupBox();
|
||||
this.button3 = new System.Windows.Forms.Button();
|
||||
this.groupBox1.SuspendLayout();
|
||||
this.groupBox2.SuspendLayout();
|
||||
this.groupBox3.SuspendLayout();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// groupBox1
|
||||
//
|
||||
this.groupBox1.Controls.Add(this.button1);
|
||||
this.groupBox1.Location = new System.Drawing.Point(12, 12);
|
||||
this.groupBox1.Name = "groupBox1";
|
||||
this.groupBox1.Size = new System.Drawing.Size(185, 71);
|
||||
this.groupBox1.TabIndex = 0;
|
||||
this.groupBox1.TabStop = false;
|
||||
this.groupBox1.Text = "Работа с изображениями";
|
||||
//
|
||||
// button1
|
||||
//
|
||||
this.button1.Location = new System.Drawing.Point(56, 42);
|
||||
this.button1.Name = "button1";
|
||||
this.button1.Size = new System.Drawing.Size(75, 23);
|
||||
this.button1.TabIndex = 0;
|
||||
this.button1.Text = "Создать";
|
||||
this.button1.UseVisualStyleBackColor = true;
|
||||
this.button1.Click += new System.EventHandler(this.button1_Click);
|
||||
//
|
||||
// groupBox2
|
||||
//
|
||||
this.groupBox2.Controls.Add(this.button2);
|
||||
this.groupBox2.Location = new System.Drawing.Point(217, 12);
|
||||
this.groupBox2.Name = "groupBox2";
|
||||
this.groupBox2.Size = new System.Drawing.Size(185, 71);
|
||||
this.groupBox2.TabIndex = 1;
|
||||
this.groupBox2.TabStop = false;
|
||||
this.groupBox2.Text = "Работа с таблицей";
|
||||
//
|
||||
// button2
|
||||
//
|
||||
this.button2.Location = new System.Drawing.Point(57, 42);
|
||||
this.button2.Name = "button2";
|
||||
this.button2.Size = new System.Drawing.Size(75, 23);
|
||||
this.button2.TabIndex = 0;
|
||||
this.button2.Text = "Создать";
|
||||
this.button2.UseVisualStyleBackColor = true;
|
||||
this.button2.Click += new System.EventHandler(this.button2_Click);
|
||||
//
|
||||
// groupBox3
|
||||
//
|
||||
this.groupBox3.Controls.Add(this.button3);
|
||||
this.groupBox3.Location = new System.Drawing.Point(437, 12);
|
||||
this.groupBox3.Name = "groupBox3";
|
||||
this.groupBox3.Size = new System.Drawing.Size(185, 71);
|
||||
this.groupBox3.TabIndex = 2;
|
||||
this.groupBox3.TabStop = false;
|
||||
this.groupBox3.Text = "Работа с диаграммой";
|
||||
//
|
||||
// button3
|
||||
//
|
||||
this.button3.Location = new System.Drawing.Point(56, 42);
|
||||
this.button3.Name = "button3";
|
||||
this.button3.Size = new System.Drawing.Size(75, 23);
|
||||
this.button3.TabIndex = 0;
|
||||
this.button3.Text = "Создать";
|
||||
this.button3.UseVisualStyleBackColor = true;
|
||||
this.button3.Click += new System.EventHandler(this.button3_Click);
|
||||
//
|
||||
// Form2
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(649, 95);
|
||||
this.Controls.Add(this.groupBox3);
|
||||
this.Controls.Add(this.groupBox2);
|
||||
this.Controls.Add(this.groupBox1);
|
||||
this.Name = "Form2";
|
||||
this.Text = "Form2";
|
||||
this.groupBox1.ResumeLayout(false);
|
||||
this.groupBox2.ResumeLayout(false);
|
||||
this.groupBox3.ResumeLayout(false);
|
||||
this.ResumeLayout(false);
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private GroupBox groupBox1;
|
||||
private Button button1;
|
||||
private GroupBox groupBox2;
|
||||
private Button button2;
|
||||
private GroupBox groupBox3;
|
||||
private Button button3;
|
||||
}
|
||||
}
|
141
WinFormsProject/WinFormsProject/Form2.cs
Normal file
141
WinFormsProject/WinFormsProject/Form2.cs
Normal file
@ -0,0 +1,141 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using WinFormsLibrary.SupportClasses.Enums;
|
||||
using WinFormsLibrary.SupportClasses;
|
||||
using WinFormsLibrary;
|
||||
|
||||
namespace WinFormsProject
|
||||
{
|
||||
public partial class Form2 : Form
|
||||
{
|
||||
private List<string> testArray;
|
||||
DocumentWithImage documentWithImage;
|
||||
Table2column table2column;
|
||||
CircleDiagram circleDiagram;
|
||||
|
||||
public Form2()
|
||||
{
|
||||
InitializeComponent();
|
||||
documentWithImage = new DocumentWithImage();
|
||||
table2column = new Table2column();
|
||||
circleDiagram = new CircleDiagram();
|
||||
}
|
||||
|
||||
private void button1_Click(object sender, EventArgs e)
|
||||
{
|
||||
testArray = new List<string>() {
|
||||
"C:\\Users\\aleyc\\OneDrive\\Рабочий стол\\Images For Tets\\image_1.jpg",
|
||||
"C:\\Users\\aleyc\\OneDrive\\Рабочий стол\\Images For Tets\\image_2.png",
|
||||
};
|
||||
|
||||
//фильтрация файлов для диалогового окна
|
||||
using var dialog = new SaveFileDialog
|
||||
{
|
||||
Filter = "docx|*.docx"
|
||||
};
|
||||
if (dialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
try
|
||||
{
|
||||
ImageClass imageClass = new(dialog.FileName, "Любой заголовок", testArray);
|
||||
documentWithImage.CreateDocument(imageClass);
|
||||
|
||||
MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void button2_Click(object sender, EventArgs e)
|
||||
{
|
||||
List<int[]> mergedColumns = new()
|
||||
{
|
||||
new int[] { 0, 1, 2 }
|
||||
};
|
||||
|
||||
|
||||
|
||||
List<ColumnDefinition> columnDefinitions = new List<ColumnDefinition>
|
||||
{
|
||||
new ColumnDefinition { Header = "Образование", PropertyName = "Eduction", Weight = 35 },
|
||||
new ColumnDefinition { Header = "", PropertyName = "Education1", Weight = 35 },
|
||||
new ColumnDefinition { Header = "", PropertyName = "Education2", Weight = 10 },
|
||||
new ColumnDefinition { Header = "Фамилия", PropertyName = "Name", Weight = 20 }
|
||||
};
|
||||
|
||||
List<ColumnDefinition> columnDefinitions2 = new List<ColumnDefinition>
|
||||
{
|
||||
new ColumnDefinition { Header = "Группа", PropertyName = "Group", Weight = 35 },
|
||||
new ColumnDefinition { Header = "Факультатив", PropertyName = "Faculty", Weight = 35 },
|
||||
new ColumnDefinition { Header = "Курс", PropertyName = "Course", Weight = 10 },
|
||||
new ColumnDefinition { Header = "Фамилия", PropertyName = "Name", Weight = 20 }
|
||||
};
|
||||
|
||||
List<Student> data = new List<Student>
|
||||
{
|
||||
new Student { Group = "ПИбд-32", Faculty = "ФИСТ", Course = 3, Name = "Васильев" },
|
||||
new Student { Group = "РТбд-11", Faculty = "РТФ", Course = 1, Name = "Иванов" },
|
||||
new Student { Group = "ЛМККбд-41", Faculty = "ГФ", Course = 4, Name = "Смирнова" }
|
||||
};
|
||||
|
||||
using var dialog = new SaveFileDialog
|
||||
{
|
||||
Filter = "docx|*.docx"
|
||||
};
|
||||
if (dialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
try
|
||||
{
|
||||
BigTable<Student> bigTable = new(dialog.FileName, "Задание 2", columnDefinitions, columnDefinitions2, data, mergedColumns);
|
||||
table2column.CreateTable(bigTable);
|
||||
MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void button3_Click(object sender, EventArgs e)
|
||||
{
|
||||
//фильтрация файлов для диалогового окна
|
||||
using var dialog = new SaveFileDialog
|
||||
{
|
||||
Filter = "docx|*.docx"
|
||||
};
|
||||
|
||||
if (dialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
try
|
||||
{
|
||||
string[] month = { "Январь", "Февраль", "Март" };
|
||||
double[] profit1 = { 300, 440, 270 };
|
||||
double[] profit2 = { 500, 620, 310 };
|
||||
double[] profit3 = { 420, 189, 430 };
|
||||
SimpleCircleDiagram simpleCircleDiagram = new(dialog.FileName, "Третье задание", "График прибыли", EnumAreaLegend.Right, new List<DataCircleDiagram> {
|
||||
new DataCircleDiagram("Компания 1", month, profit1), new DataCircleDiagram("Компания 2", month, profit2), new DataCircleDiagram("Компания 3", month, profit3),
|
||||
});
|
||||
|
||||
circleDiagram.AddCircleDiagram(simpleCircleDiagram);
|
||||
|
||||
MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
60
WinFormsProject/WinFormsProject/Form2.resx
Normal file
60
WinFormsProject/WinFormsProject/Form2.resx
Normal file
@ -0,0 +1,60 @@
|
||||
<root>
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
@ -11,7 +11,7 @@ namespace WinFormsProject
|
||||
// To customize application configuration such as set high DPI settings or default font,
|
||||
// see https://aka.ms/applicationconfiguration.
|
||||
ApplicationConfiguration.Initialize();
|
||||
Application.Run(new Form1());
|
||||
Application.Run(new Form2());
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user