private void button1_Click(object sender, EventArgs e) { try { savePath = pathTB.Text; string fileName = Parsing.CheckForDuplicateDOCX(savePath, savePath, protocolNumTB.Text + " (" + MetalMarkingsTB.Text + ")"); var doc = DocX.Create(fileName); Xceed.Document.NET.Formatting smallText = new Xceed.Document.NET.Formatting(); smallText.FontColor = Color.Black; smallText.FontFamily = new Xceed.Document.NET.Font("Times New Roman"); smallText.Size = 11; smallText.Bold = false; smallText.Position = 1; Xceed.Document.NET.Formatting boldSmall = new Xceed.Document.NET.Formatting(); boldSmall.FontColor = Color.Black; boldSmall.FontFamily = new Xceed.Document.NET.Font("Times New Roman"); boldSmall.Size = 11; boldSmall.Bold = true; boldSmall.Position = 1; doc.PageLayout.Orientation = Xceed.Document.NET.Orientation.Landscape; Xceed.Document.NET.Formatting bold = new Xceed.Document.NET.Formatting(); bold.FontColor = Color.Black; bold.FontFamily = new Xceed.Document.NET.Font("Times New Roman"); bold.Size = 12; bold.Bold = true; bold.Position = 1; Xceed.Document.NET.Formatting defaultText = new Xceed.Document.NET.Formatting(); defaultText.FontColor = Color.Black; defaultText.FontFamily = new Xceed.Document.NET.Font("Times New Roman"); defaultText.Size = 12; defaultText.Bold = false; defaultText.Position = 1; doc.SetDefaultFont(new Xceed.Document.NET.Font("Times New Roman"), 12, Color.Black); doc.InsertParagraph(protocolNumTB.Text, false, bold).Alignment = Xceed.Document.NET.Alignment.center; doc.InsertParagraph(generalDateTB.Text, false, bold).Alignment = Xceed.Document.NET.Alignment.center; doc.InsertParagraph(experimentsForTB.Text, false, bold).Alignment = Xceed.Document.NET.Alignment.center; var l1 = doc.InsertParagraph(label1.Text, false, bold); l1.Append(" " + experimentMethods.Text, defaultText); doc.InsertParagraph(); var l2 = doc.InsertParagraph(label2.Text, false, bold); l2.Append(" " + applicationTB.Text, defaultText); var l3 = doc.InsertParagraph(label3.Text, false, bold); l3.Append(" " + recieveDataTB.Text, defaultText); doc.InsertParagraph(); var l4 = doc.InsertParagraph(label4.Text, false, bold); l4.Append(" " + nameAndAdressTB.Text, defaultText); var l5 = doc.InsertParagraph(label5.Text, false, bold); l5.Append(" " + objectOfTheExperimentTB.Text, defaultText); var l6 = doc.InsertParagraph(label6.Text, false, bold); l6.Append(" " + MetalMarkingsTB.Text, defaultText); doc.InsertParagraph(); var l7 = doc.InsertParagraph(label7.Text, false, bold); Xceed.Document.NET.Table infoData = doc.AddTable(informationData.Rows.Count, 4); infoData.Rows[0].Cells[0].InsertParagraph("Объекты испытаний", false, bold); infoData.Rows[0].Cells[0].Width += 30; infoData.Rows[0].Cells[1].InsertParagraph("Маркировка", false, bold); infoData.Rows[0].Cells[2].InsertParagraph("Марка стали", false, bold); infoData.Rows[0].Cells[3].InsertParagraph("Сортамент, мм", false, bold); for (int i = 0; i < informationData.Rows.Count - 1; i++) { if (informationData.Rows[i].Cells[0].Value == null || informationData.Rows[i].Cells[1].Value == null || informationData.Rows[i].Cells[2].Value == null || informationData.Rows[i].Cells[3].Value == null) { MessageBox.Show("Проверьте что все значения в ячейках заполнены. (кроме последней строки) Для того чтоб заполнить ячейку после ввода нажмите Enter"); } else { infoData.Rows[i].Cells[0].InsertParagraph(informationData.Rows[i + 1].Cells[0].Value.ToString(), false, defaultText); infoData.Rows[i].Cells[1].InsertParagraph(informationData.Rows[i + 1].Cells[1].Value.ToString(), false, defaultText).Alignment = Xceed.Document.NET.Alignment.center; infoData.Rows[i].Cells[2].InsertParagraph(informationData.Rows[i + 1].Cells[2].Value.ToString(), false, defaultText).Alignment = Xceed.Document.NET.Alignment.center; infoData.Rows[i].Cells[3].InsertParagraph(informationData.Rows[i + 1].Cells[3].Value.ToString(), false, defaultText).Alignment = Xceed.Document.NET.Alignment.center; } } doc.InsertTable(infoData); doc.InsertParagraph(); var l8 = doc.InsertParagraph(label8.Text, false, bold); l8.Append(" " + experimentDateTB.Text, defaultText); doc.InsertSectionPageBreak(); doc.InsertParagraph(); var l9 = doc.InsertParagraph(label9.Text, false, bold); Xceed.Document.NET.Table deviceInfo = doc.AddTable(1, 1); deviceInfo.Rows[0].Cells[0].InsertParagraph(deviceInfoTB.Text, false, defaultText); deviceInfo.Rows[0].Cells[0].Width = doc.PageWidth; doc.InsertTable(deviceInfo); doc.InsertParagraph(); var l10 = doc.InsertParagraph(label10.Text, false, bold); doc.InsertParagraph("\t" + temperatureTB.Text, false, defaultText); doc.InsertParagraph("\t" + musicalTB.Text, false, defaultText); doc.InsertSectionPageBreak(); var l13 = doc.InsertParagraph(label11.Text, false, bold); if (squareMetalSamplesTable.Rows.Count > 1) { Xceed.Document.NET.Table squareMetalSamplesTableData = doc.AddTable(squareMetalSamplesTable.Rows.Count, squareMetalSamplesTable.Columns.Count - 1); for (int i = 0; i < squareMetalSamplesTable.RowCount; i++) { for (int j = 0; j < squareMetalSamplesTable.Columns.Count - 1; j++) { if (i == 0) { string tempStr = squareMetalSamplesTable.Columns[j].HeaderText; squareMetalSamplesTableData.Rows[i].Cells[j].InsertParagraph(tempStr, false, boldSmall); } else { squareMetalSamplesTableData.Rows[i].Cells[j].InsertParagraph(squareMetalSamplesTable.Rows[i - 1].Cells[j].Value.ToString(), false, smallText); } } } doc.InsertTable(squareMetalSamplesTableData); doc.InsertSectionPageBreak(); } if (roundMetalSamplesTable.Rows.Count > 1) { Xceed.Document.NET.Table roundMetalSamplesTableData = doc.AddTable(roundMetalSamplesTable.Rows.Count, roundMetalSamplesTable.Columns.Count); for (int i = 0; i < roundMetalSamplesTable.RowCount; i++) { for (int j = 0; j < roundMetalSamplesTable.Columns.Count; j++) { if (i == 0) { string tempStr = roundMetalSamplesTable.Columns[j].HeaderText; roundMetalSamplesTableData.Rows[i].Cells[j].InsertParagraph(tempStr, false, boldSmall); } else { roundMetalSamplesTableData.Rows[i].Cells[j].InsertParagraph(roundMetalSamplesTable.Rows[i - 1].Cells[j].Value.ToString(), false, smallText); } } } doc.InsertTable(roundMetalSamplesTableData); } doc.AddHeaders(); doc.DifferentFirstPage = true; boldSmall.Size = 10; smallText.Size = 10; var headerDefault = doc.Headers.Odd; Bitmap bmp = new Bitmap(ComPortReader.Properties.Resources.ИТ_Сервис); var image = doc.AddImage(GetResourceStream(@"ИТ_Сервис")); var picture = image.CreatePicture(196 / 3, 401 / 3); var image2 = doc.AddImage(GetResourceStream(@"Визитка")); var picture2 = image2.CreatePicture(261 / 3, 818 / 3); //var headerFirstParagraph = doc.Headers.First.InsertParagraph(); //headerFirstParagraph.InsertPicture(picture); //headerFirstParagraph.InsertParagraphBeforeSelf(doc.InsertParagraph()); var headerDefault1 = doc.Headers.First; Paragraph hp = headerDefault1.Paragraphs.First(); hp.InsertPicture(picture, 0); hp.Append(" "); hp.AppendPicture(picture2); doc.Headers.First.InsertParagraph("Испытательный центр", false, boldSmall).Alignment = Xceed.Document.NET.Alignment.center; doc.Headers.First.InsertParagraph("443036, г.Самара, Железнодорожный Район, Набережная реки Самара, дом 1", false, smallText).Alignment = Xceed.Document.NET.Alignment.center; doc.Headers.First.InsertParagraph("______________________________________________________________________________________________________________________"); doc.DifferentOddAndEvenPages = false; doc.AddFooters(); Paragraph tempParagraph1 = doc.Footers.First.InsertParagraph(" из "); tempParagraph1.Append("").InsertPageCount(PageNumberFormat.normal, 4); tempParagraph1.Append("").InsertPageNumber(PageNumberFormat.normal, 0); Paragraph tempParagraph2 = doc.Footers.Odd.InsertParagraph(" из "); tempParagraph2.Append("").InsertPageCount(PageNumberFormat.normal, 4); tempParagraph2.Append("").InsertPageNumber(PageNumberFormat.normal, 0); //tempParagraph.AppendLine(" из ").InsertPageCount(PageNumberFormat.normal, 6); string info = this.protocolNumTB.Text + " " + generalDateTB.Text; doc.Footers.First.InsertParagraph(info); doc.Footers.First.InsertParagraph("Не может быть частично и полностью воспроизведен без письменного разрешения испытательного центра"); doc.Footers.Odd.InsertParagraph(info); doc.Footers.Odd.InsertParagraph("Не может быть частично и полностью воспроизведен без письменного разрешения испытательного центра"); doc.Save(); try { System.Diagnostics.Process.Start(fileName); } catch (Exception ex1) { MessageBox.Show(ex1.ToString()); } } catch (Exception ex) { if (ex is System.IO.DirectoryNotFoundException) { MessageBox.Show("Неверный путь: " + ex.Message); } else { MessageBox.Show(ex.Message); } } }
public virtual Paragraph InsertParagraph(int index, string text, bool trackChanges, Formatting formatting) { var newParagraph = new Paragraph(this.Document, new XElement(Document.w + "p"), index); newParagraph.InsertText(0, text, trackChanges, formatting); var firstPar = HelperFunctions.GetFirstParagraphEffectedByInsert(Document, index); if (firstPar != null) { var splitIndex = index - firstPar._startIndex; if (splitIndex > 0) { var splitParagraph = HelperFunctions.SplitParagraph(firstPar, splitIndex); firstPar.Xml.ReplaceWith(splitParagraph[0], newParagraph.Xml, splitParagraph[1]); } else { firstPar.Xml.ReplaceWith(newParagraph.Xml, firstPar.Xml); } } else { this.AddElementInXml(newParagraph); } this.SetParentContainer(newParagraph); return(newParagraph); }
public override Paragraph InsertParagraph( int index, string text, bool trackChanges, Formatting formatting ) { var p = base.InsertParagraph( index, text, trackChanges, formatting ); p.PackagePart = this.PackagePart; return p; }
internal void InternalModifyFormatting(Formatting f) { _setInitialFormatting = false; this.formatting = f; _setInitialFormatting = true; }