Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void uploadWord_Click(object sender, EventArgs e)
- {
- DataTable dt = new DataTable();
- dt.Columns.AddRange(new DataColumn[4] { new DataColumn("ID", typeof(string)), new DataColumn("ФИО пациента", typeof(string)), new DataColumn("Лечаший врач", typeof(string)), new DataColumn("Диагноз", typeof(string)) });
- dt.Rows.Add("ID", "ФИО пациента", "Лечащий врач", "Диагноз");
- for (int i = 0; i < entryGrid.RowCount; i++)
- {
- dt.Rows.Add(entryGrid.Rows[i].Cells[0].Value.ToString(), entryGrid.Rows[i].Cells[1].Value.ToString(), entryGrid.Rows[i].Cells[2].Value.ToString(), entryGrid.Rows[i].Cells[0].Value.ToString());
- }
- dt.Rows.Add("", "", "", "");
- dt.Rows.Add("ID", "ФИО врача", "E-mail", "Специальность");
- for (int i = 0; i < entryGrid.RowCount; i++)
- {
- dt.Rows.Add(doctorsGrid.Rows[i].Cells[0].Value.ToString(), doctorsGrid.Rows[i].Cells[1].Value.ToString(), doctorsGrid.Rows[i].Cells[2].Value.ToString(), doctorsGrid.Rows[i].Cells[0].Value.ToString());
- }
- string[] splitString = { "bin" };
- // Path of blank document.
- CreateWordDocument("output.docx", dt);
- //Открываем полученный документ
- MessageBox.Show("Успешно экспортировано! Открываем документ...");
- Process.Start("output.docx");
- }
- public void CreateWordDocument(string filePath, DataTable data)
- {
- WordprocessingDocument doc = WordprocessingDocument.Create(filePath, WordprocessingDocumentType.Document);
- MainDocumentPart mainDocPart = doc.AddMainDocumentPart();
- mainDocPart.Document = new Document();
- Body body = new Body();
- mainDocPart.Document.Append(body);
- DocumentFormat.OpenXml.Wordprocessing.Table table = new DocumentFormat.OpenXml.Wordprocessing.Table();
- for (int i = 0; i < data.Rows.Count; ++i)
- {
- TableRow row = new TableRow();
- for (int j = 0; j < data.Columns.Count; j++)
- {
- TableCell cell = new TableCell();
- cell.Append(new Paragraph(new DocumentFormat.OpenXml.Wordprocessing.Run(new DocumentFormat.OpenXml.Wordprocessing.Text(data.Rows[i][j].ToString()))));
- cell.Append(new TableCellProperties(new TableCellWidth { Type = TableWidthUnitValues.Dxa, Width = "3000" }, new TableBorders(new TopBorder() { Val = new EnumValue<BorderValues>(BorderValues.Birds), Size = 24 },
- new BottomBorder() { Val = new EnumValue<BorderValues>(BorderValues.Birds), Size = 12 },
- new LeftBorder() { Val = new EnumValue<BorderValues>(BorderValues.Birds), Size = 12 },
- new RightBorder() { Val = new EnumValue<BorderValues>(BorderValues.Birds), Size = 12 },
- new InsideHorizontalBorder() { Val = new EnumValue<BorderValues>(BorderValues.Birds), Size = 12 },
- new InsideVerticalBorder() { Val = new EnumValue<BorderValues>(BorderValues.Birds), Size = 12 })));
- row.Append(cell);
- }
- table.Append(row);
- }
- body.Append(table);
- doc.MainDocumentPart.Document.Save();
- doc.Dispose();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement