public void OnTableButton(Office.IRibbonControl control) { object missing = System.Type.Missing; Word.Range currentRange = Globals.ThisAddIn.Application.Selection.Range; Word.Table newTable = Globals.ThisAddIn.Application.ActiveDocument.Tables.Add( currentRange, 3, 4, ref missing, ref missing); // Get all of the borders except for the diagonal borders. Word.Border[] borders = new Word.Border[6]; borders[0] = newTable.Borders[Word.WdBorderType.wdBorderLeft]; borders[1] = newTable.Borders[Word.WdBorderType.wdBorderRight]; borders[2] = newTable.Borders[Word.WdBorderType.wdBorderTop]; borders[3] = newTable.Borders[Word.WdBorderType.wdBorderBottom]; borders[4] = newTable.Borders[Word.WdBorderType.wdBorderHorizontal]; borders[5] = newTable.Borders[Word.WdBorderType.wdBorderVertical]; // Format each of the borders. foreach (Word.Border border in borders) { border.LineStyle = Word.WdLineStyle.wdLineStyleSingle; border.Color = Word.WdColor.wdColorBlue; } }
public void OnTableButton(MSOffice.IRibbonControl control) { MessageBox.Show("Функция не реализована на данный момент.", "Нет реализации", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; object missing = System.Type.Missing; Word.Range currentRange = Globals.ThisAddIn.Application.Selection.Range; Word.Table newTable = Globals.ThisAddIn.Application.ActiveDocument.Tables.Add( currentRange, 3, 4, ref missing, ref missing); // Get all of the borders except for the diagonal borders. Word.Border[] borders = new Word.Border[6]; borders[0] = newTable.Borders[Word.WdBorderType.wdBorderLeft]; borders[1] = newTable.Borders[Word.WdBorderType.wdBorderRight]; borders[2] = newTable.Borders[Word.WdBorderType.wdBorderTop]; borders[3] = newTable.Borders[Word.WdBorderType.wdBorderBottom]; borders[4] = newTable.Borders[Word.WdBorderType.wdBorderHorizontal]; borders[5] = newTable.Borders[Word.WdBorderType.wdBorderVertical]; // Format each of the borders. foreach (Word.Border border in borders) { border.LineStyle = Word.WdLineStyle.wdLineStyleSingle; border.Color = Word.WdColor.wdColorBlue; } }
/// <summary> /// Establece el estilo de la arista de una celda. /// </summary> /// <param name="cell">Celda a formatear.</param> /// <param name="style">Estilo de la línea.</param> /// <param name="borderType">Arista a colorear.</param> /// <param name="color">Color de la línea.</param> private void SetCellBorder(Word.Cell cell, Word.WdLineStyle style = Word.WdLineStyle.wdLineStyleSingle, Word.WdBorderType borderType = Word.WdBorderType.wdBorderBottom, Word.WdColor color = Word.WdColor.wdColorBlack) { Word.Border border = cell.Borders[borderType]; border.Visible = true; border.LineStyle = style; border.LineWidth = Word.WdLineWidth.wdLineWidth050pt; border.Color = color; }
public void copy2(ref Word.Borders extBorders) { extBorders.AlwaysInFront = this.AlwaysInFront; //extBorders.Count = this.Count; //extBorders.Creator = this.Creator; try { extBorders.DistanceFrom = this.DistanceFrom; extBorders.DistanceFromBottom = this.DistanceFromBottom; extBorders.DistanceFromLeft = this.DistanceFromLeft; extBorders.DistanceFromRight = this.DistanceFromRight; extBorders.DistanceFromTop = this.DistanceFromTop; } catch (System.Exception ex) { } finally { } extBorders.Enable = this.Enable; extBorders.EnableFirstPageInSection = this.EnableFirstPageInSection; extBorders.EnableOtherPagesInSection = this.EnableOtherPagesInSection; //extBorders.HasHorizontal = this.HasHorizontal; //extBorders.HasVertical = this.HasVertical; extBorders.InsideColor = this.InsideColor; extBorders.InsideColorIndex = this.InsideColorIndex; extBorders.InsideLineStyle = this.InsideLineStyle; extBorders.InsideLineWidth = this.InsideLineWidth; extBorders.JoinBorders = this.JoinBorders; extBorders.OutsideColor = this.OutsideColor; extBorders.OutsideColorIndex = this.OutsideColorIndex; extBorders.OutsideLineStyle = this.OutsideLineStyle; extBorders.OutsideLineWidth = this.OutsideLineWidth; extBorders.Shadow = this.Shadow; extBorders.SurroundFooter = this.SurroundFooter; extBorders.SurroundHeader = this.SurroundHeader; ClassBorder classbd = null; for (int i = (int)WdBorderType.wdBorderVertical; i <= (int)WdBorderType.wdBorderTop; i++) { classbd = (ClassBorder)m_hashBorder[(WdBorderType)i]; if (classbd != null) { Word.Border bd = extBorders[(WdBorderType)i]; classbd.copy2(ref bd); } } return; }
private void wordToolStripMenuItem_Click(object sender, EventArgs e) { saveFileDialog2.Filter = "doc files (*.doc)|*.doc|All files (*.*)|*.*"; saveFileDialog2.FilterIndex = 2; saveFileDialog2.RestoreDirectory = true; if (saveFileDialog2.ShowDialog() == DialogResult.OK) { Microsoft.Office.Interop.Word.Application application = new Microsoft.Office.Interop.Word.Application(); Object missing = Type.Missing; Word.Document word1 = application.Documents.Add(ref missing, ref missing, ref missing, ref missing); //object text = "tesfsdfkslghsdgjh"; //word1.Paragraphs[1].Range.InsertParagraphAfter(); //word1.Paragraphs[1].Range.Text = "asaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; //word1.Footnotes.Location = Word.WdFootnoteLocation.wdBeneathText; //word1.Footnotes.NumberStyle = Word.WdNoteNumberStyle.wdNoteNumberStyleLowercaseRoman; //word1.Footnotes.Add(word1.Paragraphs[1].Range.Words[2].Characters[2], ref missing, ref text); Microsoft.Office.Interop.Word.Document doc = application.ActiveDocument; Microsoft.Office.Interop.Word.Range range = doc.Paragraphs[doc.Paragraphs.Count].Range; dataSetTemp = dbw1.ReadMetricsByReport(listView2.Items[listView2.SelectedIndices[0]].Text); doc.Tables.Add(range, dataSetTemp.Tables[0].Rows.Count + 1, 6, ref missing, ref missing); doc.Tables[1].Cell(1, 1).Range.Text = "NAME metric"; doc.Tables[1].Cell(1, 2).Range.Text = "MIN value"; doc.Tables[1].Cell(1, 3).Range.Text = "CUR value"; doc.Tables[1].Cell(1, 4).Range.Text = "MAX value"; doc.Tables[1].Cell(1, 5).Range.Text = "VALUE"; doc.Tables[1].Cell(1, 6).Range.Text = "RATE"; for (int i = 0; i < dataSetTemp.Tables[0].Rows.Count; i++) { dataSetTemp1 = dbw1.ReadInfoMetricByReportMetric(listView2.Items[listView2.SelectedIndices[0]].Text, dataSetTemp.Tables[0].Rows[i].ItemArray[0].ToString()); doc.Tables[1].Cell(i + 2, 1).Range.Text = dataSetTemp.Tables[0].Rows[i].ItemArray[0].ToString(); doc.Tables[1].Cell(i + 2, 2).Range.Text = dataSetTemp1.Tables[0].Rows[0].ItemArray[2].ToString(); doc.Tables[1].Cell(i + 2, 3).Range.Text = dataSetTemp1.Tables[0].Rows[0].ItemArray[0].ToString(); doc.Tables[1].Cell(i + 2, 4).Range.Text = dataSetTemp1.Tables[0].Rows[0].ItemArray[3].ToString(); doc.Tables[1].Cell(i + 2, 5).Range.Text = Double.Parse(dataSetTemp1.Tables[0].Rows[0].ItemArray[4].ToString()).ToString("F5"); doc.Tables[1].Cell(i + 2, 6).Range.Text = dataSetTemp1.Tables[0].Rows[0].ItemArray[5].ToString(); } doc.Tables[1].Columns.AutoFit(); Word.Border[] borders = new Word.Border[6]; Word.Table tbl = doc.Tables[doc.Tables.Count]; borders[0] = tbl.Borders[Word.WdBorderType.wdBorderLeft]; borders[1] = tbl.Borders[Word.WdBorderType.wdBorderRight]; borders[2] = tbl.Borders[Word.WdBorderType.wdBorderTop]; borders[3] = tbl.Borders[Word.WdBorderType.wdBorderBottom]; borders[4] = tbl.Borders[Word.WdBorderType.wdBorderHorizontal]; borders[5] = tbl.Borders[Word.WdBorderType.wdBorderVertical]; foreach (Word.Border border in borders) { border.LineStyle = Word.WdLineStyle.wdLineStyleSingle; border.Color = Word.WdColor.wdColorBlack; } application.Documents[word1].SaveAs(saveFileDialog2.FileName, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing); application.Quit(); string info = "Doc file saved at\n" + saveFileDialog2.FileName; MessageBox.Show(this, info, "Info", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
private void button1_Click(object sender, EventArgs e) { String name; String mark; List <String> one = new List <String>(); List <String> two = new List <String>(); command = new dabse.OleDbCommand("Select Дисциплины.Название, Дисциплины_обучение.Балл From Дисциплины, Дисциплины_обучение, Студенты Where Дисциплины.Код = Дисциплины_обучение.Код_дисциплины and Студенты.Шифр = Дисциплины_обучение.Шифр_студента and Студенты.Шифр = " + firststudensshifr.Text + " order by Дисциплины_обучение.Балл, Дисциплины.Название", Date_baseone); dabse.OleDbDataReader result = command.ExecuteReader(); wooord.Application app = new wooord.Application(); Object missing = Type.Missing; app.Documents.Add(ref missing, ref missing, ref missing, ref missing); wooord.Document docec = app.ActiveDocument; wooord.Range range = docec.Paragraphs[docec.Paragraphs.Count].Range; while (result.Read()) { name = result[1].ToString(); mark = result[0].ToString(); one.Add(name); two.Add(mark); } int len = two.Count; docec.Tables.Add(range, len + 1, 2, ref missing, ref missing); docec.Tables[1].Cell(1, 1).Range.Text = "Название дисциплины"; docec.Tables[1].Cell(1, 2).Range.Text = "Балл"; for (int i = 0; i < len; i++) { docec.Tables[1].Cell(i + 2, 1).Range.Text = two[i]; docec.Tables[1].Cell(i + 2, 2).Range.Text = one[i]; } wooord.Border[] bords = new wooord.Border[6]; wooord.Table table = docec.Tables[docec.Tables.Count]; bords[0] = table.Borders[wooord.WdBorderType.wdBorderLeft]; bords[1] = table.Borders[wooord.WdBorderType.wdBorderRight]; bords[2] = table.Borders[wooord.WdBorderType.wdBorderTop]; bords[3] = table.Borders[wooord.WdBorderType.wdBorderBottom]; bords[4] = table.Borders[wooord.WdBorderType.wdBorderVertical]; bords[5] = table.Borders[wooord.WdBorderType.wdBorderHorizontal]; foreach (wooord.Border border in bords) { border.LineStyle = wooord.WdLineStyle.wdLineStyleSingle; border.Color = wooord.WdColor.wdColorBlack; } app.Visible = true; }
// 复制到对象 public void copy2(ref Word.Border extBorder) { extBorder.ArtStyle = this.ArtStyle; // 进行赋值 extBorder.ArtWidth = this.ArtWidth; // 进行赋值 extBorder.Color = this.Color; // 进行赋值 extBorder.ColorIndex = this.ColorIndex; // 进行赋值 //extBorder.Creator = this.Creator; //extBorder.Inside = this.Inside; extBorder.LineStyle = this.LineStyle; // 进行赋值 extBorder.LineWidth = this.LineWidth; // 进行赋值 extBorder.Visible = this.Visible; // 进行赋值 return; }
public bool Visible; // { get; set; } // copy public void clone(Word.Border obd) { this.ArtStyle = obd.ArtStyle; // 进行赋值 this.ArtWidth = obd.ArtWidth; // 进行赋值 this.Color = obd.Color; // 进行赋值 this.ColorIndex = obd.ColorIndex; // 进行赋值 this.Creator = obd.Creator; // 进行赋值 this.Inside = obd.Inside; // 进行赋值 this.LineStyle = obd.LineStyle; // 进行赋值 this.LineWidth = obd.LineWidth; // 进行赋值 this.Visible = obd.Visible; // 进行赋值 return; }
private void btnGenTable_Click(object sender, EventArgs e) { //Word.Document document = Globals.ThisAddIn.Application.ActiveDocument; //object start = 0; //object end = 0; //Word.Range tableLocation = (Word.Range)document.Range(ref start, ref end); //tableLocation.Font.Size = 8; //object indentStyle = "Normal Indent"; //tableLocation.set_Style(ref indentStyle); //document.Tables.Add(tableLocation, // Convert.ToInt32(txtNoOfRows.Text), Convert.ToInt32(txtNoOfRows.Text)); object missing = System.Type.Missing; Word.Range currentRange = Globals.ThisAddIn.Application.Selection.Range; Word.Table newTable = Globals.ThisAddIn.Application.ActiveDocument.Tables.Add( currentRange, Convert.ToInt32(txtNoOfRows.Text), Convert.ToInt32(txtNoOfRows.Text), ref missing, ref missing); // Get all of the borders except for the diagonal borders. Word.Border[] borders = new Word.Border[6]; borders[0] = newTable.Borders[Word.WdBorderType.wdBorderLeft]; borders[1] = newTable.Borders[Word.WdBorderType.wdBorderRight]; borders[2] = newTable.Borders[Word.WdBorderType.wdBorderTop]; borders[3] = newTable.Borders[Word.WdBorderType.wdBorderBottom]; borders[4] = newTable.Borders[Word.WdBorderType.wdBorderHorizontal]; borders[5] = newTable.Borders[Word.WdBorderType.wdBorderVertical]; // Format each of the borders. foreach (Word.Border border in borders) { border.LineStyle = Word.WdLineStyle.wdLineStyleSingle; border.Color = Word.WdColor.wdColorBlue; } }
public void OnTableButton(Office.IRibbonControl control) { var missing = Type.Missing; var currentRange = Globals.ThisAddIn.Application.Selection.Range; var newTable = Globals.ThisAddIn.Application.ActiveDocument.Tables.Add(Range: currentRange, NumRows: 3, NumColumns: 4, DefaultTableBehavior: ref missing, AutoFitBehavior: ref missing); // Get all of the borders except for the diagonal borders. var borders = new Word.Border[6]; borders[0] = newTable.Borders[Word.WdBorderType.wdBorderLeft]; borders[1] = newTable.Borders[Word.WdBorderType.wdBorderRight]; borders[2] = newTable.Borders[Word.WdBorderType.wdBorderTop]; borders[3] = newTable.Borders[Word.WdBorderType.wdBorderBottom]; borders[4] = newTable.Borders[Word.WdBorderType.wdBorderHorizontal]; borders[5] = newTable.Borders[Word.WdBorderType.wdBorderVertical]; // Format each of the borders. foreach (var border in borders) { border.LineStyle = Word.WdLineStyle.wdLineStyleSingle; border.Color = Word.WdColor.wdColorBlue; } }
//</Snippet3> //<Snippet4> public void OnTableButton(Office.IRibbonControl control) { object missing = System.Type.Missing; Word.Range currentRange = Globals.ThisAddIn.Application.Selection.Range; Word.Table newTable = Globals.ThisAddIn.Application.ActiveDocument.Tables.Add( currentRange, 3, 4, ref missing, ref missing); // Get all of the borders except for the diagonal borders. Word.Border[] borders = new Word.Border[6]; borders[0] = newTable.Borders[Word.WdBorderType.wdBorderLeft]; borders[1] = newTable.Borders[Word.WdBorderType.wdBorderRight]; borders[2] = newTable.Borders[Word.WdBorderType.wdBorderTop]; borders[3] = newTable.Borders[Word.WdBorderType.wdBorderBottom]; borders[4] = newTable.Borders[Word.WdBorderType.wdBorderHorizontal]; borders[5] = newTable.Borders[Word.WdBorderType.wdBorderVertical]; // Format each of the borders. foreach (Word.Border border in borders) { border.LineStyle = Word.WdLineStyle.wdLineStyleSingle; border.Color = Word.WdColor.wdColorBlue; } }
/// <summary> /// Создает и отправляет пользоваетеляю файл с результатами сесии группы /// </summary> /// <param name="subjectID">Идентификатор предмета</param> /// <param name="groupID">Идентификатор группы</param> /// <returns>Имя файла для загрузки</returns> public string Session(int subjectID, int groupID) { string fileName = "session" + "_" + DateTime.Now.ToString("dd_MM_yyyy") + ".docx"; DeleteFile(fileName); Group @group = new Group(groupID); group.GetInformationAboutUserFromDB(); Student[] students = group.GetStudent(); Subject subject = new Subject(subjectID); subject.GetInformationAboutUserFromDB(); Lecturer lecturer = new Lecturer(subject.LecturerID); lecturer.GetInformationAboutUserFromDB(); Examination[] examinations = subject.GetSession(group.ID); if (examinations == null) { return(null); } Microsoft.Office.Interop.Word.Application applicationWord = new Microsoft.Office.Interop.Word.Application(); applicationWord.Documents.Add(Type.Missing, false, Microsoft.Office.Interop.Word.WdNewDocumentType.wdNewBlankDocument, false); Microsoft.Office.Interop.Word.Document documentWord = applicationWord.Documents.get_Item(1); documentWord.Activate(); //applicationWord.Visible = true; Microsoft.Office.Interop.Word.Paragraph documentParagraph = documentWord.Paragraphs.First; documentParagraph.Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphRight; documentParagraph.Range.Font.Bold = 1; documentParagraph.Range.Text = "Іспит"; documentParagraph = documentWord.Paragraphs.Add().Next(); documentParagraph.Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter; documentParagraph.Range.Font.Bold = 0; documentParagraph.Range.Text = "Національний технічний університет України \"Київський політехнічний інститут\""; documentParagraph = documentWord.Paragraphs.Add().Next(); documentParagraph.Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter; documentParagraph.Range.Font.Bold = 1; documentParagraph.Range.Text = "Факультет інформатики та обчислювальної техніки"; documentParagraph = documentWord.Paragraphs.Add().Next(); documentParagraph.Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter; documentParagraph.Range.Font.Bold = 0; documentParagraph.Range.Text = group.Name; documentParagraph = documentWord.Paragraphs.Add().Next(); documentParagraph.Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter; documentParagraph.Range.Font.Bold = 1; documentParagraph.Range.Text = "Заліково-екзаменаційна відомость № " + (new Random()).Next(20, 700); documentParagraph = documentWord.Paragraphs.Add().Next(); documentParagraph.Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphLeft; documentParagraph.Range.Font.Bold = 0; documentParagraph.Range.Font.Underline = Microsoft.Office.Interop.Word.WdUnderline.wdUnderlineSingle; documentParagraph.Range.Text = subject.Name; documentParagraph = documentWord.Paragraphs.Add().Next(); documentParagraph.Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphLeft; documentParagraph.Range.Font.Bold = 0; documentParagraph.Range.Font.Underline = Microsoft.Office.Interop.Word.WdUnderline.wdUnderlineNone; documentParagraph.Range.Text = "за " + students[0].CurrentSemester + " навчальний семетр" + "\t\t Дата _____________"; documentParagraph = documentWord.Paragraphs.Add().Next(); documentParagraph.Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphLeft; documentParagraph.Range.Font.Bold = 0; documentParagraph.Range.Text = "Екзаменатор " + lecturer.ShortName; documentParagraph = documentWord.Paragraphs.Add().Next(); Microsoft.Office.Interop.Word.Table table = documentWord.Tables.Add(documentParagraph.Range, students.Length + 2, 7); Microsoft.Office.Interop.Word.Border[] borders = new Microsoft.Office.Interop.Word.Border[6]; //массив бордеров borders[0] = table.Borders[Microsoft.Office.Interop.Word.WdBorderType.wdBorderLeft]; //левая граница borders[1] = table.Borders[Microsoft.Office.Interop.Word.WdBorderType.wdBorderRight]; //правая граница borders[2] = table.Borders[Microsoft.Office.Interop.Word.WdBorderType.wdBorderTop]; //нижняя граница borders[3] = table.Borders[Microsoft.Office.Interop.Word.WdBorderType.wdBorderBottom]; //верхняя граница borders[4] = table.Borders[Microsoft.Office.Interop.Word.WdBorderType.wdBorderHorizontal]; //горизонтальная граница borders[5] = table.Borders[Microsoft.Office.Interop.Word.WdBorderType.wdBorderVertical]; //вертикальная граница foreach (Microsoft.Office.Interop.Word.Border border in borders) { border.LineStyle = Microsoft.Office.Interop.Word.WdLineStyle.wdLineStyleSingle; //ставим стиль границы border.Color = Microsoft.Office.Interop.Word.WdColor.wdColorBlack; //задаем цвет границы } documentWord.Range(table.Cell(1, 1).Range.Start, table.Cell(2, 1).Range.End).Select(); applicationWord.Selection.Cells.Merge(); documentWord.Range(table.Cell(1, 2).Range.Start, table.Cell(2, 2).Range.End).Select(); applicationWord.Selection.Cells.Merge(); documentWord.Range(table.Cell(1, 3).Range.Start, table.Cell(2, 3).Range.End).Select(); applicationWord.Selection.Cells.Merge(); documentWord.Range(table.Cell(1, 5).Range.Start, table.Cell(1, 6).Range.End).Select(); applicationWord.Selection.Cells.Merge(); documentWord.Range(table.Cell(1, 6).Range.Start, table.Cell(2, 7).Range.End).Select(); applicationWord.Selection.Cells.Merge(); table.Cell(1, 1).Range.Text = "№\nз/п"; table.Cell(1, 2).Range.Text = "Прізвище, ініціали студента"; table.Cell(1, 3).Range.Text = "№ залікової книжки"; table.Cell(1, 4).Range.Text = "Рейтингові бали"; table.Cell(2, 4).Range.Text = "Всього"; table.Cell(1, 5).Range.Text = "Результат"; table.Cell(2, 5).Range.Text = "Оцінка ECTS"; table.Cell(2, 6).Range.Text = "Традиційна оцінка"; table.Cell(1, 6).Range.Text = "Підпис виклад."; for (int i = 0, end = students.Length; i < end; i++) { table.Cell(i + 3, 1).Range.Text = (i + 1).ToString(); table.Cell(i + 3, 2).Range.Text = students[i].ShortName; table.Cell(i + 3, 3).Range.Text = students[i].RecordBook; table.Cell(i + 3, 4).Range.Text = examinations[i].Mark.ToString(); table.Cell(i + 3, 5).Range.Text = Marks.ToBolognaSystem(examinations[i].Mark, 100); table.Cell(i + 3, 6).Range.Text = Marks.ToTraditional(Marks.ToBolognaSystem(examinations[i].Mark, 100)); } documentWord.SaveAs(Server.MapPath("~/Files") + "\\" + fileName); documentWord.Close(); applicationWord.Quit(); return(fileName); }
private void wordToolStripMenuItem_Click(object sender, EventArgs e) { saveFileDialog2.Filter = "doc files (*.doc)|*.doc|All files (*.*)|*.*"; saveFileDialog2.FilterIndex = 2; saveFileDialog2.RestoreDirectory = true; if (saveFileDialog2.ShowDialog() == DialogResult.OK) { Microsoft.Office.Interop.Word.Application application = new Microsoft.Office.Interop.Word.Application(); Object missing = Type.Missing; Word.Document word1 = application.Documents.Add(ref missing, ref missing, ref missing, ref missing); //object text = "tesfsdfkslghsdgjh"; //word1.Paragraphs[1].Range.InsertParagraphAfter(); //word1.Paragraphs[1].Range.Text = "asaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; //word1.Footnotes.Location = Word.WdFootnoteLocation.wdBeneathText; //word1.Footnotes.NumberStyle = Word.WdNoteNumberStyle.wdNoteNumberStyleLowercaseRoman; //word1.Footnotes.Add(word1.Paragraphs[1].Range.Words[2].Characters[2], ref missing, ref text); Microsoft.Office.Interop.Word.Document doc = application.ActiveDocument; Microsoft.Office.Interop.Word.Range range = doc.Paragraphs[doc.Paragraphs.Count].Range; dataSetTemp = dbw1.ReadMetricsByReport(listView2.Items[listView2.SelectedIndices[0]].Text); doc.Tables.Add(range, dataSetTemp.Tables[0].Rows.Count + 1, 6, ref missing, ref missing); doc.Tables[1].Cell(1, 1).Range.Text = "NAME metric"; doc.Tables[1].Cell(1, 2).Range.Text = "MIN value"; doc.Tables[1].Cell(1, 3).Range.Text = "CUR value"; doc.Tables[1].Cell(1, 4).Range.Text = "MAX value"; doc.Tables[1].Cell(1, 5).Range.Text = "VALUE"; doc.Tables[1].Cell(1, 6).Range.Text = "RATE"; for (int i = 0; i < dataSetTemp.Tables[0].Rows.Count; i++) { dataSetTemp1 = dbw1.ReadInfoMetricByReportMetric(listView2.Items[listView2.SelectedIndices[0]].Text, dataSetTemp.Tables[0].Rows[i].ItemArray[0].ToString()); doc.Tables[1].Cell(i + 2, 1).Range.Text = dataSetTemp.Tables[0].Rows[i].ItemArray[0].ToString(); doc.Tables[1].Cell(i + 2, 2).Range.Text = dataSetTemp1.Tables[0].Rows[0].ItemArray[2].ToString(); doc.Tables[1].Cell(i + 2, 3).Range.Text = dataSetTemp1.Tables[0].Rows[0].ItemArray[0].ToString(); doc.Tables[1].Cell(i + 2, 4).Range.Text = dataSetTemp1.Tables[0].Rows[0].ItemArray[3].ToString(); doc.Tables[1].Cell(i + 2, 5).Range.Text = Double.Parse(dataSetTemp1.Tables[0].Rows[0].ItemArray[4].ToString()).ToString("F5"); doc.Tables[1].Cell(i + 2, 6).Range.Text = dataSetTemp1.Tables[0].Rows[0].ItemArray[5].ToString(); } doc.Tables[1].Columns.AutoFit(); Word.Border[] borders = new Word.Border[6]; Word.Table tbl = doc.Tables[doc.Tables.Count]; borders[0] = tbl.Borders[Word.WdBorderType.wdBorderLeft]; borders[1] = tbl.Borders[Word.WdBorderType.wdBorderRight]; borders[2] = tbl.Borders[Word.WdBorderType.wdBorderTop]; borders[3] = tbl.Borders[Word.WdBorderType.wdBorderBottom]; borders[4] = tbl.Borders[Word.WdBorderType.wdBorderHorizontal]; borders[5] = tbl.Borders[Word.WdBorderType.wdBorderVertical]; foreach (Word.Border border in borders) { border.LineStyle = Word.WdLineStyle.wdLineStyleSingle; border.Color = Word.WdColor.wdColorBlack; } application.Documents[word1].SaveAs(saveFileDialog2.FileName, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing); application.Quit(); string info = "Doc file saved at\n" + saveFileDialog2.FileName; MessageBox.Show(this, info, "Info", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
private void button2_Click(object sender, EventArgs e) { String surname; String name; String middlename; String mark; List <String> surnameMas = new List <String>(); List <String> nameMas = new List <String>(); List <String> middlenameMas = new List <String>(); List <String> markMas = new List <String>(); var Command = new dabse.OleDbCommand("SELECT DISTINCT Студенты.Фамилия, Студенты.Имя, Студенты.Отчество, Дисциплины_обучение.Балл FROM ((Дисциплины_обучение INNER JOIN Дисциплины ON Дисциплины_обучение.Код_дисциплины = Дисциплины.Код) INNER JOIN Студенты ON Дисциплины_обучение.Шифр_студента = Студенты.Шифр), Группы_обучение WHERE Дисциплины.Название = " + "\"" + secondnameofsubject.Text + "\" AND Группы_обучение.Номер_группы = " + secondnumberofgroup.Text, Date_baseone); dabse.OleDbDataReader Ask2 = Command.ExecuteReader(); wooord.Application application = new wooord.Application(); Object missing = Type.Missing; application.Documents.Add(ref missing, ref missing, ref missing, ref missing); wooord.Document doc = application.ActiveDocument; wooord.Range range = doc.Paragraphs[doc.Paragraphs.Count].Range; while (Ask2.Read() == true) { surname = Ask2[0].ToString(); name = Ask2[1].ToString(); middlename = Ask2[2].ToString(); mark = Ask2[3].ToString(); surnameMas.Add(surname); nameMas.Add(name); middlenameMas.Add(middlename); markMas.Add(mark); } int length = markMas.Count; doc.Tables.Add(range, length + 1, 6, ref missing, ref missing); doc.Tables[1].Cell(1, 1).Range.Text = "Фамилия"; doc.Tables[1].Cell(1, 2).Range.Text = "Имя"; doc.Tables[1].Cell(1, 3).Range.Text = "Отчество"; doc.Tables[1].Cell(1, 4).Range.Text = "Балл"; doc.Tables[1].Cell(1, 5).Range.Text = "Оценка"; doc.Tables[1].Cell(1, 6).Range.Text = "Подпись экзаменатора"; for (int i = 0; i < length; i++) { doc.Tables[1].Cell(i + 2, 1).Range.Text = surnameMas[i]; doc.Tables[1].Cell(i + 2, 2).Range.Text = nameMas[i]; doc.Tables[1].Cell(i + 2, 3).Range.Text = middlenameMas[i]; doc.Tables[1].Cell(i + 2, 4).Range.Text = markMas[i]; if (int.Parse(markMas[i]) >= 90 && int.Parse(markMas[i]) <= 100) { doc.Tables[1].Cell(i + 2, 5).Range.Text = "5"; } if (int.Parse(markMas[i]) >= 70 && int.Parse(markMas[i]) <= 89) { doc.Tables[1].Cell(i + 2, 5).Range.Text = "4"; } if (int.Parse(markMas[i]) >= 60 && int.Parse(markMas[i]) <= 69) { doc.Tables[1].Cell(i + 2, 5).Range.Text = "3"; } if (int.Parse(markMas[i]) >= 50 && int.Parse(markMas[i]) <= 59) { doc.Tables[1].Cell(i + 2, 5).Range.Text = "2"; } } wooord.Border[] borders = new wooord.Border[6]; wooord.Table tbl = doc.Tables[doc.Tables.Count]; borders[0] = tbl.Borders[wooord.WdBorderType.wdBorderLeft]; borders[1] = tbl.Borders[wooord.WdBorderType.wdBorderRight]; borders[2] = tbl.Borders[wooord.WdBorderType.wdBorderTop]; borders[3] = tbl.Borders[wooord.WdBorderType.wdBorderBottom]; borders[4] = tbl.Borders[wooord.WdBorderType.wdBorderHorizontal]; borders[5] = tbl.Borders[wooord.WdBorderType.wdBorderVertical]; foreach (wooord.Border border in borders) { border.LineStyle = wooord.WdLineStyle.wdLineStyleSingle; border.Color = wooord.WdColor.wdColorBlack; } application.Visible = true; }
public void GetNewReport(DataTable dt) { object oMissing = System.Reflection.Missing.Value; object unknow = Type.Missing; object start = 0; object end = 0; Microsoft.Office.Interop.Word.Range tableLocation = ActiveDocumentManager.getDefaultAD().Range(ref start, ref end); // 添加页眉 emrTaskPane.wordApp.ActiveWindow.View.Type = Word.WdViewType.wdOutlineView; emrTaskPane.wordApp.ActiveWindow.View.SeekView = Word.WdSeekView.wdSeekPrimaryHeader; emrTaskPane.wordApp.ActiveWindow.ActivePane.Selection.InsertAfter(""); emrTaskPane.wordApp.Selection.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphRight; //设置右对齐 emrTaskPane.wordApp.ActiveWindow.View.SeekView = Word.WdSeekView.wdSeekMainDocument; //跳出页眉设置 emrTaskPane.wordApp.Selection.ParagraphFormat.LineSpacing = 15f; //设置文档的行间距 //2012-07-29 LiuQi 删除页眉 int c = ActiveDocumentManager.getDefaultAD().Paragraphs[1].Borders.Count; emrTaskPane.wordApp.ActiveWindow.View.SeekView = Microsoft.Office.Interop.Word.WdSeekView.wdSeekCurrentPageHeader; Microsoft.Office.Interop.Word.Application WordApp; Microsoft.Office.Interop.Word.Document WordDoc; WordApp = new Microsoft.Office.Interop.Word.ApplicationClass(); if (c != 0) { Word.HeaderFooter hf = ActiveDocumentManager.getDefaultAD().Sections[1].Headers[Word.WdHeaderFooterIndex.wdHeaderFooterPrimary]; Word.Range r = hf.Range; //r.Start = r.End; r.Select(); Word.Border border = r.Borders[Word.WdBorderType.wdBorderBottom]; border.Visible = false; } //移动焦点并换行 object count = 14; object WdLine = Microsoft.Office.Interop.Word.WdUnits.wdLine; //换一行; emrTaskPane.wordApp.Selection.MoveDown(ref WdLine, ref count, ref unknow); //移动焦点 emrTaskPane.wordApp.Selection.MoveDown(ref WdLine, ref count, ref unknow); //移动焦点 emrTaskPane.wordApp.Selection.TypeParagraph(); //插入段落 Word.Range range = ActiveDocumentManager.getDefaultAD().Paragraphs.Last.Range; range.Start = ActiveDocumentManager.getDefaultAD().Paragraphs.Last.Range.End; range.Select(); //// range.Text = "病历质量月度评分表" + "(" + comboBox2.Text + "年" + comboBox1.Text + "月)"; if (hz) { range.Text = "各科室现岗病历质检情况一览表"; } else { range.Text = "现岗病历质量评分科室汇总表"; } range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter; range.Font.Name = "黑体"; range.Font.Size = 15.5f; range.Start = range.End; range.Select(); range.Text = dateTimePickerStart.Value.ToString() + "至" + dateTimePickerEnd.Value.ToString(); range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter; range.Font.Name = "黑体"; range.Font.Size = 10f; range.Start = range.End; range.Select(); ActiveDocumentManager.getDefaultAD().PageSetup.Orientation = Word.WdOrientation.wdOrientPortrait; ActiveDocumentManager.getDefaultAD().PageSetup.PageWidth = emrTaskPane.wordApp.CentimetersToPoints(29.7F); ActiveDocumentManager.getDefaultAD().PageSetup.PageHeight = emrTaskPane.wordApp.CentimetersToPoints(21F); int rows = 0; if (ks || qy) { rows = 9; } else { rows = 8; } Microsoft.Office.Interop.Word.Table newTable = ActiveDocumentManager.getDefaultAD().Tables.Add(emrTaskPane.wordApp.Selection.Range, dt.Rows.Count + 1, rows, ref unknow, ref unknow); //设置表格样式 newTable.Range.Font.Size = 11.0f; newTable.Borders.OutsideLineStyle = Word.WdLineStyle.wdLineStyleSingle; newTable.Borders.InsideLineStyle = Word.WdLineStyle.wdLineStyleSingle; emrTaskPane.wordApp.Selection.ParagraphFormat.LineSpacing = 15f;//设置文档的行间距 if (ks || qy) { newTable.Cell(1, 1).Range.Text = "科室"; newTable.Cell(1, 1).Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter; newTable.Cell(1, 2).Range.Text = "主治医师"; newTable.Cell(1, 2).Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter; newTable.Cell(1, 3).Range.Text = "病案号"; newTable.Cell(1, 3).Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter; newTable.Cell(1, 4).Range.Text = "住院日期"; newTable.Cell(1, 4).Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter; newTable.Cell(1, 5).Range.Text = "住院号"; newTable.Cell(1, 5).Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter; newTable.Cell(1, 6).Range.Text = "扣分项目"; newTable.Cell(1, 6).Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter; newTable.Cell(1, 7).Range.Text = "扣分原因"; newTable.Cell(1, 7).Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter; newTable.Cell(1, 8).Range.Text = "总得分"; newTable.Cell(1, 8).Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter; newTable.Cell(1, 9).Range.Text = "等级"; newTable.Cell(1, 9).Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter; newTable.Columns[1].Width = 60f; newTable.Columns[2].Width = 60f; newTable.Columns[3].Width = 70f;//能显示三个字 newTable.Columns[4].Width = 65f; newTable.Columns[5].Width = 60f; newTable.Columns[6].Width = 70f; newTable.Columns[7].Width = 220f; newTable.Columns[8].Width = 50f; newTable.Columns[9].Width = 40f; //if (dt.Rows.Count > 0) //{ // try // { // for (int i = 0; i < dt.Rows.Count; i++) // { // newTable.Cell(i + 2, 4).Range.Text = dt.Rows[i]["zyrq"].ToString(); // newTable.Cell(i + 2, 4).Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter; // newTable.Cell(i + 2, 1).Range.Text = dt.Rows[i]["ksmc"].ToString(); // newTable.Cell(i + 2, 1).Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter; // newTable.Cell(i + 2, 2).Range.Text = dt.Rows[i]["ysm"].ToString(); // newTable.Cell(i + 2, 2).Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter; // newTable.Cell(i + 2, 3).Range.Text = dt.Rows[i]["bah"].ToString(); // newTable.Cell(i + 2, 3).Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter; // newTable.Cell(i + 2, 5).Range.Text = dt.Rows[i]["zyh"].ToString(); // newTable.Cell(i + 2, 5).Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter; // newTable.Cell(i + 2, 6).Range.Text = dt.Rows[i]["kfxm"].ToString(); // newTable.Cell(i + 2, 6).Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphLeft; // newTable.Cell(i + 2, 7).Range.Text = dt.Rows[i]["kfyy"].ToString(); // newTable.Cell(i + 2, 7).Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter; // newTable.Cell(i + 2, 8).Range.Text = dt.Rows[i]["sdf"].ToString(); // newTable.Cell(i + 2, 8).Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter; // newTable.Cell(i + 2, 9).Range.Text = dt.Rows[i]["pj"].ToString(); // newTable.Cell(i + 2, 9).Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter; // } // verticalCellMerge(newTable, 2, 1); // verticalCellMerge(newTable, 2, 2); // verticalCellMerge(newTable, 2, 3); // verticalCellMerge(newTable, 2, 4); // verticalCellMerge(newTable, 2, 8); // verticalCellMerge(newTable, 2, 9); // verticalCellMerge(newTable, 2, 5); // // verticalCellMerge(newTable,2,5); // } // catch (Exception ex) // { // MessageBox.Show(ex.ToString()); // } //} if (dt.Rows.Count > 0) { try { for (int i = 0; i < dt.Rows.Count; i++) { newTable.Cell(i + 2, 4).Range.Text = dt.Rows[i]["住院日期"].ToString(); newTable.Cell(i + 2, 4).Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter; newTable.Cell(i + 2, 1).Range.Text = dt.Rows[i]["科室"].ToString(); newTable.Cell(i + 2, 1).Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter; newTable.Cell(i + 2, 2).Range.Text = dt.Rows[i]["质检医师"].ToString(); newTable.Cell(i + 2, 2).Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter; newTable.Cell(i + 2, 3).Range.Text = dt.Rows[i]["病案号"].ToString(); newTable.Cell(i + 2, 3).Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter; newTable.Cell(i + 2, 5).Range.Text = dt.Rows[i]["住院号"].ToString(); newTable.Cell(i + 2, 5).Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter; newTable.Cell(i + 2, 6).Range.Text = dt.Rows[i]["扣分项目"].ToString(); newTable.Cell(i + 2, 6).Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphLeft; newTable.Cell(i + 2, 7).Range.Text = dt.Rows[i]["扣分原因"].ToString(); newTable.Cell(i + 2, 7).Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter; newTable.Cell(i + 2, 8).Range.Text = dt.Rows[i]["总得分"].ToString(); newTable.Cell(i + 2, 8).Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter; newTable.Cell(i + 2, 9).Range.Text = dt.Rows[i]["评审结果"].ToString(); newTable.Cell(i + 2, 9).Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter; } verticalCellMerge(newTable, 2, 1); verticalCellMerge(newTable, 2, 2); verticalCellMerge(newTable, 2, 3); verticalCellMerge(newTable, 2, 4); verticalCellMerge(newTable, 2, 8); verticalCellMerge(newTable, 2, 9); verticalCellMerge(newTable, 2, 5); // verticalCellMerge(newTable,2,5); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } } } else { newTable.Cell(1, 1).Range.Text = "科室"; newTable.Cell(1, 1).Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter; newTable.Cell(1, 2).Range.Text = "病历质检数"; newTable.Cell(1, 2).Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter; newTable.Cell(1, 3).Range.Text = "甲级"; newTable.Cell(1, 3).Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter; newTable.Cell(1, 4).Range.Text = "甲级病历率"; newTable.Cell(1, 4).Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter; newTable.Cell(1, 5).Range.Text = "乙级"; newTable.Cell(1, 5).Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter; newTable.Cell(1, 6).Range.Text = "乙级病历率"; newTable.Cell(1, 6).Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter; newTable.Cell(1, 7).Range.Text = "丙级"; newTable.Cell(1, 7).Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter; newTable.Cell(1, 8).Range.Text = "丙级病历率"; newTable.Cell(1, 8).Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter; newTable.Columns[1].Width = 70f; newTable.Columns[2].Width = 70f; newTable.Columns[3].Width = 70f;//能显示三个字 newTable.Columns[4].Width = 70f; newTable.Columns[5].Width = 70f; newTable.Columns[6].Width = 70f; if (dt.Rows.Count > 0) { int k = 2; for (int i = 0; i < dt.Rows.Count; i++) { decimal bl = Convert.ToDecimal(dt.Rows[i]["病历率"].ToString()); string strbl = (Convert.ToDecimal(bl.ToString("0.00")) * 100).ToString() + "%"; if (i > 0) { if (dt.Rows[i]["科室"].ToString() == dt.Rows[i - 1]["科室"].ToString()) { newTable.Cell(k, 1).Range.Text = dt.Rows[i]["科室"].ToString(); newTable.Cell(k, 1).Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter; newTable.Cell(k, 2).Range.Text = dt.Rows[i]["科室质检数"].ToString(); newTable.Cell(k, 2).Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter; if (dt.Rows[i]["评级"].ToString() == "甲") { newTable.Cell(k, 3).Range.Text = dt.Rows[i]["病历数"].ToString(); newTable.Cell(k, 3).Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter; newTable.Cell(k, 4).Range.Text = strbl; newTable.Cell(k, 4).Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter; } else if (dt.Rows[i]["评级"].ToString() == "乙") { newTable.Cell(k, 5).Range.Text = dt.Rows[i]["病历数"].ToString(); newTable.Cell(k, 5).Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter; newTable.Cell(k, 6).Range.Text = strbl; newTable.Cell(k, 6).Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter; } else if (dt.Rows[i]["评级"].ToString() == "丙") { newTable.Cell(k, 7).Range.Text = dt.Rows[i]["病历数"].ToString(); newTable.Cell(k, 7).Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter; newTable.Cell(k, 8).Range.Text = strbl; newTable.Cell(k, 8).Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter; } } else { k++; newTable.Cell(k, 1).Range.Text = dt.Rows[i]["科室"].ToString(); newTable.Cell(k, 1).Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter; newTable.Cell(k, 2).Range.Text = dt.Rows[i]["科室质检数"].ToString();; newTable.Cell(k, 2).Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter; if (dt.Rows[i]["评级"].ToString() == "甲") { newTable.Cell(k, 3).Range.Text = dt.Rows[i]["病历数"].ToString(); newTable.Cell(k, 3).Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter; newTable.Cell(k, 4).Range.Text = strbl; newTable.Cell(k, 4).Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter; } else if (dt.Rows[i]["评级"].ToString() == "乙") { newTable.Cell(k, 5).Range.Text = dt.Rows[i]["病历数"].ToString(); newTable.Cell(k, 5).Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter; newTable.Cell(k, 6).Range.Text = strbl; newTable.Cell(k, 6).Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter; } else if (dt.Rows[i]["评级"].ToString() == "丙") { newTable.Cell(k, 7).Range.Text = dt.Rows[i]["病历数"].ToString(); newTable.Cell(k, 7).Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter; newTable.Cell(k, 8).Range.Text = strbl; newTable.Cell(k, 8).Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter; } } } else { newTable.Cell(i + 2, 1).Range.Text = dt.Rows[i]["科室"].ToString(); newTable.Cell(i + 2, 1).Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter; newTable.Cell(i + 2, 2).Range.Text = dt.Rows[i]["科室质检数"].ToString(); newTable.Cell(i + 2, 2).Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter; if (dt.Rows[i]["评级"].ToString() == "甲") { newTable.Cell(i + 2, 3).Range.Text = dt.Rows[i]["病历数"].ToString(); newTable.Cell(i + 2, 3).Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter; newTable.Cell(i + 2, 4).Range.Text = strbl; newTable.Cell(i + 2, 4).Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter; } else if (dt.Rows[i]["评级"].ToString() == "乙") { newTable.Cell(i + 2, 5).Range.Text = dt.Rows[i]["病历数"].ToString(); newTable.Cell(i + 2, 5).Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter; newTable.Cell(i + 2, 6).Range.Text = strbl; newTable.Cell(i + 2, 6).Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter; } else if (dt.Rows[i]["评级"].ToString() == "丙") { newTable.Cell(i + 2, 7).Range.Text = dt.Rows[i]["病历数"].ToString(); newTable.Cell(i + 2, 7).Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter; newTable.Cell(i + 2, 8).Range.Text = strbl; newTable.Cell(i + 2, 8).Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter; } } } //删除多余的行 for (int i = 2; i <= newTable.Rows.Count; i++) { if (newTable.Cell(i, 1).Range.Text == "\r\a") { newTable.Rows[i].Delete(); i = i - 2; } } } } object Line1 = Microsoft.Office.Interop.Word.WdUnits.wdLine;//换一行; //object WdLine = Microsoft.Office.Interop.Word.WdUnits.wdLine;//换一行; emrTaskPane.wordApp.Selection.MoveDown(ref Line1, ref count, ref unknow); //移动焦点 emrTaskPane.wordApp.Selection.MoveDown(ref Line1, ref count, ref unknow); //移动焦点 emrTaskPane.wordApp.Selection.TypeParagraph(); //插入段落 Word.Range range1 = ActiveDocumentManager.getDefaultAD().Paragraphs.Last.Range; range1.Start = ActiveDocumentManager.getDefaultAD().Paragraphs.Last.Range.End; int count2 = newTable.Rows.Count - 1; range1.Select(); range1.Text = "记录数共计" + count2 + "条"; range1.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphRight; range1.Font.Name = "黑体"; range1.Font.Size = 10f; range1.Start = range.End; //Globals.ThisAddIn.ShowNoteMenu(); //OperationEnableForStat(true); Cursor.Current = Cursors.Default; }