From e6dd043cbbbffd42b03d294d21dff56dbb5dbe50 Mon Sep 17 00:00:00 2001 From: revengel66 Date: Tue, 15 Oct 2024 10:27:49 +0300 Subject: [PATCH] lab 2 in process --- AddTable.docx | Bin 0 -> 1310 bytes ComponentsLab.sln | 31 +++++++ ComponentsLibrary/ComponentTable.cs | 6 +- ComponentsView/FormComponents.cs | 19 +++-- ComponentsView/Program.cs | 125 ++++++++++++++++++++++++++-- docs/Word.docx | Bin 0 -> 1129 bytes 6 files changed, 165 insertions(+), 16 deletions(-) create mode 100644 AddTable.docx create mode 100644 ComponentsLab.sln create mode 100644 docs/Word.docx diff --git a/AddTable.docx b/AddTable.docx new file mode 100644 index 0000000000000000000000000000000000000000..d622449927b10e63c28f6b9159d322b37d788b1c GIT binary patch literal 1310 zcmWIWW@Zs#U|`^2n6TL^l6`V{t`j2zLnkK#gCJ0}JijPKKP5l8G&eP`M6V(@=WSS^ zf3tzWKkX&&*X5`kn{ZI5_T$APF7p?PTwC(i^sV8X{r7?*t{mYhiLN;?eRtfu-S79w z1?;-FM@#bUj#8!)uW8*gTw;thTGs_%N+>P$HoLjY*DIm-k(6@(b-m2sO|B-KOZ#$n zp1RA#bKNeyG1T(cg=%Yu$ zVo}SQ9IF?6X`_c<&5L_`u8DSLoNwmHVo|AVRTj{G^;W_yL*4720q55m5!d~BQ|ja# z@*~rI1H^ph>$E*mJn}{^WpRlJdzYPP&I%W^12?+!`>PKJPcr9dzHqDS)5#~l7JPAz zTEX2NpAq>l=JZM1@cIj%e|?!Z*ZR{1L*ZRbKZL4hTYg<~F#d__JP4f)rsqHO_`UpJ z-G{&Wc0c~TdMw_a9r}$g02<&73=@F?zUp(UgBCErL6{pD;PFMNImP;VAoBh0{WkW% zAXg|$Eh^5;&$CrB)H6_0NX<*mPsz+nw^b@FNz=7ZvbVDdO3g_u0jem@$Sf#U0BXrA zwpGd~DJihh*Dp@aNX<&A$G}nU$=QkNsrp6+24?y|8xdwG zp_-`>Qdy8njEVVaX_?8XF3|LX#bA9@6-o*riACwDCALcX7%5Fj!865HDJUr^#mF!< zImsf$(7+_oB2`I2-_AxK#m9E2L3&@BDLe`ooFFU=4AN-l{Jaui@{I@iqBs_miird1ae|QK~82eI4bnZ@>0;^ zO&1b=@Ei#WwSuDj%ENd$PavVjya1K~~} J?au<@0RWDB)?5Gp literal 0 HcmV?d00001 diff --git a/ComponentsLab.sln b/ComponentsLab.sln new file mode 100644 index 0000000..8c42f15 --- /dev/null +++ b/ComponentsLab.sln @@ -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 diff --git a/ComponentsLibrary/ComponentTable.cs b/ComponentsLibrary/ComponentTable.cs index 83da694..c791e8a 100644 --- a/ComponentsLibrary/ComponentTable.cs +++ b/ComponentsLibrary/ComponentTable.cs @@ -18,7 +18,7 @@ namespace ComponentsLibrary InitializeComponent(); } - + /* public void CreateDocument(string filePath, DocumentTable documentTable) { ValidateInput(documentTable); @@ -106,6 +106,6 @@ namespace ComponentsLibrary } table.Append(dataRow); } - } - } + }*/ + } } diff --git a/ComponentsView/FormComponents.cs b/ComponentsView/FormComponents.cs index 4549d4a..800b1be 100644 --- a/ComponentsView/FormComponents.cs +++ b/ComponentsView/FormComponents.cs @@ -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) { diff --git a/ComponentsView/Program.cs b/ComponentsView/Program.cs index e60b7ea..9b56f5e 100644 --- a/ComponentsView/Program.cs +++ b/ComponentsView/Program.cs @@ -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.Single), + Size = 12 + }, + new BottomBorder + { + Val = new EnumValue(BorderValues.Single), + Size = 12 + }, + new LeftBorder + { + Val = new EnumValue(BorderValues.Single), + Size = 12 + }, + new RightBorder + { + Val = new EnumValue(BorderValues.Single), + Size = 12 + }, + new InsideHorizontalBorder + { + Val = new EnumValue(BorderValues.Single), + Size = 12 + }, + new InsideVerticalBorder + { + Val = new EnumValue(BorderValues.Single), + Size = 12 + } + ) + ); + table.AppendChild(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(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(); + + } + } + + } } } \ No newline at end of file diff --git a/docs/Word.docx b/docs/Word.docx new file mode 100644 index 0000000000000000000000000000000000000000..142778c4eca60474b59cbe9344a17b4faea6afc0 GIT binary patch literal 1129 zcmWIWW@Zs#U|`^2_}t+YIkj2Rr5DKC55$5%T%KQ)qMwqVT$-DjSE5&un`7E{k?)WK zk86GE!@G@k63)lI>2jn-8$~hse0i^HxNpw4ZQIS~PAj)*6MwQvSgKHVssw}VPuXzg zb5eTz8_xt^o_9x*@%4c^on4X}ug=;sd69;zV7xt znx)e(zSF3BGWpN)>sKaPzmlnGV91>mTk>hnNwH_|8)pAE{wy8*(w?887L{F<|XH+Wag#YDwUR` z=~^h++t~!A<|LK?RTO7r78EN0wd57sDrJFV{er~g?8Nj`eIo+{Gku_q2s4yW%~S}fEJ!8B#Qe0h%;Z!TXwYLZSRYk|l0ryg zQF>~Lt&%=Qq$w$Qrr0V4r6wh(7@DRT8WP#)P0aZPAn+M$xH@Eg??FH3R=ABLc$N8xIv*-P?VpXT3ifF61h2gaGBi1%sg$d z@xbuHVlya(k!CeCxq#9pBBj8s&O@AO<;T=0gOmTXvdyC5PJ6jnMj!h fT_buTKxpJ=!kQ!kyjj^mikN|LCy<`S4B`O*gzR@p literal 0 HcmV?d00001