}///////////Создание файла и запись информации о клиентах private void WriteService(string fileName) { int checkedRowsCount = 0; for (int i = 0; i < data.RowCount; i++) { if (Convert.ToBoolean(data[checkBoxColumnIndex, i].Value)) { checkedRowsCount++; } } DocX doc = DocX.Create(fileName); Paragraph paragraph = doc.InsertParagraph(); paragraph.Alignment = Alignment.right; paragraph.AppendLine("ElecPair").Font("Arial Black").FontSize(16).UnderlineStyle(UnderlineStyle.singleLine).Highlight(Highlight.magenta); paragraph.AppendLine($"(29) 970 - 14 - 80\r\[email protected]").Font("Arial Black").FontSize(12); Table table = doc.AddTable(checkedRowsCount + 1, 3); table.Design = TableDesign.TableGrid; table.Rows[0].Cells[0].Paragraphs[0].Append("Тип оборудования").Font("Arial").Bold(); table.Rows[0].Cells[1].Paragraphs[0].Append("Вид работ").Font("Arial").Bold(); table.Rows[0].Cells[2].Paragraphs[0].Append("Стоимость, руб").Font("Arial").Bold(); int index = 1; for (int i = 0; i < checkedRowsCount; i++) { table.Rows[index].Cells[0].Paragraphs[0].Append(data[1, i].Value.ToString()).Font("Arial"); table.Rows[index].Cells[1].Paragraphs[0].Append(data[2, i].Value.ToString()).Font("Arial"); table.Rows[index].Cells[2].Paragraphs[0].Append(data[3, i].Value.ToString()).Font("Arial"); index++; } doc.InsertParagraph().InsertTableAfterSelf(table); doc.AddProtection(EditRestrictions.readOnly); doc.Save(); }//////////Создание файла и запись информации об услугах
private void WriteClients(string fileName) { DocX doc = DocX.Create(fileName); for (int i = 0; i < data.RowCount; i++) { if (Convert.ToBoolean(data[checkBoxColumnIndex, i].Value)) { Paragraph paragraph = doc.InsertParagraph(); paragraph.Alignment = Alignment.right; paragraph.AppendLine("ElecPair").Font("Arial Black").FontSize(16).UnderlineStyle(UnderlineStyle.singleLine).Highlight(Highlight.magenta);; paragraph.AppendLine($"(29) 970 - 14 - 80\r\[email protected]").Font("Arial Black").FontSize(12); doc.InsertParagraph($"Клиент: {data[1, i].Value}").Font("Arial Black").FontSize(14); doc.InsertParagraph($"Телефон: {data[2, i].Value}").Font("Arial Black").FontSize(14); doc.InsertParagraph($"Сотрудник: {userFullName}").Font("Arial Black").FontSize(14); doc.InsertParagraph($"Дата принятия в ремонт: {data[3, i].Value}").Font("Arial Black").FontSize(12); Table table = doc.AddTable(4, 2); table.Design = TableDesign.TableGrid; table.Rows[0].Cells[0].Paragraphs[0].Append("Принятое оборудование").Font("Arial").Bold(); table.Rows[1].Cells[0].Paragraphs[0].Append("Заявленная неисправность").Font("Arial").Bold(); table.Rows[2].Cells[0].Paragraphs[0].Append("Вид работ").Font("Arial").Bold(); table.Rows[3].Cells[0].Paragraphs[0].Append("Сумма, руб").Font("Arial").Bold(); table.Rows[0].Cells[1].Paragraphs[0].Append(data[5, i].Value.ToString()).Font("Arial"); table.Rows[1].Cells[1].Paragraphs[0].Append(data[6, i].Value.ToString()).Font("Arial"); table.Rows[2].Cells[1].Paragraphs[0].Append(data[7, i].Value.ToString()).Font("Arial"); table.Rows[3].Cells[1].Paragraphs[0].Append(data[8, i].Value.ToString()).Font("Arial"); doc.InsertParagraph().InsertTableAfterSelf(table); doc.InsertParagraph($"Дата выдачи: {data[4, i].Value}").Font("Arial Black").FontSize(12);; } } doc.AddProtection(EditRestrictions.readOnly); doc.Save(); }///////////Создание файла и запись информации о клиентах
private void Button_Click_4(object sender, RoutedEventArgs e) { string pathDocument = AppDomain.CurrentDomain.BaseDirectory + "Отчет" + ".docx"; DocX document = DocX.Create(pathDocument); Xceed.Document.NET.Paragraph paragraph = document.InsertParagraph(); paragraph.Alignment = Alignment.center; paragraph.AppendLine("Отчет").Bold().Font("Times New Roman").FontSize(14); Xceed.Document.NET.Paragraph paragraph2 = document.InsertParagraph(); paragraph2.Font("Times New Roman"); paragraph2.FontSize(14); paragraph2.Alignment = Alignment.left; paragraph2.AppendLine("Список товаров: ").Font("Times New Roman").FontSize(14).Bold(); paragraph2.AppendLine(); foreach (Product product in config.list.AllProducts) { paragraph2.AppendLine("Название: " + product.Name).Font("Times New Roman").FontSize(14); paragraph2.AppendLine("Описание: " + product.Desc).Font("Times New Roman").FontSize(12); paragraph2.AppendLine(); } paragraph2.AppendLine("Список товаров на складе: ").Font("Times New Roman").FontSize(14).Bold(); paragraph2.AppendLine(); foreach (StroredProduct product in config.list.AllstroredProducts) { paragraph2.AppendLine("Название: " + product.product.Name).Font("Times New Roman").FontSize(14); paragraph2.AppendLine("Полочка: " + product.polka).Font("Times New Roman").FontSize(12); paragraph2.AppendLine("Количество: " + product.count).Font("Times New Roman").FontSize(12); paragraph2.AppendLine("Поставщик: " + product.Postavshick.name).Font("Times New Roman").FontSize(12); paragraph2.AppendLine(); } paragraph2.AppendLine("Список заказов: ").Font("Times New Roman").FontSize(14).Bold(); paragraph2.AppendLine(); foreach (Zakaz product in config.list.AllZakazs) { paragraph2.AppendLine("Название товара: " + product.stroredProduct.Name).Font("Times New Roman").FontSize(14); paragraph2.AppendLine("Поставщик: " + product.postavshick.name).Font("Times New Roman").FontSize(14); paragraph2.AppendLine("Информация по данному поставщику: ").Font("Times New Roman").FontSize(14); paragraph2.AppendLine("Адрес: " + product.postavshick.adress); paragraph2.AppendLine("Телефон: " + product.postavshick.tel); } document.Save(); Process.Start(AppDomain.CurrentDomain.BaseDirectory + "Отчет" + ".docx"); }
private void createExportDoc() { try { DBManager con = new DBManager(); var modelAnimalpark = con.getAnimalparkList(); if (extension == string.Empty) { MessageBox.Show("Не выбран тип экспортруемого файла"); return; } switch (extension) { case (".docx"): string pathDocumentDOCX = Session.baseDir + "Учет товар" + extension; DocX document = DocX.Create(pathDocumentDOCX); Xceed.Document.NET.Paragraph paragraph = document.InsertParagraph(); paragraph. AppendLine("Документ '" + "Отчет о учете автомобилей" + "' создан " + DateTime.Now.ToShortDateString()). Font("Time New Roman"). FontSize(16).Bold().Alignment = Alignment.left; paragraph.AppendLine(); Xceed.Document.NET.Table doctable = document.AddTable(modelAnimalpark.Count + 1, 2); doctable.Design = TableDesign.TableGrid; doctable.TableCaption = "учет товара"; doctable.Rows[0].Cells[0].Paragraphs[0].Append("Учет товара").Font("Times New Roman").FontSize(14); for (int i = 0; i < modelAnimalpark.Count; i++) { doctable.Rows[i + 1].Cells[0].Paragraphs[0].Append(modelAnimalpark[i].Number).Font("Times New Roman").FontSize(14); } document.InsertParagraph().InsertTableAfterSelf(doctable); document.Save(); MessageBox.Show("Отчет успешно сформирован!"); Process.Start(pathDocumentDOCX); break; case (".xlsx"): Excel.Application excel; Excel.Workbook worKbooK; Excel.Worksheet worKsheeT; Excel.Range celLrangE; string pathDocumentXLSX = Session.baseDir + "Учет о животных" + extension; try { excel = new Excel.Application(); excel.Visible = false; excel.DisplayAlerts = false; worKbooK = excel.Workbooks.Add(Type.Missing); worKsheeT = (Microsoft.Office.Interop.Excel.Worksheet)worKbooK.ActiveSheet; worKsheeT.Name = "Учет о животных"; worKsheeT.Range[worKsheeT.Cells[1, 1], worKsheeT.Cells[1, 8]].Merge(); worKsheeT.Cells[1, 1] = "Учет о животных"; worKsheeT.Cells.Font.Size = 15; for (int i = 0; i < modelAnimalpark.Count; i++) { worKsheeT.Cells[i + 3, 1] = modelAnimalpark[i].Number; } worKbooK.SaveAs(pathDocumentXLSX);; worKbooK.Close(); excel.Quit(); MessageBox.Show("Отчет успешно сформирован!"); Process.Start(pathDocumentXLSX); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { worKsheeT = null; celLrangE = null; worKbooK = null; } break; case (".pdf"): string pathDocumentPDF = Session.baseDir + "Учет о животных" + extension; if (File.Exists(Session.baseDir + "Учет о животных.docx")) { Word.Application appWord = new Word.Application(); var wordDocument = appWord.Documents.Open(Session.baseDir + "Учет о животных.docx"); wordDocument.ExportAsFixedFormat(pathDocumentPDF, Word.WdExportFormat.wdExportFormatPDF); MessageBox.Show("Отчет успешно сформирован!"); wordDocument.Close(); Process.Start(pathDocumentPDF); } else { MessageBox.Show("Сначала сформируйте отчет .docx"); } break; } } catch (Exception) { MessageBox.Show("Отсутсвие Ms Office на компьютере. Пожалуйста скачайте его."); Process.Start("https://www.microsoft.com/ru-ru/microsoft-365/compare-all-microsoft-365-products?tab=1&rtc=1"); } }
private void StartTest_Copy_Click(object sender, RoutedEventArgs e) { string pathDocument = AppDomain.CurrentDomain.BaseDirectory + "Отчет " + FIOLABEL.Content + ".docx"; // создаём документ DocX document = DocX.Create(pathDocument); Xceed.Document.NET.Paragraph paragraph = document.InsertParagraph(); // выравниваем параграф по правой стороне paragraph.Alignment = Alignment.center; // добавляем отдельную строку со своим форматированием paragraph.AppendLine("Служба персонала").Bold().Font("Times New Roman").FontSize(14); paragraph.AppendLine("ООО \"Эрнис\"").Bold().Font("Times New Roman").FontSize(14); paragraph.AppendLine("ПРОТОКОЛ ТЕСТИРОВАНИЯ").Bold().Font("Times New Roman").FontSize(14); Xceed.Document.NET.Paragraph paragraph2 = document.InsertParagraph(); paragraph2.Font("Times New Roman"); paragraph2.FontSize(14); paragraph2.Alignment = Alignment.left; paragraph2.AppendLine("Фамилия: " + _loginPage.SerName.Text).Font("Times New Roman").FontSize(14); paragraph2.AppendLine("Имя: " + _loginPage.Name.Text).Font("Times New Roman").FontSize(14); paragraph2.AppendLine("Отчество: " + _loginPage.ser2.Text).Font("Times New Roman").FontSize(14); paragraph2.AppendLine(); paragraph2.AppendLine("Всего вопросов: " + scrambled.Count()).Font("Times New Roman").FontSize(14); paragraph2.AppendLine("Правильных ответов: " + rightanswes + " (" + (Math.Truncate((double)rightanswes * 100 / (double)scrambled.Count())) + "%)").Font("Times New Roman").FontSize(14); Xceed.Document.NET.Paragraph paragraph3 = document.InsertParagraph().Font("Times New Roman").FontSize(14); paragraph3.Alignment = Alignment.right; paragraph3.Font("Times New Roman"); paragraph3.FontSize(14); paragraph3.AppendLine(); DateTime time = DateTime.Today; if (time.Month < 10) { paragraph3.AppendLine("Дата: " + time.Day + ".0" + time.Month + "." + time.Year).Font("Times New Roman").FontSize(14); } else { paragraph3.AppendLine("Дата: " + time.Day + "." + time.Month + "." + time.Year).Font("Times New Roman").FontSize(14); } paragraph3.AppendLine("ФИО контролирующего:___________________________________").Font("Times New Roman").FontSize(14); paragraph3.AppendLine("Подпись тестируемого:__________________________________").Font("Times New Roman").FontSize(14); paragraph3.InsertPageBreakAfterSelf(); document.InsertSectionPageBreak(); Xceed.Document.NET.Paragraph paragraph4 = document.InsertParagraph(); paragraph4.Alignment = Alignment.left; paragraph4.AppendLine("Неверные ответы:").Font("Times New Roman").FontSize(14).Alignment = Alignment.center; paragraph4.AppendLine().Alignment = Alignment.left;; foreach (FailedQuestion failed in otchet) { paragraph4.AppendLine(failed.text).Font("Times New Roman").FontSize(14); paragraph4.AppendLine("Ответ тестируемого:").Font("Times New Roman").FontSize(14); foreach (Answer answer in failed.FailedAnswers) { paragraph4.AppendLine("-" + answer.text).Font("Times New Roman").FontSize(14); } paragraph4.AppendLine("Правильный ответ:").Font("Times New Roman").FontSize(14); foreach (Answer answer in failed.CorrectAnswers) { paragraph4.AppendLine("-" + answer.text).Font("Times New Roman").FontSize(14); } paragraph4.AppendLine(); } paragraph4.AppendLine("Верные ответы:").Font("Times New Roman").FontSize(14).Alignment = Alignment.center;; paragraph4.AppendLine().Alignment = Alignment.left;; foreach (Question failed in otchet2) { paragraph4.AppendLine(failed.text).Font("Times New Roman").FontSize(14); paragraph4.AppendLine("Ответ тестируемого:").Font("Times New Roman").FontSize(14); foreach (Answer answer in failed.answers.Where(x => x.right == true)) { paragraph4.AppendLine("-" + answer.text).Font("Times New Roman").FontSize(14); } paragraph4.AppendLine(); } // сохраняем документ document.Save(); Process.Start(AppDomain.CurrentDomain.BaseDirectory + "Отчет " + FIOLABEL.Content + ".docx"); }