标签:using document styles except sys names his led div
//Title: 个人健康管理分析报告 using System; using System.Collections.Generic; using System.Linq; using System.Text; using Word = Microsoft.Office.Interop.Word; using System.Windows.Forms; using System.Data; using HMSClientServiceFactory.BASE.HMS; using Microsoft.Office.Interop.Word; using PdfiumViewer; using Syscom.Comm.Utility; using System.IO; using System.Drawing; using HMSClientServiceFactory.BASE.PUB; using System.Drawing.Imaging; namespace Syscom.HMS.Client.HMS.RPT { public class HmsRpt1070Client { IPubServiceManager PUBSM = new PubServiceManager(); #region 报告打印 Word.Application WordApp = new Word.Application(); Word.Document WordDoc = new Word.Document(); HmsServiceManager hmsService = new HmsServiceManager(); object Nothing = System.Reflection.Missing.Value; private string strMemberNo; int TableCount = 2; /// <summary> /// 打印报告 /// </summary> /// <param name="strRegisterNo">体检号</param> public HmsRpt1070Client(string strMemberNo, DataTable dtItem) { try { this.strMemberNo = strMemberNo; DataSet dsHms = new DataSet(); dsHms = hmsService.QueryDataSetBy1070(strMemberNo); System.Data.DataTable dtPatient = new System.Data.DataTable(); //查询客户信息 dtPatient = dsHms.Tables["HMS_MEMBER"]; //不同身份调用不同模板 string filename = System.Windows.Forms.Application.StartupPath + "\\RPT\\HMSRPT1070.dot"; try { WordDoc = WordApp.Documents.Add(filename); WordDoc = WordApp.ActiveDocument; } catch (Exception ex) { throw (ex); } if (dtPatient.Rows.Count > 0) { #region 模板页签中插入数据 //个人信息 WordDoc.Bookmarks.get_Item("Name").Range.Text = dtPatient.Rows[0]["PATIENT_NAME"].ToString(); WordDoc.Bookmarks.get_Item("Gender").Range.Text = dtPatient.Rows[0]["SEX"].ToString(); WordDoc.Bookmarks.get_Item("Birthday").Range.Text = dtPatient.Rows[0]["BIRTHDAY"].ToString(); WordDoc.Bookmarks.get_Item("Age").Range.Text = dtPatient.Rows[0]["AGE"].ToString(); WordDoc.Bookmarks.get_Item("Tel").Range.Text = dtPatient.Rows[0]["PHONE_NO"].ToString(); WordDoc.Bookmarks.get_Item("NurseName").Range.Text = dtPatient.Rows[0]["NURSE_NAME"].ToString(); WordDoc.Bookmarks.get_Item("Date").Range.Text = DateTime.Now.ToString("yyyy-MM-dd"); WordDoc.Bookmarks.get_Item("PATIENT_NAME").Range.Text = dtPatient.Rows[0]["PATIENT_NAME"].ToString() + (dtPatient.Rows[0]["PATIENT_SEX"].ToString().Trim() == "1" ? "先生" : "女士") + ":"; #endregion if (dtItem.Rows.Count > 0) { for (int n = 0; n < dtItem.Rows.Count - 1; n++) { CopyTable(); } DataTable dtHmsReportMemo = new DataTable("HMS_REPORT_MEMO"); dtHmsReportMemo = dsHms.Tables["HMS_REPORT_MEMO"]; DataTable dtMemberReport = new DataTable("HMS_MEMBER_REPORT"); dtMemberReport = dsHms.Tables["HMS_MEMBER_REPORT"]; DataTable dtMemberRecipe = new DataTable("HMS_MEMBER_RECIPE"); dtMemberRecipe = dsHms.Tables["HMS_MEMBER_RECIPE"]; for (int i = 0; i < dtItem.Rows.Count; i++) { WordDoc.Tables[TableCount].Cell(1, 1).Width = WordDoc.Tables[TableCount].Cell(1, 1).Width - 1; WordDoc.Tables[TableCount].Cell(1, 2).Range.Text = dtItem.Rows[i]["SYS_CODE_NAME"].ToString(); WordDoc.Tables[TableCount].Cell(1, 2).Range.Font.Color = WdColor.wdColorBlack; WordDoc.Tables[TableCount].Cell(1, 2).Range.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphLeft; WordDoc.Tables[TableCount].Cell(1, 2).Range.Font.Bold = 1; WordDoc.Tables[TableCount].Cell(1, 2).Range.Font.Size = 16; int iNewRow = 3; int iCol = 1; if (dtHmsReportMemo.Rows.Count > 0) { DataRow[] dr = dtHmsReportMemo.Select("REPORT_ID = ‘" + dtItem.Rows[i]["SYS_CODE"].ToString().Trim() + "‘"); if (dr.Length > 0) { WordDoc.Tables[TableCount].Cell(2, 1).Range.Text = dr[0]["MEMO"].ToString(); if (dtMemberReport.Rows.Count > 0) { DataRow[] drMemberReport = dtMemberReport.Select("REPORT_ID = ‘" + dr[0]["REPORT_ID"].ToString().Trim() + "‘"); if (drMemberReport.Length > 0) { for (int j = 0; j < drMemberReport.Length; j++) { if (j == 0) { WordDoc.Tables[TableCount].Rows[iNewRow].Borders.OutsideLineStyle = WdLineStyle.wdLineStyleSingle; WordDoc.Tables[TableCount].Rows[iNewRow].Borders.InsideLineStyle = WdLineStyle.wdLineStyleSingle; WordDoc.Content.Tables[TableCount].Rows.Add(ref Nothing); iNewRow += 1; } else { if (j % 3 == 0) { WordDoc.Content.Tables[TableCount].Rows.Add(ref Nothing); WordDoc.Content.Tables[TableCount].Rows.Add(ref Nothing); iNewRow += 2; } } iCol = j % 3 + 1; WordDoc.Tables[TableCount].Cell(iNewRow - 1, iCol).Range.Text = drMemberReport[j]["REPORT_DATE"].ToString().Trim(); WordDoc.Tables[TableCount].Cell(iNewRow - 1, iCol).Range.Font.Bold = 1; WordDoc.Tables[TableCount].Rows[iNewRow - 1].Range.Shading.BackgroundPatternColor = (WdColor)ColorTranslator.ToWin32(Color.FromArgb(204, 154, 255)); WordDoc.Tables[TableCount].Cell(iNewRow - 1, iCol).Range.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter; WordDoc.Tables[TableCount].Cell(iNewRow - 1, iCol).Range.Font.Size = 12; WordDoc.Tables[TableCount].Cell(iNewRow, iCol).Range.Text = drMemberReport[j]["REPORT_RESULT"].ToString().Trim(); WordDoc.Tables[TableCount].Cell(iNewRow, iCol).Range.Font.Bold = 0; WordDoc.Tables[TableCount].Cell(iNewRow, iCol).Range.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphLeft; WordDoc.Tables[TableCount].Cell(iNewRow, iCol).Range.Shading.BackgroundPatternColor = WdColor.wdColorWhite; WordDoc.Tables[TableCount].Cell(iNewRow, iCol).Range.Font.Size = 10; } } } WordDoc.Content.Tables[TableCount].Rows.Add(ref Nothing); WordDoc.Tables[TableCount].Cell(iNewRow + 4, 1).Merge(WordDoc.Tables[TableCount].Cell(iNewRow + 4, 3)); WordDoc.Tables[TableCount].Cell(iNewRow + 4, 1).Range.Text = dr[0]["SYS_CODE_NAME"].ToString(); WordDoc.Tables[TableCount].Cell(iNewRow + 4, 1).Range.Font.Color = WdColor.wdColorBlue; WordDoc.Tables[TableCount].Cell(iNewRow + 4, 1).Range.Font.Bold = 1; WordDoc.Tables[TableCount].Cell(iNewRow + 4, 1).Range.Font.Size = 12; WordDoc.Tables[TableCount].Cell(iNewRow + 4, 1).Borders.OutsideLineStyle = WdLineStyle.wdLineStyleNone; WordDoc.Tables[TableCount].Cell(iNewRow + 4, 1).Borders[WdBorderType.wdBorderTop].LineStyle = WdLineStyle.wdLineStyleSingle; if (dtMemberRecipe.Rows.Count > 0) { DataRow[] drMemberRecipe = dtMemberRecipe.Select("RECIPE_TYPE = ‘" + dr[0]["RECIPE_TYPE"].ToString().Trim() + "‘"); if (drMemberRecipe.Length > 0) { WordDoc.Content.Tables[TableCount].Rows.Add(ref Nothing); WordDoc.Tables[TableCount].Cell(iNewRow + 5, 1).Range.Text = drMemberRecipe[0]["RECIPE_CONTENT"].ToString(); WordDoc.Tables[TableCount].Cell(iNewRow + 5, 1).Range.Font.Color = WdColor.wdColorBlack; WordDoc.Tables[TableCount].Cell(iNewRow + 5, 1).Range.Font.Size = 10; WordDoc.Tables[TableCount].Cell(iNewRow + 5, 1).Range.Font.Bold = 0; WordDoc.Tables[TableCount].Cell(iNewRow + 5, 1).Borders[WdBorderType.wdBorderTop].LineStyle = WdLineStyle.wdLineStyleNone; WordDoc.Content.Tables[TableCount].Rows.Add(ref Nothing); WordDoc.Tables[TableCount].Cell(iNewRow + 6, 1).Range.Text = drMemberRecipe[0]["RECIPE_NAME"].ToString(); WordDoc.Tables[TableCount].Cell(iNewRow + 6, 1).Range.Font.Bold = 1; WordDoc.Tables[TableCount].Cell(iNewRow + 6, 1).Range.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphRight; WordDoc.Tables[TableCount].Cell(iNewRow + 6, 1).Range.Font.Color = WdColor.wdColorBlack; } } else { WordDoc.Tables[TableCount].Cell(iNewRow + 4, 1).Borders[WdBorderType.wdBorderTop].LineStyle = WdLineStyle.wdLineStyleNone; } } } TableCount++; } } #region 保存Word SaveFileDialog sfd = new SaveFileDialog(); string strFileName = strMemberNo + "_" + DateTime.Now.ToString("yyyyMMddHHmmss"); sfd.FileName = strFileName + ".doc"; object oMissing = System.Reflection.Missing.Value; object ofilename = sfd.FileName; WordApp.Visible = true; #endregion WordApp.DisplayAlerts = WdAlertLevel.wdAlertsNone; WordDoc.Saved = true; } } catch (Exception ex) { throw ex; } } #endregion #region 复制模板 //复制模板 private void CopyTable() { try { WordDoc.Tables[2].Select(); WordApp.Selection.Copy(); object mymessing = System.Reflection.Missing.Value; object myunit = Microsoft.Office.Interop.Word.WdUnits.wdStory; WordApp.Selection.EndKey(ref myunit, ref mymessing); object count = 999999; object oMissing = System.Reflection.Missing.Value; object WdLine = Microsoft.Office.Interop.Word.WdUnits.wdLine;//换一行; WordApp.Selection.MoveDown(ref WdLine, ref count, ref oMissing);//移动焦点 WordApp.Selection.TypeParagraph();//插入段落 WordApp.Selection.Paste(); } catch (Exception ex) { throw ex; } } #endregion } }
插入书签,合并拆分Word 表格,插入图片,插入PDF,转换PDF
标签:using document styles except sys names his led div
原文地址:https://www.cnblogs.com/6B23/p/12205103.html