private static void printSpec(DocX document, SpecInfo spec) { printName(document, spec); printSkipped(document, spec); printGiven(document, spec); printWhen(document, spec); printThen(document, spec); document.InsertParagraph(); }
private static void printSkipped(DocX document, SpecInfo spec) { if (spec.Skipped.IsSkipped) { document.InsertParagraph() .Append(spec.Skipped.ToString()) .Font(new FontFamily("Cambria")) .FontSize(13) .Bold() .Color(Color.FromArgb(255, 255, 124, 0)) ; } }
private void printCategory(SpecCategory category, DocX document) { document.InsertParagraph() .Append(category.ToString()) .Font(new FontFamily("Cambria")) .FontSize(26) .Color(Color.FromArgb(255, 23, 54, 93)) .Spacing(2.0f) .AppendLine(); foreach (var spec in category.Specs) printSpec(document, spec); }
private static void printGiven(DocX document, SpecInfo spec) { if (spec.Givens.Length == 0) return; document.InsertParagraph() .Append("Given") .Font(new FontFamily("Cambria")) .FontSize(13) .Bold() .Color(Color.FromArgb(255, 79, 129, 189)) ; foreach (var given in spec.Givens) { var description = spec.HasExecutionBeenTriggered ? string.Format("{0} [{1}]", given.Description, given.Passed ? "Passed" : "Failed") : given.Description; var p = document.InsertParagraph() .Append(description) .Color(spec.HasExecutionBeenTriggered ? (given.Passed ? Color.Green : Color.Red) : Color.Black) .FontSize(12); p.IndentationBefore = 0.5f; } if (!spec.Givens.All(x => x.Passed) && spec.Exception != null) { document.InsertParagraph() .Append(spec.Exception.ToString()) .Color(Color.Black) .FontSize(12) .IndentationBefore = 0.5f; } }
internal Image(DocX document, PackageRelationship pr) { id = pr.Id; }
private void Button01_Click(object sender, RoutedEventArgs e) { //Creates a new folders string pathString1 = System.IO.Path.Combine(folderName1, "TheBigButton1"); string pathString2 = System.IO.Path.Combine(folderName1, "TheBigButton2"); string pathString3 = System.IO.Path.Combine(folderName1, "TheBigButton3"); Directory.CreateDirectory(pathString1); Directory.CreateDirectory(pathString2); Directory.CreateDirectory(pathString3); stopWatch.Start(); //Creates "n" files within a loop into TheBigButton1 folder for (int i = 0; i < 100; i++) { string line = $"The value of i is {i} at {DateTime.Now} \n"; string pathFile1 = $@"C:\Users\xiajt\Desktop\Sparta Global\Course\C# Week\2020-06-c-sharp-labs\labs\lab_12_big_button\TheBigButton1\TheBigButtonTxt{i}.txt"; Thread.Sleep(50); // The line below will create a text file, my_file.txt, in // the Text_Files folder in D:\ drive. // The CreateText method that returns a StreamWriter object using (StreamWriter sw = File.CreateText(pathFile1)); for (int n = 0; n < 5; n++) { File.AppendAllText(pathFile1, line); } } //Creates "n" files within a loop into TheBigButton2 folder for (int i = 0; i < 100; i++) { string line = $"The value of i is {i} at {DateTime.Now} \n"; string pathFile2 = $@"C:\Users\xiajt\Desktop\Sparta Global\Course\C# Week\2020-06-c-sharp-labs\labs\lab_12_big_button\TheBigButton2\TheBigButtonTxt{i}.txt"; Thread.Sleep(50); using (StreamWriter sw = File.CreateText(pathFile2)); for (int n = 0; n < 10; n++) { File.AppendAllText(pathFile2, line); } } //Creates "n" files within a loop into TheBigButton3 folder for (int i = 0; i < 100; i++) { string line = $"The value of i is {i} at {DateTime.Now} \n"; string pathFile3 = $@"C:\Users\xiajt\Desktop\Sparta Global\Course\C# Week\2020-06-c-sharp-labs\labs\lab_12_big_button\TheBigButton3\TheBigButtonTxt{i}.txt"; Thread.Sleep(50); using (StreamWriter sw = File.CreateText(pathFile3)); for (int n = 0; n < 15; n++) { File.AppendAllText(pathFile3, line); } } var document = DocX.Create("MyReport.docx"); document.InsertParagraph("This is an amazing report"); document.InsertParagraph($"Report generated by <<author>> {DateTime.Now}"); document.Save(); Process.Start("WINWORD.EXE", "MyReport.docx"); stopWatch.Stop(); }
private void GerarRelatorioTotalVendas(List <PedidoModelo> pedidos) { string docPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\Relatorios"; string fileName = ""; bool unico = true; if (txtIdVendedor.Text != "") { VendedorModelo vendedor = SqliteAcessoDados.LoadQuery <VendedorModelo>("select * from Vendedor where Vendedor.ID == " + pedidos[0].VendedorID.ToString()).First(); PessoaModelo vendedorPessoa = SqliteAcessoDados.LoadQuery <PessoaModelo>("select * from Pessoa where Pessoa.ID == " + vendedor.PessoaId.ToString()).First(); fileName = "Vendedor - " + vendedorPessoa.Nome + " - "; unico = true; } else { fileName = "Geral - "; unico = false; } if (txtDataFinal.Text != "" && txtDataInicial.Text != "") { if (txtDataFinal.Text == txtDataInicial.Text) { fileName += DateTime.Parse(txtDataFinal.Text).Day.ToString() + "_" + DateTime.Parse(txtDataFinal.Text).Month.ToString() + "_" + DateTime.Parse(txtDataFinal.Text).Year.ToString(); } else { fileName += "De - " + DateTime.Parse(txtDataFinal.Text).Day.ToString() + "_" + DateTime.Parse(txtDataFinal.Text).Month.ToString() + "_" + DateTime.Parse(txtDataFinal.Text).Year.ToString() + " - Até - " + DateTime.Parse(txtDataInicial.Text).Day.ToString() + "_" + DateTime.Parse(txtDataInicial.Text).Month.ToString() + "_" + DateTime.Parse(txtDataInicial.Text).Year.ToString(); } } else { fileName += "Todas as Datas"; } fileName += ".docx"; System.IO.Directory.CreateDirectory(docPath); docPath = System.IO.Path.Combine(docPath, fileName); if (unico) { using (var document = DocX.Create(docPath)) { document.InsertParagraph("SABOR MINEIRO - RELATÓRIO").FontSize(11d).Bold().Alignment = Alignment.center; document.InsertParagraph("TOTAL DE VENDAS").FontSize(10d).Bold().Alignment = Alignment.center; CreateHeaderTotalVendas(pedidosList.First(), document); Table t = document.AddTable(1, 7); CreateTableTotalVendas(document, t); t = CreateTableContentTotalVendas(pedidosList.First(), t); t = CreateTableLastRowTotalVendas(t); document.InsertTable(t); try { document.Save(); DialogResult result = MessageBox.Show("Relatorio gerado na pasta Meus Documentos -> Relatorios(" + docPath + ")", "Atenção!", MessageBoxButtons.OK); } catch { DialogResult result = MessageBox.Show("Arquivo aberto em outro aplicativo, favor fecha-lo antes de continuar", "Atenção!", MessageBoxButtons.OK); } } } else { using (var document = DocX.Create(docPath)) { document.InsertParagraph("SABOR MINEIRO - RELATÓRIO").FontSize(11d).Bold().Alignment = Alignment.center; document.InsertParagraph("TOTAL DE VENDAS").FontSize(10d).Bold().Alignment = Alignment.center; int vendedorID = -1; Table t = document.AddTable(1, 7); for (int i = 0; i < pedidosList.Count; i++) { if (vendedorID != pedidosList[i].VendedorID) { CreateHeaderTotalVendas(pedidosList[i], document); t = CreateTableTotalVendas(document, t); } t = CreateTableContentTotalVendas(pedidosList[i], t); vendedorID = pedidosList[i].VendedorID; if (i == pedidosList.Count - 1) { t = CreateTableLastRowTotalVendas(t); document.InsertTable(t); } else if (vendedorID != pedidosList[i + 1].VendedorID) { t = CreateTableLastRowTotalVendas(t); document.InsertTable(t); } } try { document.Save(); DialogResult result = MessageBox.Show("Relatorio gerado na pasta Meus Documentos -> Relatorios(" + docPath + ")", "Atenção!", MessageBoxButtons.OK); } catch { DialogResult result = MessageBox.Show("Arquivo aberto em outro aplicativo, favor fecha-lo antes de continuar", "Atenção!", MessageBoxButtons.OK); } } } }
private void btDepositos_Click(object sender, EventArgs e) { if (txtIdVendedor.Text != "") { if (cbbPraça.SelectedItem != null) { if (txtDataFinal.Text != "" && txtDataInicial.Text != "") { DateTime dataInicial = DateTime.Parse(txtDataInicial.Text); DateTime dataFinal = DateTime.Parse(txtDataFinal.Text); string query = "select * from Deposito where Deposito.VendedorID == " + txtIdVendedor.Text + " and date(Deposito.Data) BETWEEN date('" + dataInicial.Year + "-" + dataInicial.Month.ToString("00") + "-" + dataInicial.Day.ToString("00") + "') and date('" + dataFinal.Year + "-" + dataFinal.Month.ToString("00") + "-" + dataFinal.Day.ToString("00") + "') order by Deposito.Data"; depositoList = SqliteAcessoDados.LoadQuery <DepositoModelo>(query); } else { depositoList = SqliteAcessoDados.LoadQuery <DepositoModelo>("select * from Deposito where Deposito.VendedorID == " + txtIdVendedor.Text + " order by Deposito.Data"); } if (depositoList.Count > 0) { string docPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\Relatorios"; VendedorModelo vendedor = SqliteAcessoDados.LoadQuery <VendedorModelo>("select * from Vendedor where Vendedor.ID == " + txtIdVendedor.Text).First(); PessoaModelo vendedorPessoa = SqliteAcessoDados.LoadQuery <PessoaModelo>("select * from Pessoa where Pessoa.ID == " + vendedor.PessoaId.ToString()).First(); string fileName = "Depositos - Vendedor - " + vendedorPessoa.Nome + " - Praça - " + cbbPraça.SelectedItem.ToString() + " - "; if (txtDataFinal.Text != "" && txtDataInicial.Text != "") { if (txtDataFinal.Text == txtDataInicial.Text) { fileName += DateTime.Parse(txtDataFinal.Text).Day.ToString() + "_" + DateTime.Parse(txtDataFinal.Text).Month.ToString() + "_" + DateTime.Parse(txtDataFinal.Text).Year.ToString(); } else { fileName += "De - " + DateTime.Parse(txtDataFinal.Text).Day.ToString() + "_" + DateTime.Parse(txtDataFinal.Text).Month.ToString() + "_" + DateTime.Parse(txtDataFinal.Text).Year.ToString() + " - Até - " + DateTime.Parse(txtDataInicial.Text).Day.ToString() + "_" + DateTime.Parse(txtDataInicial.Text).Month.ToString() + "_" + DateTime.Parse(txtDataInicial.Text).Year.ToString(); } } else { fileName += "Todas as Datas"; } fileName += ".docx"; System.IO.Directory.CreateDirectory(docPath); docPath = System.IO.Path.Combine(docPath, fileName); using (var document = DocX.Create(docPath)) { document.InsertParagraph("SABOR MINEIRO - RELATÓRIO").FontSize(11d).Bold().Alignment = Alignment.center; document.InsertParagraph("TOTAL DE VENDAS").FontSize(10d).Bold().Alignment = Alignment.center; document.InsertParagraph(); document.InsertParagraph("PROMOTOR: ").FontSize(10d).Bold() .Append(txtNomeVendedor.Text).FontSize(10d) .Alignment = Alignment.left; document.InsertParagraph("PRAÇA: ").FontSize(10d).Bold() .Append(cbbPraça.SelectedItem.ToString()).FontSize(10d) .Alignment = Alignment.left; document.InsertParagraph(); Table t = document.AddTable(1, 6); t.AutoFit = AutoFit.Contents; t.Design = TableDesign.LightGridAccent3; t.Rows[0].Cells[0].Paragraphs.First().Append("DEPOSTIO").Bold().FontSize(10d).Alignment = Alignment.center; t.Rows[0].Cells[1].Paragraphs.First().Append("DATA").Bold().FontSize(10d).Alignment = Alignment.center; t.Rows[0].Cells[2].Paragraphs.First().Append("DIA SEMANA").Bold().FontSize(10d).Alignment = Alignment.center; t.Rows[0].Cells[3].Paragraphs.First().Append("VALOR PAGO").Bold().FontSize(10d).Alignment = Alignment.center; t.Rows[0].Cells[4].Paragraphs.First().Append("PEPINO").Bold().FontSize(10d).Alignment = Alignment.center; t.Rows[0].Cells[5].Paragraphs.First().Append("TOTAL").Bold().FontSize(10d).Alignment = Alignment.center; decimal totalPeriodo = 0; decimal totalPepinoPeriodo = 0; decimal totalGeralPeriodo = 0; foreach (DepositoModelo deposito in depositoList) { t.InsertRow(); t.Rows.Last().Cells[0].Paragraphs.First().Append(deposito.Id.ToString()).FontSize(10d).Alignment = Alignment.left; t.Rows.Last().Cells[1].Paragraphs.First().Append(deposito.Data.ToShortDateString()).FontSize(10d).Alignment = Alignment.left; t.Rows.Last().Cells[2].Paragraphs.First().Append(DateTimeFormatInfo.CurrentInfo.GetDayName(deposito.Data.DayOfWeek)).FontSize(10d).Alignment = Alignment.left; t.Rows.Last().Cells[3].Paragraphs.First().Append(string.Format("{0:C}", deposito.Valor)).FontSize(10d).Alignment = Alignment.left; t.Rows.Last().Cells[4].Paragraphs.First().Append(string.Format("{0:C}", deposito.ValorPepino)).FontSize(10d).Alignment = Alignment.left; t.Rows.Last().Cells[5].Paragraphs.First().Append(string.Format("{0:C}", deposito.Valor + deposito.ValorPepino)).FontSize(10d).Alignment = Alignment.left; totalPeriodo += deposito.Valor; totalPepinoPeriodo += deposito.ValorPepino; totalGeralPeriodo += deposito.Valor + deposito.ValorPepino; } t.InsertRow(); t.Rows.Last().Cells[0].Paragraphs.First().Append("TOTAL PERIODO").Bold().FontSize(10d).Alignment = Alignment.right; t.Rows.Last().MergeCells(0, 2); t.Rows.Last().Cells[1].Paragraphs.First().Append(string.Format("{0:C}", totalPeriodo)).FontSize(10d).Alignment = Alignment.left; t.Rows.Last().Cells[2].Paragraphs.First().Append(string.Format("{0:C}", totalPepinoPeriodo)).FontSize(10d).Alignment = Alignment.left; t.Rows.Last().Cells[3].Paragraphs.First().Append(string.Format("{0:C}", totalGeralPeriodo)).FontSize(10d).Alignment = Alignment.left; document.InsertTable(t); try { document.Save(); DialogResult result = MessageBox.Show("Relatorio gerado na pasta Meus Documentos -> Relatorios(" + docPath + ")", "Atenção!", MessageBoxButtons.OK); } catch { DialogResult result = MessageBox.Show("Arquivo aberto em outro aplicativo, favor fecha-lo antes de continuar", "Atenção!", MessageBoxButtons.OK); } } /*docForPrint.MarginLeft = 36; * docForPrint.MarginRight = 36; * docForPrint.MarginTop = 36; * docForPrint.MarginBottom = 36; * * foreach (DataGridViewRow row in dgvListaImpressão.Rows) * { * string docTempPath = GerarArquivoImpressão(row); * * if (docTempPath != "") * { * docForPrint.InsertDocument(DocX.Load(docTempPath), false); * } * }*/ //DialogResult result = MessageBox.Show("Relatorio gerado na pasta Meus Documentos -> Relatorios(" + docPath + ")", "Atenção!", MessageBoxButtons.OK); } else { DialogResult result = MessageBox.Show("Nenhum Deposito registrado para esse Vendedor na Praça selecionada", "Atenção!", MessageBoxButtons.OK); } } else { DialogResult result = MessageBox.Show("Selecione uma Praça primeiro", "Atenção!", MessageBoxButtons.OK); } } else { DialogResult result = MessageBox.Show("Selecione um Vendedor primeiro", "Atenção!", MessageBoxButtons.OK); } }
internal DocProperty(DocX document, XElement xml) : base(document, xml) { string instr = Xml.Attribute(XName.Get("instr", "http://schemas.openxmlformats.org/wordprocessingml/2006/main")).Value; this.name = extractName.Match(instr.Trim()).Groups["name"].Value; }
public static DocX obrNazwa(this DocX doc, object value) { return(doc.podstaw("[OBR_NAZWA]", value)); }
private void GerarCabecalhoTabela(DocX docX) { docX.InsertParagraph($"Nome do Aluno (a): {Requisitos.NomeAluno.PadRight(47)} RA: {Requisitos.RA.PadRight(10)}").Alignment = Alignment.left; docX.InsertParagraph($"Turma: {Requisitos.Turma.PadRight(17)} Carga Horária do Estágio Supervisionado Exigida: {Requisitos.Carga_Horaria_Exigida.PadRight(4)}").Alignment = Alignment.left; docX.InsertParagraph($"Nome da Instituição Estagiada: {Requisitos.Nome_Instituicao}").Alignment = Alignment.left; }
/// <summary> /// Erstellt einen neuen Servicebericht für den Servicetermin für eine CJV30 oder JV33. /// </summary> /// <param name="serviceTermin"></param> /// <returns></returns> public string CreateServiceReportCJV30(Appointment serviceTermin) { try { // APPT: DocXService -> CreateServiceReportCJV30 Ich denke, diese ganze Nummer muss // noch einmal überdacht werden. // Kunde kunde = serviceTermin.Kunde; string reportFilename = // string.Format("{0:yyyy-MM-dd_mmss}_{1}_{2}.docx", serviceTermin.StartsAt, // serviceTermin.Kundennummer.Substring(0, 5), serviceTermin.Techniker.NameFirst); // string reportFilePath = System.IO.Path.Combine(Common.Global.LinkedFilesPath, reportFilename); var templateFilePath = Path.Combine(CatalistRegistry.Application.TemplatePath, "sb_cjv30.docx"); using (DocX doc = DocX.Load(templateFilePath)) { foreach (Paragraph p in doc.Paragraphs) { var adresseTelefon = p.GetBookmarks().FirstOrDefault(b => b.Name == "Addresse_Telefon"); if (adresseTelefon != null) { // APPT: DocXService -> CreateServiceReportCJV30 Ich denke, diese ganze // Nummer muss noch einmal überdacht werden. // adresseTelefon.Paragraph.InsertText(string.Format("{0}-{1}\n{2}", // kunde.Street, kunde.ZipCode + kunde.City, kunde.Kontaktlist[0].Telefon)); } var annahmeDurch = p.GetBookmarks().FirstOrDefault(b => b.Name == "Annahme_durch"); if (annahmeDurch != null) { annahmeDurch.Paragraph.InsertText(serviceTermin.OwnerName); } var datumService = p.GetBookmarks().FirstOrDefault(b => b.Name == "Datum_Service"); if (datumService != null) { datumService.Paragraph.InsertText(string.Format("{0:dd.MM.yyyy}", serviceTermin.StartsAt)); } var firmenName = p.GetBookmarks().FirstOrDefault(b => b.Name == "Kunde_Firmenname"); if (firmenName != null) { // APPT: DocXService -> CreateServiceReportCJV30 Ich denke, diese ganze // Nummer muss noch einmal überdacht werden. //firmenName.Paragraph.InsertText(kunde.CompanyName1); } var modell = p.GetBookmarks().FirstOrDefault(b => b.Name == "Maschine_Modell"); if (modell != null) { // APPT: DocXService -> CreateServiceReportCJV30 Ich denke, diese ganze // Nummer muss noch einmal überdacht werden. // modell.Paragraph.InsertText(serviceTermin.Maschinenmodell); } var kundenNummer = p.GetBookmarks().FirstOrDefault(b => b.Name == "Kunde_Nummer"); if (kundenNummer != null) { // APPT: DocXService -> CreateServiceReportCJV30 Ich denke, diese ganze // Nummer muss noch einmal überdacht werden. // kundenNummer.Paragraph.InsertText(kunde.CustomerId.Substring(0, 5)); } var sn = p.GetBookmarks().FirstOrDefault(b => b.Name == "Maschine_Seriennummer"); if (sn != null) { // APPT: DocXService -> CreateServiceReportCJV30 Ich denke, diese ganze // Nummer muss noch einmal überdacht werden. // sn.Paragraph.InsertText(serviceTermin.Maschine.Seriennummer); } var kontakt = p.GetBookmarks().FirstOrDefault(b => b.Name == "Kunde_Ansprechpartner"); if (kontakt != null) { // APPT: DocXService -> CreateServiceReportCJV30 Ich denke, diese ganze // Nummer muss noch einmal überdacht werden. // kontakt.Paragraph.InsertText(kunde.Kontaktlist[0].Kontaktname); } var techniker = p.GetBookmarks().FirstOrDefault(b => b.Name == "Name_Techniker"); if (techniker != null) { // APPT: DocXService -> CreateServiceReportCJV30 Ich denke, diese ganze // Nummer muss noch einmal überdacht werden. // techniker.Paragraph.InsertText(serviceTermin.Technikername); } } // APPT: DocXService -> CreateServiceReportCJV30 // Ich denke, diese ganze Nummer muss noch einmal überdacht werden. //doc.SaveAs(reportFilePath); //serviceTermin.AddFileLink(reportFilePath, deleteSourceFile: false); } //return reportFilePath; throw new ApplicationException("Sorry, die Funktion gibt's noch nicht."); } catch (Exception) { return(string.Empty); } }
private static void printName(DocX document, SpecInfo spec) { document.InsertParagraph() .Append(spec.Name) .Font(new FontFamily("Cambria")) .FontSize(13) .Bold() .Color(Color.FromArgb(255, 54, 95, 145)) ; }
static void Main() { string FileName = @"D:\OOP\Homeworks\Homework_04\GalacticGPS\Word_Document_Generator\Output items\Word.docx"; using (var doc = DocX.Create(FileName)) { //header string Header = "SoftUni OOP Game Contest"; var HeaderFormat = new Formatting(); HeaderFormat.Bold = true; HeaderFormat.Position = 25; HeaderFormat.Size = 20D; var header = doc.InsertParagraph(Header, false, HeaderFormat); header.Alignment = Alignment.center; //read image from file,resize and position Picture image = doc.AddImage(@"D:\OOP\Homeworks\Homework_04\GalacticGPS\Word_Document_Generator\Input Assets\rpg-game.png").CreatePicture(); image.Height = 200; image.Width = 520; var picParagraph = doc.InsertParagraph(""); picParagraph.InsertPicture(image); picParagraph.Alignment = Alignment.center; Paragraph mainText = doc.InsertParagraph("", false); mainText.Append("SoftUni is organizing a contest for the best "). Append("role playing game ").Bold(). Append("from the OOP teamwork "). Append("projects. The winnig teams will receive a "). Append("grand prize").Bold(). Append("!"). AppendLine("The game shoud be: "); mainText.IndentationAfter = 2.0f; var bulletedList = doc.AddList("Properly structured and follow all good OOP practices", 0, ListItemType.Bulleted); doc.AddListItem(bulletedList, "Awesome"); doc.AddListItem(bulletedList, "..Very Awesome"); doc.InsertList(bulletedList); doc.InsertParagraph(""); Table teamsResultTable = doc.AddTable(4, 3); teamsResultTable.Alignment = Alignment.center; teamsResultTable.AutoFit = AutoFit.Window; teamsResultTable.Rows[0].Cells[0].FillColor = Color.FromArgb(84, 141, 212); teamsResultTable.Rows[0].Cells[0].Paragraphs[0].Append("Team").Color(Color.White).Bold().Alignment = Alignment.center; teamsResultTable.Rows[0].Cells[1].FillColor = Color.FromArgb(84, 141, 212); teamsResultTable.Rows[0].Cells[1].Paragraphs[0].Append("Game").Color(Color.White).Bold().Alignment = Alignment.center; teamsResultTable.Rows[0].Cells[2].FillColor = Color.FromArgb(84, 141, 212); teamsResultTable.Rows[0].Cells[2].Paragraphs[0].Append("Points").Color(Color.White).Bold().Alignment = Alignment.center; teamsResultTable.Rows[1].Cells[0].Paragraphs[0].Append("-").Alignment = Alignment.center; teamsResultTable.Rows[2].Cells[0].Paragraphs[0].Append("-").Alignment = Alignment.center; teamsResultTable.Rows[3].Cells[0].Paragraphs[0].Append("-").Alignment = Alignment.center; teamsResultTable.Rows[1].Cells[1].Paragraphs[0].Append("-").Alignment = Alignment.center; teamsResultTable.Rows[2].Cells[1].Paragraphs[0].Append("-").Alignment = Alignment.center; teamsResultTable.Rows[3].Cells[1].Paragraphs[0].Append("-").Alignment = Alignment.center; teamsResultTable.Rows[1].Cells[2].Paragraphs[0].Append("-").Alignment = Alignment.center; teamsResultTable.Rows[2].Cells[2].Paragraphs[0].Append("-").Alignment = Alignment.center; teamsResultTable.Rows[3].Cells[2].Paragraphs[0].Append("-").Alignment = Alignment.center; doc.InsertTable(teamsResultTable); Paragraph footText1 = doc.InsertParagraph("", false); footText1.Append("The top 3 teams will receive a "). Append("SPECTACULAR").Bold(). Append(" prize:"); footText1.Alignment = Alignment.center; Paragraph footText2 = doc.InsertParagraph("", false); footText2.Append("A HANDSHAKE FROM NAKOV").Color(Color.Blue).Bold().UnderlineColor(Color.Blue); footText2.Alignment = Alignment.center; doc.Save(); } }
public void Execute(object parameter) { string invoiceName; int maxId; using (var db = new InvoicesContext()) { if (!db.Invoices.Any()) { maxId = 0; } else { maxId = db.Invoices.Where(u => u.Created.Year == DateTime.Now.Year).OrderByDescending(u => u.InvoiceId).FirstOrDefault().InvoiceId; } invoiceName = $"FV_{++maxId}_{DateTime.Now.Year}"; } string fileName = string.Concat(AppDomain.CurrentDomain.BaseDirectory, invoiceName, ".docx"); var doc = DocX.Create(fileName); string docDate = DateTime.Now.ToString("dd/MM/yyyy").ToString(); int paymentDays = 14; string paymentType = "przelew"; doc.InsertParagraph($"Faktura nr {invoiceName.Replace("_", "/")}").Alignment = Alignment.right; doc.InsertParagraph($"Data wystawienia {docDate}").Alignment = Alignment.right; doc.InsertParagraph($"Termin płatności: {paymentDays.ToString()} dni").Alignment = Alignment.right; doc.InsertParagraph($"Metoda płatności: {paymentType}").Alignment = Alignment.right; doc.InsertParagraph("Sprzedawca:").Bold(); doc.InsertParagraph(Properties.Settings.Default.Name); doc.InsertParagraph($"{Properties.Settings.Default.Street} {Properties.Settings.Default.Number}"); doc.InsertParagraph($"{Properties.Settings.Default.PostalCode} {Properties.Settings.Default.City}"); doc.InsertParagraph($"NIP: {Properties.Settings.Default.NIP}"); if (!string.IsNullOrEmpty(Properties.Settings.Default.BankAccount)) { doc.InsertParagraph($"Nr rachunku do wpłat: {Properties.Settings.Default.BankAccount}"); } doc.InsertParagraph("Nabywca:").Bold().Alignment = Alignment.right; doc.InsertParagraph(this.vm.Customer.Name).Alignment = Alignment.right; doc.InsertParagraph(this.vm.Customer.Adress).Alignment = Alignment.right; doc.InsertParagraph($"NIP: {this.vm.Customer.Nip}").Alignment = Alignment.right; doc.InsertParagraph(); doc.InsertParagraph(); Table posTable = doc.AddTable(this.vm.Positions.Count + 1, 8); posTable.Rows[0].Cells[0].Paragraphs.First().Append("Lp."); posTable.Rows[0].Cells[1].Paragraphs.First().Append("Nazwa"); posTable.Rows[0].Cells[2].Paragraphs.First().Append("Jedn."); posTable.Rows[0].Cells[3].Paragraphs.First().Append("Ilość"); posTable.Rows[0].Cells[4].Paragraphs.First().Append("Cena netto"); posTable.Rows[0].Cells[5].Paragraphs.First().Append("Stawka VAT"); posTable.Rows[0].Cells[6].Paragraphs.First().Append("Wartość netto"); posTable.Rows[0].Cells[7].Paragraphs.First().Append("Wartość brutto"); foreach (Position item in this.vm.Positions) { item.RowIndex = this.vm.Positions.IndexOf(item) + 1; posTable.Rows[item.RowIndex].Cells[0].Paragraphs.First().Append($"{item.RowIndex.ToString()}."); posTable.Rows[item.RowIndex].Cells[1].Paragraphs.First().Append(item.Name); posTable.Rows[item.RowIndex].Cells[2].Paragraphs.First().Append(item.Unit); posTable.Rows[item.RowIndex].Cells[3].Paragraphs.First().Append(item.Quantity.ToString("F")); posTable.Rows[item.RowIndex].Cells[4].Paragraphs.First().Append(item.PriceNetto.ToString("F")); posTable.Rows[item.RowIndex].Cells[5].Paragraphs.First().Append($"{item.Vat.ToString()}%"); posTable.Rows[item.RowIndex].Cells[6].Paragraphs.First().Append(item.AmountNetto.ToString("F")); posTable.Rows[item.RowIndex].Cells[7].Paragraphs.First().Append(item.AmountBrutto.ToString("F")); } doc.InsertTable(posTable); doc.InsertParagraph(); doc.InsertParagraph(); double totalAmountBrutto = this.vm.Positions.Sum(x => x.AmountBrutto); double totalAmountNetto = this.vm.Positions.Sum(x => x.AmountNetto); doc.InsertParagraph($"Razem netto: {totalAmountNetto.ToString("F")} PLN").Alignment = Alignment.right; doc.InsertParagraph($"Razem brutto: {totalAmountBrutto.ToString("F")} PLN").Alignment = Alignment.right; doc.InsertParagraph("Zapłacono: 0,00 PLN").Alignment = Alignment.right; doc.InsertParagraph($"Do zapłaty: {totalAmountBrutto.ToString("F")} PLN").Alignment = Alignment.right; doc.InsertParagraph(); doc.InsertParagraph("Uwagi: W tytule przelewu proszę podać nr zamówienia."); doc.AddFooters(); var footerDefault = doc.Footers.Odd; footerDefault.InsertParagraph("…..………………........................... ..........................................................").Alignment = Alignment.center; footerDefault.InsertParagraph("Osoba upoważniona do obioru Osoba upoważniona do wystawienia").Alignment = Alignment.center; doc.Save(); Process.Start("WINWORD.EXE", "\"" + fileName + "\""); using (var db = new InvoicesContext()) { var invoice = new Invoice { Name = invoiceName, Created = DateTime.Now, SellerName = Properties.Settings.Default.Name, SellerNip = Properties.Settings.Default.NIP, CustomerName = this.vm.Customer.Name, CustomerAdress = this.vm.Customer.Adress, CustomerNip = this.vm.Customer.Nip, AmountBrutto = totalAmountBrutto.ToString() }; db.Invoices.Add(invoice); foreach (Position item in this.vm.Positions) { PositionDB posDB = new PositionDB { RowIndex = item.RowIndex, Name = item.Name, Unit = item.Unit, PriceNetto = item.PriceNetto, PriceBrutto = item.PriceBrutto.GetValueOrDefault(), Quantity = item.Quantity, Vat = item.Vat, AmountNetto = item.AmountNetto, AmountBrutto = item.AmountBrutto, Invoices = invoice }; db.Positions.Add(posDB); } db.SaveChanges(); this.vm.Invoices = new System.Collections.ObjectModel.ObservableCollection <Invoice>(db.Invoices); } this.vm.Positions.Clear(); }
public static void MakeDoc(string filePath) { string fileName = Path.Combine(filePath, Cproperties.DocxReportName + ".docx"); var doc = DocX.Create(fileName); doc.PageLayout.Orientation = Orientation.Landscape; //Create Table var getColumns = Cproperties.TableHeader.Length; var getRows = Cproperties.TableBody.Length + 1; var counter = 0; Table t = doc.AddTable(getRows, getColumns); t.Alignment = Alignment.center; t.Design = TableDesign.TableGrid; //Fill cells by adding text. //Header foreach (var item in Cproperties.TableHeader) { t.Rows[0].Cells[counter].Paragraphs.First().Append(item).Font("Verdana").FontSize(9D).Bold(); counter++; } try { //Content counter = 1; var zindex = 0; foreach (var item in Cproperties.TableBody) { if (item != null) { string[] helpArr = item.Split(';'); foreach (var set in helpArr) { t.Rows[counter].Cells[zindex].Paragraphs.First().Append(set); zindex++; } zindex = 0; counter++; } } } catch (System.Exception) { FrmMain.errString = FrmMain.errString + errPathOut + "@" + Cproperties.DocxReportName + Environment.NewLine; } Paragraph TabPar1 = doc.InsertParagraph(); TabPar1.Append("Test Case: " + Cproperties.ReportTestCaseName).Font((Font) new Font("Verdana")) .FontSize(12D) .Bold() .SpacingAfter(20); Paragraph TabPar = doc.InsertParagraph(); TabPar.InsertTableBeforeSelf(t); TabPar.SpacingAfter(20); TabPar.KeepLinesTogether(); if (Cproperties.FinalResult == "Passed") { TabPar.Append("\nFinal Result: " + Cproperties.FinalResult) .Font(new Font("Verdana")) .FontSize(10D) .Bold() .Color(Color.Green); } else if (Cproperties.FinalResult == "Failed") { TabPar.Append("\nFinal Result: " + Cproperties.FinalResult) .Font(new Font("Verdana")) .FontSize(10D) .Bold() .Color(Color.Red); } else { TabPar.Append("\nFinal Result: " + Cproperties.FinalResult) .Font(new Font("Verdana")) .FontSize(10D) .Bold() .Color(Color.Orange); } doc.AddFooters(); Footer footer = doc.Footers.Odd; footer.PageNumbers = true; //***Add a picture /*if (Cproperties.ArrayOfGraphics != null) * { * //Replace "Slash" with "Backslash" * Cproperties.ArrayOfGraphics = Cproperties.ArrayOfGraphics.Replace("/", "\\"); * * //Create array and check the length * string[] graphicArrayOutput = Cproperties.ArrayOfGraphics.Split(';'); * * int i = 1; * * if (graphicArrayOutput.Length > 1) * { * foreach (var item in graphicArrayOutput) * { * var pngPath = Path.Combine(FrmMain.TestcaseSourcePath, item); * Image img = doc.AddImage(pngPath); * Picture p = img.CreatePicture(); * Paragraph par = doc.InsertParagraph(); * par.AppendPicture(p).SpacingAfter(10D); * par.Append("\nGraphic " + i); * par.Bold(); * i++; * } * } * else * { * string[] arr = graphicArrayOutput[0].Split('@'); * var pngPath = Path.Combine(FrmMain.TestcaseSourcePath, graphicArrayOutput[0]); * Image img = doc.AddImage(pngPath); * Picture p = img.CreatePicture(); * Paragraph par = doc.InsertParagraph(); * par.AppendPicture(p).SpacingAfter(10D); * par.Append("\nGraphic " + i); * par.Bold(); * } * }*/ doc.Save(); FrmMain.ResetVariables(); }
/// <summary> /// Store both the document and xml so that they can be accessed by derived types. /// </summary> /// <param name="document">The document that this element belongs to.</param> /// <param name="xml">The Xml that gives this element substance</param> public DocXElement(DocX document, XElement xml) { this.Document = document; this.Xml = xml; }
private static void printThen(DocX document, SpecInfo spec) { document.InsertParagraph() .Append("Then") .Font(new FontFamily("Cambria")) .FontSize(13) .Bold() .Color(Color.FromArgb(255, 79, 129, 189)); foreach (var then in spec.Thens) { var description = spec.HasExecutionBeenTriggered ? string.Format("{0} [{1}]", then.Description, then.Passed ? "Passed" : "Failed") : then.Description; var p = document.InsertParagraph() .Append(description) .FontSize(12) .Color(spec.HasExecutionBeenTriggered ? (then.Passed ? Color.Green : Color.Red) : Color.Black); if (!then.Passed && then.Exception != null) p.AppendLine(then.Exception.ToString()); p.IndentationBefore = 0.5f; } }
public InsertBeforeOrAfter(DocX document, XElement xml) : base(document, xml) { }
public static DocX podstaw(this DocX doc, string key, object value) { doc.ReplaceText(key, value.ToString()); return(doc); }
private void exportToWord() { string path; using (SaveFileDialog saveFileDialog = new SaveFileDialog()) { saveFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); saveFileDialog.Filter = "Word 97-2003 Documents (*.doc)|*.doc|Word 2007 Documents (*.docx)|*.docx"; saveFileDialog.FilterIndex = 2; saveFileDialog.RestoreDirectory = true; if (saveFileDialog.ShowDialog() == DialogResult.OK) { path = saveFileDialog.FileName; using (var document = DocX.Create(path)) { for (int i = 0; i < 11; i++) { document.InsertParagraph("") .Font("Arial") .Bold(true) .FontSize(22d).Alignment = Alignment.left; } //Code for the Front page document.InsertParagraph("Acceptance Management Process \nFor " + projectModel.ProjectName) .Font("Arial") .Bold(true) .FontSize(22d).Alignment = Alignment.left; document.InsertSectionPageBreak(); //Code for the Front page //Code for the title of a page document.InsertParagraph("Document Control\n") .Font("Arial") .Bold(true) .FontSize(14d).Alignment = Alignment.left; //Code for the title of a page //Code for a space document.InsertParagraph("") .Font("Arial") .Bold(true) .FontSize(14d).Alignment = Alignment.left; //Code for a space //Code of a sentence document.InsertParagraph("Document Information\n") .Font("Arial") .Bold(true) .FontSize(14d).Alignment = Alignment.left; //Code of a sentence //Code for a table var documentInfoTable = document.AddTable(6, 2); documentInfoTable.Rows[0].Cells[0].Paragraphs[0].Append("").Bold(true).Color(Color.White); documentInfoTable.Rows[0].Cells[1].Paragraphs[0].Append("Information").Bold(true).Color(Color.White); documentInfoTable.Rows[0].Cells[0].FillColor = TABLE_HEADER_COLOR; documentInfoTable.Rows[0].Cells[1].FillColor = TABLE_HEADER_COLOR; documentInfoTable.Rows[1].Cells[0].Paragraphs[0].Append("Document ID"); documentInfoTable.Rows[1].Cells[1].Paragraphs[0].Append(currentAcceptanceManagementProcessModel.DocumentID); documentInfoTable.Rows[2].Cells[0].Paragraphs[0].Append("Document Owner"); documentInfoTable.Rows[2].Cells[1].Paragraphs[0].Append(currentAcceptanceManagementProcessModel.DocumentOwner); documentInfoTable.Rows[3].Cells[0].Paragraphs[0].Append("Issue Date"); documentInfoTable.Rows[3].Cells[1].Paragraphs[0].Append(currentAcceptanceManagementProcessModel.IssueDate); documentInfoTable.Rows[4].Cells[0].Paragraphs[0].Append("Last Saved Date"); documentInfoTable.Rows[4].Cells[1].Paragraphs[0].Append(currentAcceptanceManagementProcessModel.LastSavedDate); documentInfoTable.Rows[5].Cells[0].Paragraphs[0].Append("File Name"); documentInfoTable.Rows[5].Cells[1].Paragraphs[0].Append(currentAcceptanceManagementProcessModel.FileName); documentInfoTable.SetWidths(new float[] { 493, 1094 }); document.InsertTable(documentInfoTable); //Code for a table //Code of a sentence document.InsertParagraph("\nDocument History\n") .Font("Arial") .Bold(true) .FontSize(14d).Alignment = Alignment.left; //Code of a sentence //Code for a table var documentHistoryTable = document.AddTable(currentAcceptanceManagementProcessModel.DocumentHistories.Count + 1, 3); documentHistoryTable.Rows[0].Cells[0].Paragraphs[0].Append("Version") .Bold(true) .Color(Color.White); documentHistoryTable.Rows[0].Cells[1].Paragraphs[0].Append("Issue Date") .Bold(true) .Color(Color.White); documentHistoryTable.Rows[0].Cells[2].Paragraphs[0].Append("Changes") .Bold(true) .Color(Color.White); documentHistoryTable.Rows[0].Cells[0].FillColor = TABLE_HEADER_COLOR; documentHistoryTable.Rows[0].Cells[1].FillColor = TABLE_HEADER_COLOR; documentHistoryTable.Rows[0].Cells[2].FillColor = TABLE_HEADER_COLOR; for (int i = 1; i < currentAcceptanceManagementProcessModel.DocumentHistories.Count + 1; i++) { documentHistoryTable.Rows[i].Cells[0].Paragraphs[0].Append(currentAcceptanceManagementProcessModel.DocumentHistories[i - 1].Version); documentHistoryTable.Rows[i].Cells[1].Paragraphs[0].Append(currentAcceptanceManagementProcessModel.DocumentHistories[i - 1].IssueDate); documentHistoryTable.Rows[i].Cells[2].Paragraphs[0].Append(currentAcceptanceManagementProcessModel.DocumentHistories[i - 1].Changes); } documentHistoryTable.SetWidths(new float[] { 190, 303, 1094 }); document.InsertTable(documentHistoryTable); //Code for a table //Code of a sentence document.InsertParagraph("\nDocument Approvals\n") .Font("Arial") .Bold(true) .FontSize(14d).Alignment = Alignment.left; //Code of a sentence //Code for a table var documentApprovalTable = document.AddTable(currentAcceptanceManagementProcessModel.DocumentApprovals.Count + 1, 4); documentApprovalTable.Rows[0].Cells[0].Paragraphs[0].Append("Role") .Bold(true) .Color(Color.White); documentApprovalTable.Rows[0].Cells[1].Paragraphs[0].Append("Name") .Bold(true) .Color(Color.White); documentApprovalTable.Rows[0].Cells[2].Paragraphs[0].Append("Signature") .Bold(true) .Color(Color.White); documentApprovalTable.Rows[0].Cells[3].Paragraphs[0].Append("Date") .Bold(true) .Color(Color.White); documentApprovalTable.Rows[0].Cells[0].FillColor = TABLE_HEADER_COLOR; documentApprovalTable.Rows[0].Cells[1].FillColor = TABLE_HEADER_COLOR; documentApprovalTable.Rows[0].Cells[2].FillColor = TABLE_HEADER_COLOR; documentApprovalTable.Rows[0].Cells[3].FillColor = TABLE_HEADER_COLOR; for (int i = 1; i < currentAcceptanceManagementProcessModel.DocumentApprovals.Count + 1; i++) { documentApprovalTable.Rows[i].Cells[0].Paragraphs[0].Append(currentAcceptanceManagementProcessModel.DocumentApprovals[i - 1].Role); documentApprovalTable.Rows[i].Cells[1].Paragraphs[0].Append(currentAcceptanceManagementProcessModel.DocumentApprovals[i - 1].Name); documentApprovalTable.Rows[i].Cells[2].Paragraphs[0].Append(currentAcceptanceManagementProcessModel.DocumentApprovals[i - 1].Signature); documentApprovalTable.Rows[i].Cells[3].Paragraphs[0].Append(currentAcceptanceManagementProcessModel.DocumentApprovals[i - 1].DateApproved); } documentApprovalTable.SetWidths(new float[] { 493, 332, 508, 254 }); document.InsertTable(documentApprovalTable); //Code for a table //Code for a page break document.InsertParagraph().InsertPageBreakAfterSelf(); //Code for a page break //Code for a table of contents var p = document.InsertParagraph(); var title = p.InsertParagraphBeforeSelf("Table of Contents").Bold().FontSize(20); var tocSwitches = new Dictionary <TableOfContentsSwitches, string>() { { TableOfContentsSwitches.O, "1-3" }, { TableOfContentsSwitches.U, "" }, { TableOfContentsSwitches.Z, "" }, { TableOfContentsSwitches.H, "" } }; document.InsertTableOfContents(p, "", tocSwitches); //Code for a table of contents //Code for a page break document.InsertParagraph().InsertPageBreakAfterSelf(); //Code for a page break // Code for a heading 1 var AcceptanceProcessHeading = document.InsertParagraph("1 Acceptance Process") .Bold() .FontSize(14d) .Color(Color.Black) .Bold(true) .Font("Arial"); AcceptanceProcessHeading.StyleId = "Heading1"; //Code for a heading 1 //Code for a heading 2 var OverviewSubHeading = document.InsertParagraph("1.1 Overview") .Bold() .FontSize(12d) .Color(Color.Black) .Bold(true) .Font("Arial"); OverviewSubHeading.StyleId = "Heading2"; //Code for a heading 2 //Code for a sentence document.InsertParagraph(currentAcceptanceManagementProcessModel.AcceptanceprocessOverview) .FontSize(11d) .Color(Color.Black) .Font("Arial").Alignment = Alignment.left; //Code for a sentence //Code for a heading 2 var CompleteDeliverableAchievedHeading = document.InsertParagraph("1.2 Complete Deliverable") .Bold() .FontSize(12d) .Color(Color.Black) .Bold(true) .Font("Arial"); CompleteDeliverableAchievedHeading.StyleId = "Heading2"; //Code for a heading 2 //Code for a sentence document.InsertParagraph(currentAcceptanceManagementProcessModel.AcceptanceprocessCompleteDeliverable) .FontSize(11d) .Color(Color.Black) .Font("Arial").Alignment = Alignment.left; //Code for a sentence //Code for a heading 2 var CompleteAcceptanceTestHeading = document.InsertParagraph("1.3 Complete Acceptance Test") .Bold() .FontSize(12d) .Color(Color.Black) .Bold(true) .Font("Arial"); CompleteAcceptanceTestHeading.StyleId = "Heading2"; //Code for a heading 2 //Code for a sentence document.InsertParagraph(currentAcceptanceManagementProcessModel.AcceptanceprocessCompleteAcceptanceTest) .FontSize(11d) .Color(Color.Black) .Font("Arial").Alignment = Alignment.left; //Code for a sentence //Code for a heading 2 var AcceptDeliverableHeading = document.InsertParagraph("1.4 Acceptance Deliverable") .Bold() .FontSize(12d) .Color(Color.Black) .Bold(true) .Font("Arial"); AcceptDeliverableHeading.StyleId = "Heading2"; //Code for a heading 2 //Code for a sentence document.InsertParagraph(currentAcceptanceManagementProcessModel.AcceptanceprocessAcceptDeliverable) .FontSize(11d) .Color(Color.Black) .Font("Arial").Alignment = Alignment.left; //Code for a sentence //Code for a heading 2 var AcceptProcessDescHeading = document.InsertParagraph("1.5 Acceptance Process Description") .Bold() .FontSize(12d) .Color(Color.Black) .Bold(true) .Font("Arial"); AcceptProcessDescHeading.StyleId = "Heading2"; //Code for a heading 2 //Code for a sentence document.InsertParagraph(currentAcceptanceManagementProcessModel.AcceptanceprocessDescription) .FontSize(11d) .Color(Color.Black) .Font("Arial").Alignment = Alignment.left; //Code for a sentence // Code for a heading 1 var AcceptanceRolesHeading = document.InsertParagraph("2 Acceptance Roles") .Bold() .FontSize(14d) .Color(Color.Black) .Bold(true) .Font("Arial"); AcceptanceRolesHeading.StyleId = "Heading1"; //Code for a heading 1 //Code for a heading 2 var ProjectManagerHeading = document.InsertParagraph("2.1 Project Manager") .Bold() .FontSize(12d) .Color(Color.Black) .Bold(true) .Font("Arial"); ProjectManagerHeading.StyleId = "Heading2"; //Code for a heading 2 //Code for a sentence document.InsertParagraph(currentAcceptanceManagementProcessModel.AcceptancerolesProjectManager) .FontSize(11d) .Color(Color.Black) .Font("Arial").Alignment = Alignment.left; //Code for a sentence //Code for a heading 2 var CustomerHeading = document.InsertParagraph("2.2 Customer") .Bold() .FontSize(12d) .Color(Color.Black) .Bold(true) .Font("Arial"); CustomerHeading.StyleId = "Heading2"; //Code for a heading 2 //Code for a sentence document.InsertParagraph(currentAcceptanceManagementProcessModel.AcceptancerolesCustomer) .FontSize(11d) .Color(Color.Black) .Font("Arial").Alignment = Alignment.left; //Code for a sentence //Code for a heading 2 var AcceptRoleDescHeading = document.InsertParagraph("2.3 Acceptance Roles Description") .Bold() .FontSize(12d) .Color(Color.Black) .Bold(true) .Font("Arial"); AcceptRoleDescHeading.StyleId = "Heading2"; //Code for a heading 2 //Code for a sentence document.InsertParagraph(currentAcceptanceManagementProcessModel.AcceptancerolesDescription) .FontSize(11d) .Color(Color.Black) .Font("Arial").Alignment = Alignment.left; //Code for a sentence // Code for a heading 1 var AcceptanceDocumentsHeading = document.InsertParagraph("3 Acceptance Documents") .Bold() .FontSize(14d) .Color(Color.Black) .Bold(true) .Font("Arial"); AcceptanceDocumentsHeading.StyleId = "Heading1"; //Code for a heading 1 //Code for a heading 2 var AcceptanceFormHeading = document.InsertParagraph("3.1 Acceptance Form") .Bold() .FontSize(12d) .Color(Color.Black) .Bold(true) .Font("Arial"); AcceptanceFormHeading.StyleId = "Heading2"; //Code for a heading 2 //Code for a sentence document.InsertParagraph(currentAcceptanceManagementProcessModel.AcceptancedocumentsAcceptanceForm) .FontSize(11d) .Color(Color.Black) .Font("Arial").Alignment = Alignment.left; //Code for a sentence //Code for a heading 2 var AcceptanceRegisterHeading = document.InsertParagraph("3.2 Acceptance Register") .Bold() .FontSize(12d) .Color(Color.Black) .Bold(true) .Font("Arial"); AcceptanceRegisterHeading.StyleId = "Heading2"; //Code for a heading 2 //Code for a sentence document.InsertParagraph(currentAcceptanceManagementProcessModel.AcceptancedocumentsAcceptanceRegister) .FontSize(11d) .Color(Color.Black) .Font("Arial").Alignment = Alignment.left; //Code for a sentence //Code for a heading 2 var AcceptDocumentDescHeading = document.InsertParagraph("3.3 Acceptance Documents Description") .Bold() .FontSize(12d) .Color(Color.Black) .Bold(true) .Font("Arial"); AcceptDocumentDescHeading.StyleId = "Heading2"; //Code for a heading 2 //Code for a sentence document.InsertParagraph(currentAcceptanceManagementProcessModel.AcceptancedocumentsDescription) .FontSize(11d) .Color(Color.Black) .Font("Arial").Alignment = Alignment.left; //Code for a sentence //Code for saving try { document.Save(); } catch (Exception) { MessageBox.Show("The selected File is open.", "Close File", MessageBoxButtons.OK, MessageBoxIcon.Error); } //Code for saving } } } }
private void exportToWord() { string path; using (SaveFileDialog saveFileDialog = new SaveFileDialog()) { saveFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); saveFileDialog.Filter = "Word 97-2003 Documents (*.doc)|*.doc|Word 2007 Documents (*.docx)|*.docx"; saveFileDialog.FilterIndex = 2; saveFileDialog.RestoreDirectory = true; if (saveFileDialog.ShowDialog() == DialogResult.OK) { path = saveFileDialog.FileName; using (var document = DocX.Create(path)) { for (int i = 0; i < 11; i++) { document.InsertParagraph("") .Font("Arial") .Bold(true) .FontSize(22d).Alignment = Alignment.left; } document.InsertParagraph("Communication Plan \nFor " + projectModel.ProjectName) .Font("Arial") .Bold(true) .FontSize(22d).Alignment = Alignment.left; document.InsertSectionPageBreak(); document.InsertParagraph("Document Control\n") .Font("Arial") .Bold(true) .FontSize(14d).Alignment = Alignment.left; document.InsertParagraph("") .Font("Arial") .Bold(true) .FontSize(14d).Alignment = Alignment.left; document.InsertParagraph("Document Information\n") .Font("Arial") .Bold(true) .FontSize(14d).Alignment = Alignment.left; var documentInfoTable = document.AddTable(6, 2); documentInfoTable.Rows[0].Cells[0].Paragraphs[0].Append("").Bold(true).Color(Color.White); documentInfoTable.Rows[0].Cells[1].Paragraphs[0].Append("Information").Bold(true).Color(Color.White); documentInfoTable.Rows[0].Cells[0].FillColor = TABLE_HEADER_COLOR; documentInfoTable.Rows[0].Cells[1].FillColor = TABLE_HEADER_COLOR; documentInfoTable.Rows[1].Cells[0].Paragraphs[0].Append("Document ID"); documentInfoTable.Rows[1].Cells[1].Paragraphs[0].Append(currentCommunicationsPlanModel.DocumentID); documentInfoTable.Rows[2].Cells[0].Paragraphs[0].Append("Document Owner"); documentInfoTable.Rows[2].Cells[1].Paragraphs[0].Append(currentCommunicationsPlanModel.DocumentOwner); documentInfoTable.Rows[3].Cells[0].Paragraphs[0].Append("Issue Date"); documentInfoTable.Rows[3].Cells[1].Paragraphs[0].Append(currentCommunicationsPlanModel.IssueDate); documentInfoTable.Rows[4].Cells[0].Paragraphs[0].Append("Last Saved Date"); documentInfoTable.Rows[4].Cells[1].Paragraphs[0].Append(currentCommunicationsPlanModel.LastSavedDate); documentInfoTable.Rows[5].Cells[0].Paragraphs[0].Append("File Name"); documentInfoTable.Rows[5].Cells[1].Paragraphs[0].Append(currentCommunicationsPlanModel.FileName); documentInfoTable.SetWidths(new float[] { 493, 1094 }); document.InsertTable(documentInfoTable); document.InsertParagraph("\nDocument History\n") .Font("Arial") .Bold(true) .FontSize(14d).Alignment = Alignment.left; var documentHistoryTable = document.AddTable(currentCommunicationsPlanModel.DocumentHistories.Count + 1, 3); documentHistoryTable.Rows[0].Cells[0].Paragraphs[0].Append("Version") .Bold(true) .Color(Color.White); documentHistoryTable.Rows[0].Cells[1].Paragraphs[0].Append("Issue Date") .Bold(true) .Color(Color.White); documentHistoryTable.Rows[0].Cells[2].Paragraphs[0].Append("Changes") .Bold(true) .Color(Color.White); documentHistoryTable.Rows[0].Cells[0].FillColor = TABLE_HEADER_COLOR; documentHistoryTable.Rows[0].Cells[1].FillColor = TABLE_HEADER_COLOR; documentHistoryTable.Rows[0].Cells[2].FillColor = TABLE_HEADER_COLOR; for (int i = 1; i < currentCommunicationsPlanModel.DocumentHistories.Count + 1; i++) { documentHistoryTable.Rows[i].Cells[0].Paragraphs[0].Append(currentCommunicationsPlanModel.DocumentHistories[i - 1].Version); documentHistoryTable.Rows[i].Cells[1].Paragraphs[0].Append(currentCommunicationsPlanModel.DocumentHistories[i - 1].IssueDate); documentHistoryTable.Rows[i].Cells[2].Paragraphs[0].Append(currentCommunicationsPlanModel.DocumentHistories[i - 1].Changes); } documentHistoryTable.SetWidths(new float[] { 190, 303, 104 }); document.InsertTable(documentHistoryTable); document.InsertParagraph("\nDocument Approvals\n") .Font("Arial") .Bold(true) .FontSize(14d).Alignment = Alignment.left; var documentApprovalTable = document.AddTable(currentCommunicationsPlanModel.DocumentApprovals.Count + 1, 4); documentApprovalTable.Rows[0].Cells[0].Paragraphs[0].Append("Role") .Bold(true) .Color(Color.White); documentApprovalTable.Rows[0].Cells[1].Paragraphs[0].Append("Name") .Bold(true) .Color(Color.White); documentApprovalTable.Rows[0].Cells[2].Paragraphs[0].Append("Signature") .Bold(true) .Color(Color.White); documentApprovalTable.Rows[0].Cells[3].Paragraphs[0].Append("Date") .Bold(true) .Color(Color.White); documentApprovalTable.Rows[0].Cells[0].FillColor = TABLE_HEADER_COLOR; documentApprovalTable.Rows[0].Cells[1].FillColor = TABLE_HEADER_COLOR; documentApprovalTable.Rows[0].Cells[2].FillColor = TABLE_HEADER_COLOR; documentApprovalTable.Rows[0].Cells[3].FillColor = TABLE_HEADER_COLOR; for (int i = 1; i < currentCommunicationsPlanModel.DocumentApprovals.Count + 1; i++) { documentApprovalTable.Rows[i].Cells[0].Paragraphs[0].Append(currentCommunicationsPlanModel.DocumentApprovals[i - 1].Role); documentApprovalTable.Rows[i].Cells[1].Paragraphs[0].Append(currentCommunicationsPlanModel.DocumentApprovals[i - 1].Name); documentApprovalTable.Rows[i].Cells[2].Paragraphs[0].Append(currentCommunicationsPlanModel.DocumentApprovals[i - 1].Signature); documentApprovalTable.Rows[i].Cells[3].Paragraphs[0].Append(currentCommunicationsPlanModel.DocumentApprovals[i - 1].DateApproved); } documentApprovalTable.SetWidths(new float[] { 493, 332, 508, 254 }); document.InsertTable(documentApprovalTable); document.InsertParagraph().InsertPageBreakAfterSelf(); var p = document.InsertParagraph(); var title = p.InsertParagraphBeforeSelf("Table of Contents").Bold().FontSize(20); var tocSwitches = new Dictionary <TableOfContentsSwitches, string>() { { TableOfContentsSwitches.O, "1-3" }, { TableOfContentsSwitches.U, "" }, { TableOfContentsSwitches.Z, "" }, { TableOfContentsSwitches.H, "" } }; document.InsertTableOfContents(p, "", tocSwitches); document.InsertParagraph().InsertPageBreakAfterSelf(); var CommunicationReqHeading = document.InsertParagraph("1 Communication Requirements") .Bold() .FontSize(14d) .Color(Color.Black) .Bold(true) .Font("Arial"); CommunicationReqHeading.StyleId = "Heading1"; var CommunicationListSubHeading = document.InsertParagraph("1.1 Stakeholder List") .Bold() .FontSize(12d) .Color(Color.Black) .Bold(true) .Font("Arial"); CommunicationListSubHeading.StyleId = "Heading2"; document.InsertParagraph(currentCommunicationsPlanModel.StakeholderList) .FontSize(11d) .Color(Color.Black) .Font("Arial").Alignment = Alignment.left; var CommunicationReqSubHeading = document.InsertParagraph("1.2 Stakeholder Requirement") .Bold() .FontSize(12d) .Color(Color.Black) .Bold(true) .Font("Arial"); CommunicationReqSubHeading.StyleId = "Heading2"; var documentStakeholderReq = document.AddTable(currentCommunicationsPlanModel.StakeholderReq.Count + 1, 4); documentStakeholderReq.Rows[0].Cells[0].Paragraphs[0].Append("Stakeholder Name") .Bold(true) .Color(Color.White); documentStakeholderReq.Rows[0].Cells[1].Paragraphs[0].Append("Stakeholder Role") .Bold(true) .Color(Color.White); documentStakeholderReq.Rows[0].Cells[2].Paragraphs[0].Append("Stakeholder Organization") .Bold(true) .Color(Color.White); documentStakeholderReq.Rows[0].Cells[3].Paragraphs[0].Append("Information Required") .Bold(true) .Color(Color.White); documentStakeholderReq.Rows[0].Cells[0].FillColor = TABLE_HEADER_COLOR; documentStakeholderReq.Rows[0].Cells[1].FillColor = TABLE_HEADER_COLOR; documentStakeholderReq.Rows[0].Cells[2].FillColor = TABLE_HEADER_COLOR; documentStakeholderReq.Rows[0].Cells[3].FillColor = TABLE_HEADER_COLOR; for (int i = 1; i < currentCommunicationsPlanModel.StakeholderReq.Count + 1; i++) { documentStakeholderReq.Rows[i].Cells[0].Paragraphs[0].Append(currentCommunicationsPlanModel.StakeholderReq[i - 1].StakeholderName); documentStakeholderReq.Rows[i].Cells[1].Paragraphs[0].Append(currentCommunicationsPlanModel.StakeholderReq[i - 1].StakeholderRole); documentStakeholderReq.Rows[i].Cells[2].Paragraphs[0].Append(currentCommunicationsPlanModel.StakeholderReq[i - 1].StakeholderOrganization); documentStakeholderReq.Rows[i].Cells[3].Paragraphs[0].Append(currentCommunicationsPlanModel.StakeholderReq[i - 1].InformationRequirement); } documentStakeholderReq.SetWidths(new float[] { 762, 762, 762, 762 }); document.InsertTable(documentStakeholderReq); var CommunicationPlanHeading = document.InsertParagraph("2 Communications Plan") .Bold() .FontSize(14d) .Color(Color.Black) .Bold(true) .Font("Arial"); CommunicationPlanHeading.StyleId = "Heading1"; var scheSubHeading = document.InsertParagraph("2.1 Project Schedule") .Bold() .FontSize(14d) .Color(Color.Black) .Bold(true) .Font("Arial"); scheSubHeading.StyleId = "Heading2"; var scheDoc = document.AddTable(currentCommunicationsPlanModel.ProSchedule.Count + 1, 7); scheDoc.Rows[0].Cells[0].Paragraphs[0].Append("Deliverable") .Bold(true) .Color(Color.White); scheDoc.Rows[0].Cells[1].Paragraphs[0].Append("Scheduled Completion Date") .Bold(true) .Color(Color.White); scheDoc.Rows[0].Cells[2].Paragraphs[0].Append("Actual Completion Date") .Bold(true) .Color(Color.White); scheDoc.Rows[0].Cells[3].Paragraphs[0].Append("Actual Variance") .Bold(true) .Color(Color.White); scheDoc.Rows[0].Cells[4].Paragraphs[0].Append("Forecast Completion Date") .Bold(true) .Color(Color.White); scheDoc.Rows[0].Cells[5].Paragraphs[0].Append("Forecast Variance") .Bold(true) .Color(Color.White); scheDoc.Rows[0].Cells[6].Paragraphs[0].Append("Summary") .Bold(true) .Color(Color.White); scheDoc.Rows[0].Cells[0].FillColor = TABLE_HEADER_COLOR; scheDoc.Rows[0].Cells[1].FillColor = TABLE_HEADER_COLOR; scheDoc.Rows[0].Cells[2].FillColor = TABLE_HEADER_COLOR; scheDoc.Rows[0].Cells[3].FillColor = TABLE_HEADER_COLOR; scheDoc.Rows[0].Cells[4].FillColor = TABLE_HEADER_COLOR; scheDoc.Rows[0].Cells[5].FillColor = TABLE_HEADER_COLOR; scheDoc.Rows[0].Cells[6].FillColor = TABLE_HEADER_COLOR; for (int i = 1; i < currentCommunicationsPlanModel.ProSchedule.Count + 1; i++) { scheDoc.Rows[i].Cells[0].Paragraphs[0].Append(currentCommunicationsPlanModel.ProSchedule[i - 1].Deliverable); scheDoc.Rows[i].Cells[1].Paragraphs[0].Append(currentCommunicationsPlanModel.ProSchedule[i - 1].ScheduledCompletionDate); scheDoc.Rows[i].Cells[2].Paragraphs[0].Append(currentCommunicationsPlanModel.ProSchedule[i - 1].ActualCompletionDate); scheDoc.Rows[i].Cells[3].Paragraphs[0].Append(currentCommunicationsPlanModel.ProSchedule[i - 1].ActualVariance); scheDoc.Rows[i].Cells[4].Paragraphs[0].Append(currentCommunicationsPlanModel.ProSchedule[i - 1].ForecastCompletionDate); scheDoc.Rows[i].Cells[5].Paragraphs[0].Append(currentCommunicationsPlanModel.ProSchedule[i - 1].ForecastVariance); scheDoc.Rows[i].Cells[6].Paragraphs[0].Append(currentCommunicationsPlanModel.ProSchedule[i - 1].Summary); } scheDoc.SetWidths(new float[] { 394, 762, 762, 762, 762, 762, 762 }); document.InsertTable(scheDoc); var ComPlanHeading = document.InsertParagraph("2.2 Assumption") .Bold() .FontSize(12d) .Color(Color.Black) .Bold(true) .Font("Arial"); document.InsertParagraph(currentCommunicationsPlanModel.Assumptions) .FontSize(11d) .Color(Color.Black) .Font("Arial").Alignment = Alignment.left; ComPlanHeading.StyleId = "Heading2"; var CommunicationProcessHeading = document.InsertParagraph("3 Communications Process") .Bold() .FontSize(14d) .Color(Color.Black) .Bold(true) .Font("Arial"); CommunicationReqHeading.StyleId = "Heading1"; var ProcessHeading = document.InsertParagraph("3.1 Communications Process") .Bold() .FontSize(12d) .Color(Color.Black) .Bold(true) .Font("Arial"); document.InsertParagraph(currentCommunicationsPlanModel.ComProcess) .FontSize(11d) .Color(Color.Black) .Font("Arial").Alignment = Alignment.left; ProcessHeading.StyleId = "Heading2"; var ActivitiesHeading = document.InsertParagraph("3.2 Activities") .Bold() .FontSize(12d) .Color(Color.Black) .Bold(true) .Font("Arial"); document.InsertParagraph(currentCommunicationsPlanModel.Activities) .FontSize(11d) .Color(Color.Black) .Font("Arial").Alignment = Alignment.left; ActivitiesHeading.StyleId = "Heading2"; var RolesHeading = document.InsertParagraph("3.3 Roles") .Bold() .FontSize(12d) .Color(Color.Black) .Bold(true) .Font("Arial"); document.InsertParagraph(currentCommunicationsPlanModel.Roles) .FontSize(11d) .Color(Color.Black) .Font("Arial").Alignment = Alignment.left; RolesHeading.StyleId = "Heading2"; var DocumentsHeading = document.InsertParagraph("3.4 Documents") .Bold() .FontSize(12d) .Color(Color.Black) .Bold(true) .Font("Arial"); document.InsertParagraph(currentCommunicationsPlanModel.Documents) .FontSize(11d) .Color(Color.Black) .Font("Arial").Alignment = Alignment.left; RolesHeading.StyleId = "Heading2"; try { document.Save(); } catch (Exception) { MessageBox.Show("The selected File is open.", "Close File", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } } }
void PutStringIntoTable(string fileLocation) { DocX document = DocX.Load(fileLocation); Table tb = document.Tables[1]; int index = 0; string toTruong = ""; string giamSat1 = ""; string giamSat2 = ""; string laiXe = ""; string baoVe = ""; if (cbToTruong.SelectedItem != null) { index++; var u = users[cbToTruong.SelectedIndex]; string gt = "Ông"; if (!u.gioiTinh) gt = "Bà"; string pb = Thong_tin_dang_nhap.ten_cn; if (u.chucvu != "Giám đốc" && u.chucvu != "Phó Giám đốc") pb = Thong_tin_dang_nhap.tenPb; toTruong = index + ". " + gt + ": " + u.tennv + ", Số hộ chiếu/CMND/CCCD: " + txtCMNDToTruong.Text + " Ngày cấp: " + txtNgayCapToTruong.Text + " Nơi cấp: " + txtNoiCapToTruong.Text + "; Chức vụ: " + u.chucvu + " " + pb + "; Chức danh: Tổ trưởng;"; tb.Rows[0].Cells[0].Paragraphs[0].InsertText(toTruong); } if (cbGiamSat1.SelectedItem != null) { index++; var u = users[cbGiamSat1.SelectedIndex]; string gt = "Ông"; if (!u.gioiTinh) gt = "Bà"; string pb = Thong_tin_dang_nhap.ten_cn; if (u.chucvu != "Giám đốc" && u.chucvu != "Phó Giám đốc") pb = Thong_tin_dang_nhap.tenPb; giamSat1 = index + ". " + gt + ": " + u.tennv + ", Số hộ chiếu/CMND/CCCD: " + txtCMNDGiamSat1.Text + " Ngày cấp: " + txtNgayCapGiamSat1.Text + " Nơi cấp: " + txtNoiCapGiamSat1.Text + "; Chức vụ: " + u.chucvu + " " + pb + "; Chức danh: Giám sát;"; Row row = tb.InsertRow(); row.Cells[0].Paragraphs.First().Append(giamSat1); tb.Rows.Add(row); } listDich.Add("<GIAM_SAT_2>"); if (cbGiamSat2.SelectedItem != null) { index++; var u = users[cbGiamSat2.SelectedIndex]; string gt = "Ông"; if (!u.gioiTinh) gt = "Bà"; string pb = Thong_tin_dang_nhap.ten_cn; if (u.chucvu != "Giám đốc" && u.chucvu != "Phó Giám đốc") pb = Thong_tin_dang_nhap.tenPb; listNguon.Add(index + ". " + gt + ": " + u.tennv + ", Số hộ chiếu/CMND/CCCD: " + txtCMNDGiamSat2.Text + " Ngày cấp: " + txtNgayCapGiamSat2.Text + " Nơi cấp: " + txtNoiCapGiamSat2.Text + "; Chức vụ: " + u.chucvu + " " + pb + "; Chức danh: Giám sát;"); Row row = tb.InsertRow(); row.Cells[0].Paragraphs.First().Append(giamSat2); tb.Rows.Add(row); } //Lai xe if (!string.IsNullOrEmpty(txtHoTenLaiXe.Text)) { index++; listDich.Add("<LAI_XE>"); laiXe = index + ". " + "Ông/Bà: " + txtHoTenLaiXe.Text + ", Số hộ chiếu/CMND/CCCD: " + txtCMNDLaiXe.Text + " Ngày cấp: " + txtNgayCapLaiXe.Text + ",Nơi cấp: " + txtNoiCapLaiXe.Text + ";Chức danh: Lái xe;"; Row row = tb.InsertRow(); row.Cells[0].Paragraphs.First().Append(laiXe); tb.Rows.Add(row); } //Bao ve if (!string.IsNullOrEmpty(txtHoTenBaoVe.Text)) { index++; listDich.Add("<BAO_VE>"); baoVe = index + ". " + "Ông/Bà: " + txtHoTenLaiXe.Text + ", Số hộ chiếu/CMND/CCCD: " + txtCMNDLaiXe.Text + " Ngày cấp: " + txtNgayCapLaiXe.Text + ",Nơi cấp: " + txtNoiCapLaiXe.Text + ";Chức danh: Bảo vệ;"; Row row = tb.InsertRow(); row.Cells[0].Paragraphs.First().Append(baoVe); tb.Rows.Add(row); } document.Save(); }
private void btCargaDevolução_Click(object sender, EventArgs e) { if (txtIdVendedor.Text != "") { if (cbbPraça.SelectedItem != null) { if (txtDataFinal.Text != "" && txtDataInicial.Text != "") { DateTime dataInicial = DateTime.Parse(txtDataInicial.Text); DateTime dataFinal = DateTime.Parse(txtDataFinal.Text); string query = "select * from CargaDevolução where CargaDevolução.VendedorID == " + txtIdVendedor.Text + " and date(CargaDevolução.Data) BETWEEN date('" + dataInicial.Year + "-" + dataInicial.Month.ToString("00") + "-" + dataInicial.Day.ToString("00") + "') and date('" + dataFinal.Year + "-" + dataFinal.Month.ToString("00") + "-" + dataFinal.Day.ToString("00") + "') order by CargaDevolução.Data"; cargaDevoluçãoList = SqliteAcessoDados.LoadQuery <CargaDevoluçãoModelo>(query); } else { cargaDevoluçãoList = SqliteAcessoDados.LoadQuery <CargaDevoluçãoModelo>("select * from CargaDevolução where CargaDevolução.VendedorID == " + txtIdVendedor.Text + " order by CargaDevolução.Data"); } if (cargaDevoluçãoList.Count > 0) { string docPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\Relatorios"; VendedorModelo vendedor = SqliteAcessoDados.LoadQuery <VendedorModelo>("select * from Vendedor where Vendedor.ID == " + txtIdVendedor.Text).First(); PessoaModelo vendedorPessoa = SqliteAcessoDados.LoadQuery <PessoaModelo>("select * from Pessoa where Pessoa.ID == " + vendedor.PessoaId.ToString()).First(); string fileName = "Cargas e Devoluções - Vendedor - " + vendedorPessoa.Nome + " - Praça - " + cbbPraça.SelectedItem.ToString() + " - "; if (txtDataFinal.Text != "" && txtDataInicial.Text != "") { if (txtDataFinal.Text == txtDataInicial.Text) { fileName += DateTime.Parse(txtDataFinal.Text).Day.ToString() + "_" + DateTime.Parse(txtDataFinal.Text).Month.ToString() + "_" + DateTime.Parse(txtDataFinal.Text).Year.ToString(); } else { fileName += "De - " + DateTime.Parse(txtDataFinal.Text).Day.ToString() + "_" + DateTime.Parse(txtDataFinal.Text).Month.ToString() + "_" + DateTime.Parse(txtDataFinal.Text).Year.ToString() + " - Até - " + DateTime.Parse(txtDataInicial.Text).Day.ToString() + "_" + DateTime.Parse(txtDataInicial.Text).Month.ToString() + "_" + DateTime.Parse(txtDataInicial.Text).Year.ToString(); } } else { fileName += "Todas as Datas"; } fileName += ".docx"; System.IO.Directory.CreateDirectory(docPath); docPath = System.IO.Path.Combine(docPath, fileName); using (var document = DocX.Create(docPath)) { document.InsertParagraph("SABOR MINEIRO - RELATÓRIO").FontSize(11d).Bold().Alignment = Alignment.center; document.InsertParagraph("TOTAL DE VENDAS").FontSize(10d).Bold().Alignment = Alignment.center; document.InsertParagraph(); document.InsertParagraph("PROMOTOR: ").FontSize(10d).Bold() .Append(txtNomeVendedor.Text).FontSize(10d) .Alignment = Alignment.left; document.InsertParagraph("PRAÇA: ").FontSize(10d).Bold() .Append(cbbPraça.SelectedItem.ToString()).FontSize(10d) .Alignment = Alignment.left; document.InsertParagraph("PLACA VEICULO: ").FontSize(10d).Bold() .Append(vendedor.Placa).FontSize(10d) .Alignment = Alignment.left; document.InsertParagraph(); document.InsertParagraph("RELATÓRIO GERAL").FontSize(10d).Bold().Alignment = Alignment.center; document.InsertParagraph(); Table t = document.AddTable(1, 4); t.AutoFit = AutoFit.Contents; t.Design = TableDesign.LightGridAccent3; t.Rows[0].Cells[0].Paragraphs.First().Append("DATA").Bold().FontSize(10d).Alignment = Alignment.center; t.Rows[0].Cells[1].Paragraphs.First().Append("PRODUTO").Bold().FontSize(10d).Alignment = Alignment.center; t.Rows[0].Cells[2].Paragraphs.First().Append("CARGA/DEVOLUÇÃO").Bold().FontSize(10d).Alignment = Alignment.center; t.Rows[0].Cells[3].Paragraphs.First().Append("QUANTIDADE").Bold().FontSize(10d).Alignment = Alignment.center; List <ProdutosCargaDevoluçãoModelo> produtosCargaDevoluçãoList = new List <ProdutosCargaDevoluçãoModelo>(); foreach (CargaDevoluçãoModelo cargaDevolução in cargaDevoluçãoList) { produtosCargaDevoluçãoList = SqliteAcessoDados.LoadQuery <ProdutosCargaDevoluçãoModelo>("select * from ProdutosCargaDevolução where ProdutosCargaDevolução.CargaDevoluçãoID == " + cargaDevolução.Id); foreach (ProdutosCargaDevoluçãoModelo produtosCargaDevolução in produtosCargaDevoluçãoList) { t.InsertRow(); string descrição = SqliteAcessoDados.LoadQuery <ProdutoModelo>("select Descrição from Produto where Produto.ID == " + produtosCargaDevolução.ProdutoID).First().Descrição; t.Rows.Last().Cells[0].Paragraphs.First().Append(cargaDevolução.Data.ToShortDateString()).FontSize(10d).Alignment = Alignment.left; t.Rows.Last().Cells[1].Paragraphs.First().Append(descrição).FontSize(10d).Alignment = Alignment.left; t.Rows.Last().Cells[2].Paragraphs.First().Append(cargaDevolução.Devolução ? "Devolução" : "Carga").FontSize(10d).Alignment = Alignment.left; t.Rows.Last().Cells[3].Paragraphs.First().Append(cargaDevolução.Devolução ? produtosCargaDevolução.Quantidade.ToString() : (produtosCargaDevolução.Quantidade * -1).ToString()).FontSize(10d).Alignment = Alignment.left; } } document.InsertTable(t); document.InsertParagraph(); document.InsertParagraph("RELATÓRIO POR PRODUTO").FontSize(10d).Bold().Alignment = Alignment.center; List <ProdutoModelo> produtoList = SqliteAcessoDados.GetPesquisarTodos <ProdutoModelo>(); foreach (ProdutoModelo produto in produtoList) { document.InsertParagraph(); document.InsertParagraph("PRODUTO: ") .FontSize(10d) .Bold() .Append(produto.Descrição) .Alignment = Alignment.left; document.InsertParagraph(); t = document.AddTable(1, 3); t.Rows[0].Cells[0].Paragraphs.First().Append("DATA").Bold().FontSize(10d).Alignment = Alignment.center; t.Rows[0].Cells[1].Paragraphs.First().Append("CARGA/DEVOLUÇÃO").Bold().FontSize(10d).Alignment = Alignment.center; t.Rows[0].Cells[2].Paragraphs.First().Append("QUANTIDADE").Bold().FontSize(10d).Alignment = Alignment.center; int quantidade = 0; foreach (CargaDevoluçãoModelo cargaDevolução in cargaDevoluçãoList) { produtosCargaDevoluçãoList = SqliteAcessoDados.LoadQuery <ProdutosCargaDevoluçãoModelo>("select * from ProdutosCargaDevolução where ProdutosCargaDevolução.CargaDevoluçãoID == " + cargaDevolução.Id + " and ProdutosCargaDevolução.ProdutoID == " + produto.Id); foreach (ProdutosCargaDevoluçãoModelo produtosCargaDevolução in produtosCargaDevoluçãoList) { t.InsertRow(); string descrição = SqliteAcessoDados.LoadQuery <ProdutoModelo>("select Descrição from Produto where Produto.ID == " + produtosCargaDevolução.ProdutoID).First().Descrição; t.Rows.Last().Cells[0].Paragraphs.First().Append(cargaDevolução.Data.ToShortDateString()).FontSize(10d).Alignment = Alignment.left; t.Rows.Last().Cells[1].Paragraphs.First().Append(cargaDevolução.Devolução ? "Devolução" : "Carga").FontSize(10d).Alignment = Alignment.left; t.Rows.Last().Cells[2].Paragraphs.First().Append(cargaDevolução.Devolução ? produtosCargaDevolução.Quantidade.ToString() : (produtosCargaDevolução.Quantidade * -1).ToString()).FontSize(10d).Alignment = Alignment.left; quantidade += cargaDevolução.Devolução ? produtosCargaDevolução.Quantidade : (produtosCargaDevolução.Quantidade * -1); } } t.InsertRow(); t.Rows.Last().Cells[1].Paragraphs.First().Append("TOTAL PERIODO").Bold().FontSize(10d).Alignment = Alignment.left; t.Rows.Last().Cells[2].Paragraphs.First().Append(quantidade.ToString()).FontSize(10d).Alignment = Alignment.left; document.InsertTable(t); } try { document.Save(); DialogResult result = MessageBox.Show("Relatorio gerado na pasta Meus Documentos -> Relatorios(" + docPath + ")", "Atenção!", MessageBoxButtons.OK); } catch { DialogResult result = MessageBox.Show("Arquivo aberto em outro aplicativo, favor fecha-lo antes de continuar", "Atenção!", MessageBoxButtons.OK); } } } else { DialogResult result = MessageBox.Show("Nenhum registro encontrado nas datas selecionadas para este vendedor e esta praça", "Atenção!", MessageBoxButtons.OK); } } else { DialogResult result = MessageBox.Show("Selecione uma Praça primeiro", "Atenção!", MessageBoxButtons.OK); } } else { DialogResult result = MessageBox.Show("Selecione um Vendedor primeiro", "Atenção!", MessageBoxButtons.OK); } }
/// <summary> /// Wraps an XElement as an Image /// </summary> /// <param name="document"></param> /// <param name="i">The XElement i to wrap</param> /// <param name="img"></param> internal Picture(DocX document, XElement i, Image img) : base(document, i) { picture_rels = new Dictionary <PackagePart, PackageRelationship>(); this.img = img; this.id = ( from e in Xml.Descendants() where e.Name.LocalName.Equals("blip") select e.Attribute(XName.Get("embed", "http://schemas.openxmlformats.org/officeDocument/2006/relationships")).Value ).SingleOrDefault(); if (this.id == null) { this.id = ( from e in Xml.Descendants() where e.Name.LocalName.Equals("imagedata") select e.Attribute(XName.Get("id", "http://schemas.openxmlformats.org/officeDocument/2006/relationships")).Value ).SingleOrDefault(); } this.name = ( from e in Xml.Descendants() let a = e.Attribute(XName.Get("name")) where (a != null) select a.Value ).FirstOrDefault(); if (this.name == null) { this.name = ( from e in Xml.Descendants() let a = e.Attribute(XName.Get("title")) where (a != null) select a.Value ).FirstOrDefault(); } this.descr = ( from e in Xml.Descendants() let a = e.Attribute(XName.Get("descr")) where (a != null) select a.Value ).FirstOrDefault(); this.cx = ( from e in Xml.Descendants() let a = e.Attribute(XName.Get("cx")) where (a != null) select int.Parse(a.Value) ).FirstOrDefault(); if (this.cx == 0) { XAttribute style = ( from e in Xml.Descendants() let a = e.Attribute(XName.Get("style")) where (a != null) select a ).FirstOrDefault(); string fromWidth = style.Value.Substring(style.Value.IndexOf("width:") + 6); var widthInt = ((double.Parse((fromWidth.Substring(0, fromWidth.IndexOf("pt"))).Replace(".", ","))) / 72.0) * 914400; cx = System.Convert.ToInt32(widthInt); } this.cy = ( from e in Xml.Descendants() let a = e.Attribute(XName.Get("cy")) where (a != null) select int.Parse(a.Value) ).FirstOrDefault(); if (this.cy == 0) { XAttribute style = ( from e in Xml.Descendants() let a = e.Attribute(XName.Get("style")) where (a != null) select a ).FirstOrDefault(); string fromHeight = style.Value.Substring(style.Value.IndexOf("height:") + 7); var heightInt = ((double.Parse((fromHeight.Substring(0, fromHeight.IndexOf("pt"))).Replace(".", ","))) / 72.0) * 914400; cy = System.Convert.ToInt32(heightInt); } this.xfrm = ( from d in Xml.Descendants() where d.Name.LocalName.Equals("xfrm") select d ).SingleOrDefault(); this.prstGeom = ( from d in Xml.Descendants() where d.Name.LocalName.Equals("prstGeom") select d ).SingleOrDefault(); if (xfrm != null) { this.rotation = xfrm.Attribute(XName.Get("rot")) == null ? 0 : uint.Parse(xfrm.Attribute(XName.Get("rot")).Value); } }
private void exportToWord() { string path; using (SaveFileDialog saveFileDialog = new SaveFileDialog()) { saveFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); saveFileDialog.Filter = "Word 97-2003 Documents (*.doc)|*.doc|Word 2007 Documents (*.docx)|*.docx"; saveFileDialog.FilterIndex = 2; saveFileDialog.RestoreDirectory = true; if (saveFileDialog.ShowDialog() == DialogResult.OK) { path = saveFileDialog.FileName; using (var document = DocX.Create(path)) { for (int i = 0; i < 11; i++) { document.InsertParagraph("") .Font("Arial") .Bold(true) .FontSize(22d).Alignment = Alignment.left; } document.InsertParagraph("Communications Management Process \nFor " + projectModel.ProjectName) .Font("Arial") .Bold(true) .FontSize(22d).Alignment = Alignment.left; document.InsertSectionPageBreak(); document.InsertParagraph("Document Control\n") .Font("Arial") .Bold(true) .FontSize(14d).Alignment = Alignment.left; document.InsertParagraph("") .Font("Arial") .Bold(true) .FontSize(14d).Alignment = Alignment.left; document.InsertParagraph("Document Information\n") .Font("Arial") .Bold(true) .FontSize(14d).Alignment = Alignment.left; var documentInfoTable = document.AddTable(6, 2); documentInfoTable.Rows[0].Cells[0].Paragraphs[0].Append("").Bold(true).Color(Color.White); documentInfoTable.Rows[0].Cells[1].Paragraphs[0].Append("Information").Bold(true).Color(Color.White); documentInfoTable.Rows[0].Cells[0].FillColor = TABLE_HEADER_COLOR; documentInfoTable.Rows[0].Cells[1].FillColor = TABLE_HEADER_COLOR; documentInfoTable.Rows[1].Cells[0].Paragraphs[0].Append("Document ID"); documentInfoTable.Rows[1].Cells[1].Paragraphs[0].Append(currentCommunicationsManagementProcessModel.DocumentID); documentInfoTable.Rows[2].Cells[0].Paragraphs[0].Append("Document Owner"); documentInfoTable.Rows[2].Cells[1].Paragraphs[0].Append(currentCommunicationsManagementProcessModel.DocumentOwner); documentInfoTable.Rows[3].Cells[0].Paragraphs[0].Append("Issue Date"); documentInfoTable.Rows[3].Cells[1].Paragraphs[0].Append(currentCommunicationsManagementProcessModel.IssueDate); documentInfoTable.Rows[4].Cells[0].Paragraphs[0].Append("Last Saved Date"); documentInfoTable.Rows[4].Cells[1].Paragraphs[0].Append(currentCommunicationsManagementProcessModel.LastSavedDate); documentInfoTable.Rows[5].Cells[0].Paragraphs[0].Append("File Name"); documentInfoTable.Rows[5].Cells[1].Paragraphs[0].Append(currentCommunicationsManagementProcessModel.FileName); documentInfoTable.SetWidths(new float[] { 493, 1094 }); document.InsertTable(documentInfoTable); document.InsertParagraph("\nDocument History\n") .Font("Arial") .Bold(true) .FontSize(14d).Alignment = Alignment.left; var documentHistoryTable = document.AddTable(currentCommunicationsManagementProcessModel.DocumentHistories.Count + 1, 3); documentHistoryTable.Rows[0].Cells[0].Paragraphs[0].Append("Version") .Bold(true) .Color(Color.White); documentHistoryTable.Rows[0].Cells[1].Paragraphs[0].Append("Issue Date") .Bold(true) .Color(Color.White); documentHistoryTable.Rows[0].Cells[2].Paragraphs[0].Append("Changes") .Bold(true) .Color(Color.White); documentHistoryTable.Rows[0].Cells[0].FillColor = TABLE_HEADER_COLOR; documentHistoryTable.Rows[0].Cells[1].FillColor = TABLE_HEADER_COLOR; documentHistoryTable.Rows[0].Cells[2].FillColor = TABLE_HEADER_COLOR; for (int i = 1; i < currentCommunicationsManagementProcessModel.DocumentHistories.Count + 1; i++) { documentHistoryTable.Rows[i].Cells[0].Paragraphs[0].Append(currentCommunicationsManagementProcessModel.DocumentHistories[i - 1].Version); documentHistoryTable.Rows[i].Cells[1].Paragraphs[0].Append(currentCommunicationsManagementProcessModel.DocumentHistories[i - 1].IssueDate); documentHistoryTable.Rows[i].Cells[2].Paragraphs[0].Append(currentCommunicationsManagementProcessModel.DocumentHistories[i - 1].Changes); } documentHistoryTable.SetWidths(new float[] { 190, 303, 1094 }); document.InsertTable(documentHistoryTable); document.InsertParagraph("\nDocument Approvals\n") .Font("Arial") .Bold(true) .FontSize(14d).Alignment = Alignment.left; var documentApprovalTable = document.AddTable(currentCommunicationsManagementProcessModel.DocumentApprovals.Count + 1, 4); documentApprovalTable.Rows[0].Cells[0].Paragraphs[0].Append("Role") .Bold(true) .Color(Color.White); documentApprovalTable.Rows[0].Cells[1].Paragraphs[0].Append("Name") .Bold(true) .Color(Color.White); documentApprovalTable.Rows[0].Cells[2].Paragraphs[0].Append("Signature") .Bold(true) .Color(Color.White); documentApprovalTable.Rows[0].Cells[3].Paragraphs[0].Append("Date") .Bold(true) .Color(Color.White); documentApprovalTable.Rows[0].Cells[0].FillColor = TABLE_HEADER_COLOR; documentApprovalTable.Rows[0].Cells[1].FillColor = TABLE_HEADER_COLOR; documentApprovalTable.Rows[0].Cells[2].FillColor = TABLE_HEADER_COLOR; documentApprovalTable.Rows[0].Cells[3].FillColor = TABLE_HEADER_COLOR; for (int i = 1; i < currentCommunicationsManagementProcessModel.DocumentApprovals.Count + 1; i++) { documentApprovalTable.Rows[i].Cells[0].Paragraphs[0].Append(currentCommunicationsManagementProcessModel.DocumentApprovals[i - 1].Role); documentApprovalTable.Rows[i].Cells[1].Paragraphs[0].Append(currentCommunicationsManagementProcessModel.DocumentApprovals[i - 1].Name); documentApprovalTable.Rows[i].Cells[2].Paragraphs[0].Append(currentCommunicationsManagementProcessModel.DocumentApprovals[i - 1].Signature); documentApprovalTable.Rows[i].Cells[3].Paragraphs[0].Append(currentCommunicationsManagementProcessModel.DocumentApprovals[i - 1].DateApproved); } documentApprovalTable.SetWidths(new float[] { 493, 332, 508, 254 }); document.InsertTable(documentApprovalTable); document.InsertParagraph().InsertPageBreakAfterSelf(); var p = document.InsertParagraph(); var title = p.InsertParagraphBeforeSelf("Table of Contents").Bold().FontSize(20); var tocSwitches = new Dictionary <TableOfContentsSwitches, string>() { { TableOfContentsSwitches.O, "1-3" }, { TableOfContentsSwitches.U, "" }, { TableOfContentsSwitches.Z, "" }, { TableOfContentsSwitches.H, "" } }; document.InsertTableOfContents(p, "", tocSwitches); document.InsertParagraph().InsertPageBreakAfterSelf(); var CommunicationsProcessHeading = document.InsertParagraph("1\tCommunications Process") .Bold() .FontSize(14d) .Color(Color.Black) .Bold(true) .Font("Arial"); CommunicationsProcessHeading.StyleId = "Heading1"; document.InsertParagraph(currentCommunicationsManagementProcessModel.CommunicationsDocumentsIntro) .FontSize(11d) .Color(Color.Black) .Font("Arial").Alignment = Alignment.left; var overview = document.InsertParagraph("1.1\tOverview") .Bold() .FontSize(12d) .Color(Color.Black) .Bold(true) .Font("Arial"); overview.StyleId = "Heading2"; document.InsertParagraph(currentCommunicationsManagementProcessModel.Overview) .FontSize(11d) .Color(Color.Black) .Font("Arial").Alignment = Alignment.left; var createMessage = document.InsertParagraph("1.2\tCreate Message") .Bold() .FontSize(12d) .Color(Color.Black) .Bold(true) .Font("Arial"); createMessage.StyleId = "Heading2"; document.InsertParagraph(currentCommunicationsManagementProcessModel.CreateMessage) .FontSize(11d) .Color(Color.Black) .Font("Arial").Alignment = Alignment.left; var comMessage = document.InsertParagraph("1.3\tCommunicate Message") .Bold() .FontSize(12d) .Color(Color.Black) .Bold(true) .Font("Arial"); comMessage.StyleId = "Heading2"; document.InsertParagraph(currentCommunicationsManagementProcessModel.CommunicateMessage) .FontSize(11d) .Color(Color.Black) .Font("Arial").Alignment = Alignment.left; var comRoles = document.InsertParagraph("2\tCommunications Roles") .Bold() .FontSize(14d) .Color(Color.Black) .Bold(true) .Font("Arial"); comRoles.StyleId = "Heading1"; var comTeams = document.InsertParagraph("2.1\tCommunications Team") .Bold() .FontSize(12d) .Color(Color.Black) .Bold(true) .Font("Arial"); comTeams.StyleId = "Heading2"; document.InsertParagraph(currentCommunicationsManagementProcessModel.CommunicationsTeam) .FontSize(11d) .Color(Color.Black) .Font("Arial").Alignment = Alignment.left; var projectMan = document.InsertParagraph("2.2\tProject Manager") .Bold() .FontSize(12d) .Color(Color.Black) .Bold(true) .Font("Arial"); projectMan.StyleId = "Heading2"; document.InsertParagraph(currentCommunicationsManagementProcessModel.ProjectManagerResponsibilities) .FontSize(11d) .Color(Color.Black) .Font("Arial").Alignment = Alignment.left; var comDocs = document.InsertParagraph("3\tCommunications Documents") .Bold() .FontSize(14d) .Color(Color.Black) .Bold(true) .Font("Arial"); comDocs.StyleId = "Heading1"; var statusReport = document.InsertParagraph("3.1\tProject Status Report") .Bold() .FontSize(12d) .Color(Color.Black) .Bold(true) .Font("Arial"); statusReport.StyleId = "Heading2"; document.InsertParagraph(currentCommunicationsManagementProcessModel.ProjectStatusReport) .FontSize(11d) .Color(Color.Black) .Font("Arial").Alignment = Alignment.left; var comReg = document.InsertParagraph("3.2\tCommunications Register") .Bold() .FontSize(12d) .Color(Color.Black) .Bold(true) .Font("Arial"); comReg.StyleId = "Heading2"; document.InsertParagraph(currentCommunicationsManagementProcessModel.CommunicationsRegister) .FontSize(11d) .Color(Color.Black) .Font("Arial").Alignment = Alignment.left; try { document.Save(); } catch (Exception) { MessageBox.Show("The selected File is open.", "Close File", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } } }
public Header3(DocX d, Paragraph p) : base(d, p) { }
private void CreateOrder(int course, string code, string direct) { string file = "order.docx"; // создаём документ DocX document = DocX.Create(dir + file); document.SetDefaultFont(new Font("Times New Roman"), fontSize: 12); // Устанавливаем стандартный для документа шрифт и размер шрифта document.MarginLeft = 42.5f; document.MarginTop = 34.1f; document.MarginRight = 34.1f; document.MarginBottom = 34.1f; document.InsertParagraph($"Проект приказа\n\n").Bold().Alignment = Alignment.center; document.InsertParagraph($"\tВ соответствии с календарным графиком учебного процесса допустить " + $"и направить для прохождения {form_pract.SelectedItem.ToString().ToLower()} практики {combobox_type.SelectedItem} " + $"следующих студентов {course} курса, очной формы, направление подготовки {code} «{direct}», " + $"профиль «Прикладная информатика в государственном и муниципальном управлении», факультета " + $"«Информационные системы в управлении» с {first_date.Text}г. по {second_date.Text}.\n"); document.InsertParagraph($"\tСпособ проведения практики: выездная и стационарная."); document.InsertParagraph($"\tСтационарная практика (без оплаты)\n").Bold(); document.InsertParagraph($"\tОбучающихся за счет бюджетных ассигнований федерального бюджета"); IEnumerable <Fill_data> studentsF = fill_data.Where(k => k.payable.Equals("Бюджет")); IEnumerable <Fill_data> studentsB = fill_data.Where(k => k.payable.Equals("Внебюджет")); Xceed.Document.NET.Table table = document.AddTable(studentsF.Count() + 1, 4); Xceed.Document.NET.Table tabpe_pay = document.AddTable(studentsB.Count() + 1, 4); table.Alignment = Alignment.center; table.AutoFit = AutoFit.Contents; tabpe_pay.Alignment = Alignment.center; tabpe_pay.AutoFit = AutoFit.Contents; table.Rows[0].Cells[0].Paragraphs[0].Append("ФИО студента").Alignment = Alignment.center; table.Rows[0].Cells[1].Paragraphs[0].Append("Группа").Alignment = Alignment.center; table.Rows[0].Cells[2].Paragraphs[0].Append("Место прохождения практики").Alignment = Alignment.center; table.Rows[0].Cells[3].Paragraphs[0].Append("Руководитель практики").Alignment = Alignment.center; tabpe_pay.Rows[0].Cells[0].Paragraphs[0].Append("ФИО студента").Alignment = Alignment.center; tabpe_pay.Rows[0].Cells[1].Paragraphs[0].Append("Группа").Alignment = Alignment.center; tabpe_pay.Rows[0].Cells[2].Paragraphs[0].Append("Место прохождения практики").Alignment = Alignment.center; tabpe_pay.Rows[0].Cells[3].Paragraphs[0].Append("Руководитель практики").Alignment = Alignment.center; for (int i = 0; i < studentsF.Count(); i++) { table.Rows[i + 1].Cells[0].Paragraphs[0].Append(studentsF.ElementAt(i).fio); table.Rows[i + 1].Cells[1].Paragraphs[0].Append(combobox_groupe.SelectedItem.ToString()); table.Rows[i + 1].Cells[2].Paragraphs[0].Append(studentsF.ElementAt(i).place); table.Rows[i + 1].Cells[3].Paragraphs[0].Append(combobox_otvetsven.SelectedItem.ToString()); } for (int i = 0; i < studentsB.Count(); i++) { tabpe_pay.Rows[i + 1].Cells[0].Paragraphs[0].Append(studentsB.ElementAt(i).fio); tabpe_pay.Rows[i + 1].Cells[1].Paragraphs[0].Append(combobox_groupe.SelectedItem.ToString()); tabpe_pay.Rows[i + 1].Cells[2].Paragraphs[0].Append(studentsB.ElementAt(i).place); tabpe_pay.Rows[i + 1].Cells[3].Paragraphs[0].Append(combobox_otvetsven.SelectedItem.ToString()); } document.InsertParagraph().InsertTableAfterSelf(table); if (studentsB.Count() > 0) { document.InsertParagraph($"\tОбучающихся на платной основе"); document.InsertParagraph().InsertTableAfterSelf(tabpe_pay); } document.InsertParagraph($"\tОтветственный по {form_pract.SelectedItem.ToString().ToLower()} практики по кафедре в период с {first_date.Text} г. по {second_date.Text} г. - {combobox_otvetsven.Text} ст. преподаватель кафедры ПИЭ."); Classes.Direction directions = Helper.ODirections.Where(k => k.name.Equals(direct)).ElementAt(0); Cathedra cathedra = Helper.OCathedras.Where(k => k.cathedra.Equals(directions.id_cathedra)).ElementAt(0); document.InsertParagraph($@" Проректор по УР ________«____» ________ {first_date.SelectedDate.Value.Year}г. С.В. Мельник Главный бухгалтер ________«____» ________ {first_date.SelectedDate.Value.Year} г. Г.И. Вилисова Начальник ПЭО ________«____» ________ {first_date.SelectedDate.Value.Year}г. Т.В. Грачева Начальник ООП и СТВ ________«____» ________{first_date.SelectedDate.Value.Year}г. Ю.С. Сачук Декан факультета «{directions.id_cathedra}» ________«____» ________ {first_date.SelectedDate.Value.Year}г. {cathedra.name.Remove(1)}.{cathedra.patronymic.Remove(1)}. {cathedra.surname} Ответственный за практику и содействие трудоустройству на факультете ________«____» __________ {first_date.SelectedDate.Value.Year}г. {cathedra.name.Remove(1)}.{cathedra.patronymic.Remove(1)}.{cathedra.surname} "); document.Save(); MessageBox.Show("Документ успешно сформирован!", "Документ", MessageBoxButton.OK, MessageBoxImage.Information); }
public static DocX kerg(this DocX doc, object value) { return(doc.podstaw("[KERG]", value)); }
public static DocX CreateDocA(DocX template, SRViewModel model) { //Create Date for Header // string Fdate = model.date.ToString(); //string[] d = Fdate.Split(' '); //Fdate = d[0]; //Fdate = formatdate(Fdate, model); //Create Distrbution for Header string Fdist = distrb(model.Cat); string Folang = "English"; //Session Numer string Fsnum = "[NUMBER]"; if (!String.IsNullOrEmpty(model.sNum)) { Fsnum = Sessionnum(model); } //sYMBOLE string symb = getSym(model.Cat); string[] sym = symb.Split(new string[] { "#" }, StringSplitOptions.None); string x = sym[1]; x = model.Prep.ToString() + x; string Fsym1 = x; string Fmnum = GetOrdinalSuffix(Convert.ToInt32(model.Prep.ToString())); //second page meeting date string Fsodate = ""; if (model.time.ToString() == "at 10 a.m.") { Fsodate = "The meeting was called to order at 10 a.m."; } if (model.time.ToString() == "at 3 p.m.") { Fsodate = "The meeting was called to order at 3 p.m."; } //QR code and Bar code string lang = getlanguageQR(model.lang_ID); string Fsym = getSym(model.Cat); //Fsym = Fsym.Remove(Fsym.Length-1); // Fsym = Fsym + Fsym1; Fsym = Fsym.Replace("#", model.Prep.ToString()); string url = "http://undocs.org/m2/QRCode.ashx?DS=" + Fsym + "&Size=2&Lang=" + lang; using (var client = new WebClient()) { //var content = client.DownloadData("https://api.qrserver.com/v1/create-qr-code/?size=66x66&data=http://undocs.org/fr/A/HRC/70"); //var content = client.DownloadData("http://undocs.org/m2/QRCode.ashx?DS=A/HRC/70&Size=2&Lang=F"); var content = client.DownloadData(url); using (var str1 = new MemoryStream(content)) { Image image = template.AddImage(str1); Picture p = image.CreatePicture(); Footer f = template.Footers.first; Table t = f.Tables[0]; //t.Rows[0].Cells[1].Paragraphs.First().AppendPicture(pR); t.Rows[0].Cells[1].Paragraphs.First().AppendPicture(p); } } string Floc = model.loca.ToString() + ", " + model.locb.ToString(); //string Fvirs = ""; //if (model.ver != null) //{ // Fvirs = getVerisons(model); //} //create barcode & gdoc string Fbar = " "; string gdoc = " "; string Fgdocf = " "; if (!String.IsNullOrEmpty(model.Gdoc)) { gdoc = model.Gdoc.ToString(); Fbar = "*" + gdoc + "*"; Fgdocf = gdoc; gdoc = gdoc.Insert(2, "-"); } string Fdname = ""; if (!String.IsNullOrEmpty(model.Cname)) { Fdname = model.Ctitle.ToString() + model.Cname.ToString(); } if (String.IsNullOrEmpty(model.Cname)) { int deleteStart = 0; int deleteEnd = 0; //Get the array of the paragraphs containing the start and end catches for (int i = 0; i < template.Paragraphs.Count; i++) { if (template.Paragraphs[i].Text.Contains("Chair:")) { deleteStart = i; } if (template.Paragraphs[i].Text.Contains("dname")) { deleteEnd = i; } } if (deleteStart > 0 && deleteEnd > 0) { //delete from the paraIndex as the arrays will shift when a paragraph is deleted int paraIndex = deleteStart; for (int i = deleteStart; i <= deleteEnd; i++) { template.RemoveParagraphAt(paraIndex); } } } string Flname1 = ""; string Flname2 = ""; if (!String.IsNullOrEmpty(model.L1name)) { Flname1 = model.L1title.ToString() + model.L1name.ToString(); } if (!String.IsNullOrEmpty(model.L2name)) { Flname2 = model.L2title.ToString() + model.L2name.ToString(); } if (String.IsNullOrEmpty(model.L1name)) { int deleteStart = 0; int deleteEnd = 0; int deleteStart1 = 0; int deleteEnd1 = 0; for (int i = 0; i < template.Paragraphs.Count; i++) { if (template.Paragraphs[i].Text.Contains("later") && template.Paragraphs[i].Text.Contains("lname2")) { deleteStart1 = i; } if (template.Paragraphs[i].Text.Contains("lname2")) { deleteEnd1 = i; } } //Get the array of the paragraphs containing the start and end catches for (int i = 0; i < template.Paragraphs.Count; i++) { if (template.Paragraphs[i].Text.Contains("later") && template.Paragraphs[i].Text.Contains("lname1")) { deleteStart = i; } if (template.Paragraphs[i].Text.Contains("lname1")) { deleteEnd = i; } } if (deleteStart1 > 0 && deleteEnd1 > 0) { //delete from the paraIndex as the arrays will shift when a paragraph is deleted int paraIndex = deleteStart1; for (int i = deleteStart1; i <= deleteEnd1; i++) { template.RemoveParagraphAt(paraIndex); } } if (deleteStart > 0 && deleteEnd > 0) { //delete from the paraIndex as the arrays will shift when a paragraph is deleted int paraIndex = deleteStart; for (int i = deleteStart; i <= deleteEnd; i++) { template.RemoveParagraphAt(paraIndex); } } //Get the array of the paragraphs containing the start and end catches } if (String.IsNullOrEmpty(model.L2name) && !String.IsNullOrEmpty(model.L1name)) { int deleteStart = 0; int deleteEnd = 0; for (int i = 0; i < template.Paragraphs.Count; i++) { if (template.Paragraphs[i].Text.Contains("later") && template.Paragraphs[i].Text.Contains("lname2")) { deleteStart = i; } if (template.Paragraphs[i].Text.Contains("lname2")) { deleteEnd = i; } } if (deleteStart > 0 && deleteEnd > 0) { //delete from the paraIndex as the arrays will shift when a paragraph is deleted int paraIndex = deleteStart; for (int i = deleteStart; i <= deleteEnd; i++) { template.RemoveParagraphAt(paraIndex); } } } string[] info1 = info(model); string Fldate = formatdate1(model); string xxx = DateTime.Now.ToString(); template.AddCustomProperty(new CustomProperty("gdoc", gdoc)); template.AddCustomProperty(new CustomProperty("gdocf", Fgdocf)); template.AddCustomProperty(new CustomProperty("bar", Fbar)); template.AddCustomProperty(new CustomProperty("osdate", Fsodate)); template.AddCustomProperty(new CustomProperty("sym1", Fsym1)); //template. // template.ReplaceText(Fsym, Fsym, false, RegexOptions.IgnoreCase); template.AddCustomProperty(new CustomProperty("symh", Fsym)); // template.ReplaceText(sym, sym, false, RegexOptions.IgnoreCase); template.AddCustomProperty(new CustomProperty("olang", Folang)); template.AddCustomProperty(new CustomProperty("dist", Fdist)); // template.ReplaceText("dist", Fdist, false, RegexOptions.IgnoreCase); template.AddCustomProperty(new CustomProperty("date", " ")); template.AddCustomProperty(new CustomProperty("ldate", Fldate)); // template.ReplaceText("date", Fdate, false, RegexOptions.IgnoreCase); template.AddCustomProperty(new CustomProperty("dname", Fdname)); // template.ReplaceText("date", Fdate, false, RegexOptions.IgnoreCase); template.AddCustomProperty(new CustomProperty("lname1", Flname1)); template.AddCustomProperty(new CustomProperty("lname2", Flname2)); template.AddCustomProperty(new CustomProperty("loca", Floc)); // template.ReplaceText("date", Fdate, false, RegexOptions.IgnoreCase); //template.AddCustomProperty(new CustomProperty("virs", Fvirs)); // template.ReplaceText("virs", "", false, RegexOptions.IgnoreCase); template.AddCustomProperty(new CustomProperty("snum", Fsnum)); // template.ReplaceText("snum", Fsnum, false, RegexOptions.IgnoreCase); template.AddCustomProperty(new CustomProperty("mnum", Fmnum)); // template.ReplaceText("prep", Fprep, false, RegexOptions.IgnoreCase); template.AddCustomProperty(new CustomProperty("Date-Generated", xxx)); template.AddCustomProperty(new CustomProperty("Org", "SR")); template.AddCustomProperty(new CustomProperty("Entity", info1[0])); template.AddCustomProperty(new CustomProperty("doctype", info1[1])); template.AddCustomProperty(new CustomProperty("category", info1[2])); return(template); }
public static DocX jewTeryt(this DocX doc, object value) { return(doc.podstaw("[JEW_TERYT]", value)); }
private void btnExport_Click(object sender, EventArgs e) { DocX gDoc; try { if (File.Exists(@"Template.docx")) { gDoc = CreateInvoiceFromTemplate(DocX.Load(@"Template.docx")); gDoc.SaveAs(CommonParam.ProgramPath + CommonParam.SessionFolderName + "\\BienBan.docx"); ProcessStartInfo startInfo = new ProcessStartInfo(); startInfo.FileName = "WINWORD.EXE"; startInfo.Arguments = CommonParam.ProgramPath + CommonParam.SessionFolderName + "\\BienBan.docx"; Process.Start(startInfo); btnExport.Enabled = false; } else { MessageBox.Show("Không có file Template.docx"); } } catch (Exception) { return; } /* * using (var fbd = new FolderBrowserDialog()) * { * DialogResult result = fbd.ShowDialog(); * * if (result == DialogResult.OK && !string.IsNullOrWhiteSpace(fbd.SelectedPath)) * { * //string[] files = Directory.GetFiles(fbd.SelectedPath); * * //copy file ra folder da chon * string[] originalFiles = Directory.GetFiles(CommonParam.ProgramPath+CommonParam.SessionFolderName, "*", SearchOption.AllDirectories); * * // Dealing with a string array, so let's use the actionable Array.ForEach() with a anonymous method * Array.ForEach(originalFiles, (originalFileLocation) => * { * // Get the FileInfo for both of our files * FileInfo originalFile = new FileInfo(originalFileLocation); * FileInfo destFile = new FileInfo(originalFileLocation.Replace(CommonParam.ProgramPath + CommonParam.SessionFolderName, fbd.SelectedPath)); * // ^^ We can fill the FileInfo() constructor with files that don't exist... * * // ... because we check it here * if (destFile.Exists) * { * // Logic for files that exist applied here; if the original is larger, replace the updated files... * if (originalFile.Length > destFile.Length) * { * originalFile.CopyTo(destFile.FullName, true); * } * } * else // ... otherwise create any missing directories and copy the folder over * { * Directory.CreateDirectory(destFile.DirectoryName); // Does nothing on directories that already exist * originalFile.CopyTo(destFile.FullName, false); // Copy but don't over-write * } * * }); * } * } */ }
public static DocX jewNazwa(this DocX doc, object value) { return(doc.podstaw("[JEW_NAZWA]", value)); }
public DocXManager(string filePath) { docX = new DocX(filePath); }
public static DocX obrTeryt(this DocX doc, object value) { return(doc.podstaw("[OBR_TERYT]", value)); }
public ActionResult XuatFileWord() { string targetfile = Server.MapPath("~/Content/template/template1.docx"); var doc = DocX.Load(targetfile); var doc1 = doc.Copy(); using (var workScope = new UnitOfWork(new PatientManagementDbContext())) { var listdata = workScope.Patients.GetAll().ToList(); Table table = doc1.Tables[0]; for (int i = 0; i < listdata.Count; i++) { Row myrow = table.InsertRow(); //cot stt Paragraph para0 = myrow.Cells[0].Paragraphs.First().Font("Time New Roman").FontSize(14).Append((i + 1).ToString() + "."); para0.Alignment = Alignment.center; para0.FontSize(14); para0.Font("Time New Roman"); //cột mã bệnh nhân Paragraph para1 = myrow.Cells[1].Paragraphs.First().Append(listdata[i].PatientCode); para1.FontSize(14); para1.Font("Time New Roman"); //cột mã căn cước Paragraph para2 = myrow.Cells[2].Paragraphs.First().Append(listdata[i].IndentificationCardId); para2.FontSize(14); para2.Font("Time New Roman"); //cột hộ tên Paragraph para3 = myrow.Cells[3].Paragraphs.First().Append(listdata[i].FullName); para3.FontSize(14); para3.Font("Time New Roman"); //cột ngày sinh if (listdata[i].DateOfBirth != null) { string str = listdata[i].DateOfBirth.ToString(); DateTime date = Convert.ToDateTime(str); string ngay = ""; string thang = ""; string nam = ""; ngay = date.Day.ToString(); if (ngay.Length == 1) { ngay = "0" + ngay; } thang = date.Month.ToString(); if (thang.Length == 1) { thang = "0" + thang; } nam = date.Year.ToString(); if (nam.Length == 1) { nam = "0" + nam; } string ngaynhan = ngay + "/" + thang + "/" + nam; Paragraph para4 = myrow.Cells[4].Paragraphs.First().Append(ngaynhan); para4.FontSize(14); para4.Font("Time New Roman"); para4.Alignment = Alignment.center; } //cột hộ tên string gender = ""; if (listdata[i].Gender == true) { gender = "Nam"; } else { gender = "Nữ"; } Paragraph para5 = myrow.Cells[5].Paragraphs.First().Append(gender); para5.FontSize(14); para5.Font("Time New Roman"); } } using (var stream = new System.IO.MemoryStream()) { doc1.SaveAs(stream); var content = stream.ToArray(); return(File( content, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "DanhSachBenhNhan.docx")); } }
private static void printWhen(DocX document, SpecInfo spec) { document.InsertParagraph() .Append("When") .Font(new FontFamily("Cambria")) .FontSize(13) .Bold() .Color(Color.FromArgb(255, 79, 129, 189)); var p = document.InsertParagraph() .Append(spec.HasExecutionBeenTriggered ? string.Format("{0} [{1}]", spec.When.Description, spec.When.Passed ? "Passed" : "Failed") : spec.When.Description) .Color(spec.HasExecutionBeenTriggered ? (spec.When.Passed ? Color.Green : Color.Red) : Color.Black) .FontSize(12); if (shouldDisplayWhenException(spec)) { p.AppendLine(spec.Exception.ToString()); p.AppendLine(spec.Exception.StackTrace); } p.IndentationBefore = 0.5f; }