lab 2 in process
This commit is contained in:
parent
6190df5e28
commit
e6dd043cbb
BIN
AddTable.docx
Normal file
BIN
AddTable.docx
Normal file
Binary file not shown.
31
ComponentsLab.sln
Normal file
31
ComponentsLab.sln
Normal file
@ -0,0 +1,31 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 17
|
||||
VisualStudioVersion = 17.9.34723.18
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ComponentsLibrary", "ComponentsLibrary\ComponentsLibrary.csproj", "{62BF8781-DBD1-4FC8-BE56-FDF96F51937D}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ComponentsView", "ComponentsView\ComponentsView.csproj", "{3ABCBF18-4F14-44A4-B921-329CFCE9E5DF}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{62BF8781-DBD1-4FC8-BE56-FDF96F51937D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{62BF8781-DBD1-4FC8-BE56-FDF96F51937D}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{62BF8781-DBD1-4FC8-BE56-FDF96F51937D}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{62BF8781-DBD1-4FC8-BE56-FDF96F51937D}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{3ABCBF18-4F14-44A4-B921-329CFCE9E5DF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{3ABCBF18-4F14-44A4-B921-329CFCE9E5DF}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{3ABCBF18-4F14-44A4-B921-329CFCE9E5DF}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{3ABCBF18-4F14-44A4-B921-329CFCE9E5DF}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {402122A1-1FB6-406E-869E-FADF8DF1F7EA}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
@ -18,7 +18,7 @@ namespace ComponentsLibrary
|
||||
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
/*
|
||||
public void CreateDocument(string filePath, DocumentTable<T> documentTable)
|
||||
{
|
||||
ValidateInput(documentTable);
|
||||
@ -106,6 +106,6 @@ namespace ComponentsLibrary
|
||||
}
|
||||
table.Append(dataRow);
|
||||
}
|
||||
}
|
||||
}
|
||||
}*/
|
||||
}
|
||||
}
|
||||
|
@ -31,7 +31,7 @@ namespace ComponentsView
|
||||
{
|
||||
try
|
||||
{
|
||||
var docEntry = new DocumentSymple(@"C:\Users\Natalia\Desktop\5semestr\KOP\KOP-PIbd-32-Katysheva-N-E\docs", "Word.docx", richTextBoxWord.Lines);
|
||||
var docEntry = new DocumentSymple(@"\5semestr\KOP\KOP-PIbd-32-Katysheva-N-E\docs", "Word.docx", richTextBoxWord.Lines);
|
||||
componentBigText.SetText(docEntry.FileUrl, docEntry.FileName, docEntry.Text);
|
||||
MessageBox.Show("Ñîõàðíåíî óñïåøíî", "Ðåçóëüòàò",
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
@ -47,11 +47,14 @@ namespace ComponentsView
|
||||
{
|
||||
dataGridViewTable.Columns.Add("Column1", "Íàçâàíèå");
|
||||
dataGridViewTable.Columns.Add("Column2", "Çíà÷åíèå");
|
||||
|
||||
// Äîáàâüòå íåêîòîðûå òåñòîâûå äàííûå
|
||||
dataGridViewTable.Rows.Add("Òåñò1", "Çíà÷åíèå1");
|
||||
dataGridViewTable.Rows.Add("Òåñò2", "Çíà÷åíèå2");
|
||||
}
|
||||
dataGridViewTable.Columns.Add("Column3", "Âòîðîå çíà÷åíèå");
|
||||
dataGridViewTable.Rows.Add("Òåñò1", "Çíà÷åíèå1","2 Çíà÷åíèå1");
|
||||
dataGridViewTable.Rows.Add("Òåñò2", "Çíà÷åíèå2", "2 Çíà÷åíèå2");
|
||||
dataGridViewTable.Rows.Add("Òåñò3", "Çíà÷åíèå3", "2 Çíà÷åíèå3");
|
||||
dataGridViewTable.Rows.Add("Òåñò4", "Çíà÷åíèå4", "2 Çíà÷åíèå4");
|
||||
dataGridViewTable.Rows.Add("Òåñò5", "Çíà÷åíèå5", "2 Çíà÷åíèå5");
|
||||
dataGridViewTable.Rows.Add("Òåñò6", "Çíà÷åíèå6", "2 Çíà÷åíèå6");
|
||||
}
|
||||
|
||||
private void buttonSaveTable_Click(object sender, EventArgs e)
|
||||
{
|
||||
@ -72,11 +75,11 @@ namespace ComponentsView
|
||||
}
|
||||
|
||||
// Ñîçäàíèå äîêóìåíòà ñ äàííûìè èç òàáëèöû
|
||||
var docEntry = new DocumentSymple(@"C:\Users\Natalia\Desktop\5semestr\KOP\KOP-PIbd-32-Katysheva-N-E\docs", "Table.docx", data.Select(row => string.Join("\t", row)).ToArray());
|
||||
var docEntry = new DocumentSymple(@"\5semestr\KOP\KOP-PIbd-32-Katysheva-N-E\docs", "Table.docx", data.Select(row => string.Join("\t", row)).ToArray());
|
||||
componentBigText.SetText(docEntry.FileUrl, docEntry.FileName, docEntry.Text);
|
||||
|
||||
MessageBox.Show("Ñîõðàíåíî óñïåøíî", "Ðåçóëüòàò",
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
@ -1,3 +1,6 @@
|
||||
using DocumentFormat.OpenXml;
|
||||
using DocumentFormat.OpenXml.Packaging;
|
||||
using DocumentFormat.OpenXml.Wordprocessing;
|
||||
namespace ComponentsView
|
||||
{
|
||||
internal static class Program
|
||||
@ -8,10 +11,122 @@ namespace ComponentsView
|
||||
[STAThread]
|
||||
static void Main()
|
||||
{
|
||||
// To customize application configuration such as set high DPI settings or default font,
|
||||
// see https://aka.ms/applicationconfiguration.
|
||||
ApplicationConfiguration.Initialize();
|
||||
Application.Run(new FormComponents());
|
||||
}
|
||||
// To customize application configuration such as set high DPI settings or default font,
|
||||
// see https://aka.ms/applicationconfiguration.
|
||||
//ApplicationConfiguration.Initialize();
|
||||
//Application.Run(new FormComponents());
|
||||
|
||||
const string fileName = @"AddTable.docx";
|
||||
const string fileUrl = @"\5semestr\KOP\KOP-PIbd-32-Katysheva-N-E";
|
||||
AddTable();
|
||||
|
||||
static void AddTable() {
|
||||
|
||||
|
||||
using (WordprocessingDocument document = WordprocessingDocument.Create(Path.Combine(fileUrl, fileName), WordprocessingDocumentType.Document))
|
||||
{
|
||||
|
||||
//var doc = document.MainDocumentPart.Document;
|
||||
MainDocumentPart mainPart = document.AddMainDocumentPart();
|
||||
mainPart.Document = new Document();
|
||||
Body body = new Body();
|
||||
|
||||
Table table = new Table();
|
||||
|
||||
TableProperties props = new TableProperties(
|
||||
new TableBorders(
|
||||
new TopBorder
|
||||
{
|
||||
Val = new EnumValue<BorderValues>(BorderValues.Single),
|
||||
Size = 12
|
||||
},
|
||||
new BottomBorder
|
||||
{
|
||||
Val = new EnumValue<BorderValues>(BorderValues.Single),
|
||||
Size = 12
|
||||
},
|
||||
new LeftBorder
|
||||
{
|
||||
Val = new EnumValue<BorderValues>(BorderValues.Single),
|
||||
Size = 12
|
||||
},
|
||||
new RightBorder
|
||||
{
|
||||
Val = new EnumValue<BorderValues>(BorderValues.Single),
|
||||
Size = 12
|
||||
},
|
||||
new InsideHorizontalBorder
|
||||
{
|
||||
Val = new EnumValue<BorderValues>(BorderValues.Single),
|
||||
Size = 12
|
||||
},
|
||||
new InsideVerticalBorder
|
||||
{
|
||||
Val = new EnumValue<BorderValues>(BorderValues.Single),
|
||||
Size = 12
|
||||
}
|
||||
)
|
||||
);
|
||||
table.AppendChild<TableProperties>(props);
|
||||
|
||||
var headerRow = new TableRow();
|
||||
for (var j = 0; j <= 3; j++)
|
||||
{
|
||||
var tc = new TableCell();
|
||||
|
||||
|
||||
|
||||
TableCellProperties cellProps = new TableCellProperties();
|
||||
TableCellWidth cellWidth = new TableCellWidth() { Type = TableWidthUnitValues.Auto };
|
||||
cellProps.Append(cellWidth);
|
||||
|
||||
if (j == 0)
|
||||
{
|
||||
GridSpan gridSpan = new GridSpan() { Val = 3 };
|
||||
cellProps.Append(gridSpan);
|
||||
}
|
||||
if (j == 1 || j == 2)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
RunProperties headerRunProperties = new RunProperties();
|
||||
Bold bold = new Bold();
|
||||
headerRunProperties.Append(bold);
|
||||
|
||||
string headerText = "Column " + j;
|
||||
Run run = new Run(new Text(headerText));
|
||||
run.PrependChild<RunProperties>(headerRunProperties);
|
||||
|
||||
|
||||
tc.Append(new Paragraph(run));
|
||||
tc.Append(cellProps);
|
||||
headerRow.Append(tc);
|
||||
}
|
||||
table.Append(headerRow);
|
||||
|
||||
for (var i = 0; i <= 3; i++)
|
||||
{
|
||||
var tr = new TableRow();
|
||||
for (var j = 0; j <= 3; j++)
|
||||
{
|
||||
var tc = new TableCell();
|
||||
string data = "info" + i;
|
||||
tc.Append(new Paragraph(new Run(new Text(data))));
|
||||
tc.Append(new TableCellProperties(new TableCellWidth { Type = TableWidthUnitValues.Auto }));
|
||||
tr.Append(tc);
|
||||
}
|
||||
table.Append(tr);
|
||||
}
|
||||
|
||||
body.Append(table);
|
||||
|
||||
mainPart.Document.Append(body);
|
||||
mainPart.Document.Save();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
BIN
docs/Word.docx
Normal file
BIN
docs/Word.docx
Normal file
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user