/// <summary>
/// 生产报表
/// </summary>
/// <param name="strTemplate"></param>
public void CreateWordFile(DataRow item)
{
try
{
MultiFormatWriter multiWriter = new MultiFormatWriter();
QrCodeEncodingOptions options = new QrCodeEncodingOptions();
BarcodeWriter bw = new BarcodeWriter();
bw.Format = BarcodeFormat.CODE_128;
bw.Options = options; object Nothing = System.Reflection.Missing.Value;
//定义该插入图片是否为外部链接
object linkToFile = true;
//定义插入图片是否随word文档一起保存
object saveWithDocument = true; WordApp = new Word.Application();
WordDoc = new Word.Document();
WordApp.Visible = false;
WordApp.PrintPreview = false; string filename = System.Windows.Forms.Application.StartupPath + \\******\\Word.dot;
try
{
WordDoc = WordApp.Documents.Add(filename);
WordDoc = WordApp.ActiveDocument;
}
catch (Exception ex)
{
throw (ex);
} WordDoc.Tables[].Cell(, ).Range.Text = HospitalName;
int x = ;
//Table2 x = 1
WordDoc.Tables[x].Cell(, ).Range.Text = item["CORP_DEPT_NAME"].ToString().Trim();
WordDoc.Tables[x].Cell(, ).Range.Text = item["MEMO"].ToString().Trim();
options.Width = ;
options.Height = ;
options.Margin = ;
options.PureBarcode = false;
Image BarCode = bw.Write(item["REGISTER_NO"].ToString().Trim());
Clipboard.SetDataObject(BarCode);
WordDoc.Tables[x].Cell(, ).Range.Paste();
BarCode.Dispose();
WordDoc.Tables[x].Cell(, ).Range.Text = item["PATIENT_NAME"].ToString().Trim();
WordDoc.Tables[x].Cell(, ).Range.Text = item["BIRTHDAY"].ToString().Trim();
WordDoc.Tables[x].Cell(, ).Range.Text = item["CHART_NO"].ToString().Trim(); if (item["CORPORATION_NAME"].ToString().Length > )
{
WordDoc.Tables[x].Cell(, ).Range.Text = item["CORPORATION_NAME"].ToString().Trim().Substring(, );
}
else
{
WordDoc.Tables[x].Cell(, ).Range.Text = item["CORPORATION_NAME"].ToString().Trim();
}
WordDoc.Tables[x].Cell(, ).Range.Text = item["BOOKING_DATE"].ToString().Trim(); if (item["ADDRESS"].ToString().Length > )
{
WordDoc.Tables[x].Cell(, ).Range.Text = item["ADDRESS"].ToString().Trim().Substring(, );
}
else
{
WordDoc.Tables[x].Cell(, ).Range.Text = item["ADDRESS"].ToString().Trim();
}
WordDoc.Tables[x].Cell(, ).Range.Text = item["PHONE_NUMBER"].ToString().Trim(); if (item["PHOTO"].ToString() != "")
{
SaveFileDialog sflg = new SaveFileDialog();
MemoryStream ms = new MemoryStream((byte[])item["PHOTO"]);//把照片读到MemoryStream里
Image imageBlob = Image.FromStream(ms, true);//用流创建Image
imageBlob.Save(System.Windows.Forms.Application.StartupPath + "\\" + item["REGISTER_NO"].ToString() + ".jpg");
////插入图片
WordDoc.Tables[x].Cell(, ).Range.Text = "";
WordDoc.Tables[x].Cell(, ).Select();
object range = WordApp.Selection.Range;
Word.InlineShape shape = WordApp.ActiveDocument.InlineShapes.AddPicture(System.Windows.Forms.Application.StartupPath + "\\" + item["REGISTER_NO"].ToString() + ".jpg", ref linkToFile, ref saveWithDocument, ref range); shape.Width = ;//图片宽度
shape.Height = ;//图片高度
System.IO.FileInfo file = new System.IO.FileInfo(System.Windows.Forms.Application.StartupPath + "\\" + item["REGISTER_NO"].ToString() + ".jpg");
if (file.Exists)
{
file.Delete();
}
imageBlob.Dispose();
}
DataTable dtHMS_REGISTER = hmsService.QueryHmsRequestDatafor0131(item["REGISTER_NO"].ToString().Trim(), strHavePrint);
dtHMS_REGISTER.DefaultView.Sort = "STATION_ID"; System.Data.DataTable dttemp = new System.Data.DataTable();
DataView tempDv = dtHMS_REGISTER.DefaultView;
dtHMS_REGISTER = tempDv.ToTable(); dttemp = tempDv.ToTable(true, new[] { "STATION_NAME", "FLOW_SHEET_MEMO" }); bool blMerge = false;
Table table = null;
int iRow = ;
WordDoc.Content.Tables[x].Rows.Add(ref Nothing);
WordDoc.Tables[x].Cell(, ).Range.Text = "(1)登记报到";
for (int i = ; i < dttemp.Rows.Count; i++, iRow++)
{
string strMemo = "";
DataRow[] dr = dtHMS_REGISTER.Select("STATION_NAME = '" + dttemp.Rows[i]["STATION_NAME"].ToString().Trim() + "'"); if (dr.Length > )
{
//创建新行
if (i > )
{
WordDoc.Content.Tables[x].Rows.Add(ref Nothing);
//拆分以合并行
if (blMerge)
{
WordDoc.Content.Tables[x].Cell(iRow, ).Merge(WordDoc.Tables[x].Cell(iRow, ));
WordDoc.Content.Tables[x].Cell(iRow, ).Split(, );
WordDoc.Content.Tables[x].Cell(iRow, ).Width = ;
WordDoc.Content.Tables[x].Cell(iRow, ).Width = 70.5f;
WordDoc.Content.Tables[x].Cell(iRow, ).Width = ;
blMerge = false;
}
}
WordDoc.Tables[x].Cell(iRow, ).Range.Text = dr[]["STATION_NAME"].ToString().Trim();
int iNewRow = ;
int iCol = ;
int m = ; string strModType = "";
string strCollingNo = "";
for (int j = ; j < dr.Length; j++)
{
#region 检查站类别(STATION_TYPE_CODE)=’1’(表示输入)
if (dr[j]["STATION_TYPE_CODE"].ToString().Trim() == "")
{
#region 体检项目基本档(HMS_EXAM_ITEM)中指引单打印标志(HMS_EXAM_ITEM.FLOW_SHEET_FLAG)=’Y’时
if (dr[j]["FLOW_SHEET_FLAG"].ToString().Trim() == "Y")
{
//FLOW_SHEET_NAME
if (j == )
{
WordDoc.Tables[x].Cell(iRow, ).Select();
table = CreatTable();
}
else
{
if (j % == )
{
table.Rows.Add(ref Nothing);
iNewRow++;
}
}
iCol = j % + ; table.Cell(iNewRow, iCol).Range.Text = "□ " + dr[j]["FLOW_SHEET_NAME"].ToString().Trim();
table.Cell(iNewRow, iCol).Range.Font.Name = "微软雅黑";
table.Cell(iNewRow, iCol).Range.Font.Size = 10.5F;
}
else
{
continue;
}
if (dr[j]["EXAM_MEMO"].ToString().Trim() != "" && strMemo.IndexOf(dr[j]["EXAM_MEMO"].ToString().Trim() + ",") < )
{
strMemo += dr[j]["EXAM_MEMO"].ToString().Trim() + ",";
}
#endregion
}
else if (dr[j]["STATION_TYPE_CODE"].ToString().Trim() == "" || (dr[j]["STATION_TYPE_CODE"].ToString().Trim() == ""))
{
#region 检核报告主档(HMS_REPORT)中申请单号(OBSERVATION_NO)有值时
if (dr[j]["OBSERVATION_NO"].ToString().Trim() != "" && dr[j]["FLOW_FLAG"].ToString().Trim() == "Y")
{
if (dr[j]["FLOW_TYPE_CODE"].ToString().Trim() == "")
{
if (j == )
{
WordDoc.Tables[x].Cell(iRow, ).Select();
table = CreatTable();
}
else
{
if (j % == )
{
table.Rows.Add(ref Nothing);
iNewRow++;
}
}
iCol = j % + ; table.Cell(iNewRow, iCol).Range.Text = "□ " + dr[j]["PRINT_TAG_NAME"].ToString().Trim();
table.Cell(iNewRow, iCol).Range.Font.Name = "微软雅黑";
table.Cell(iNewRow, iCol).Range.Font.Size = 10.5F;
}
else if (dr[j]["FLOW_TYPE_CODE"].ToString().Trim() == "")
{
if (j == )
{
WordDoc.Tables[x].Cell(iRow, ).Select();
table = CreatTable();
m = j;
}
else
{
m = j * ;
table.Rows.Add(ref Nothing);
} if (Convert.ToInt32("" + dr[j]["CALLING_NO"].ToString().Trim()) > )
{
if (dr[j]["STATION_TYPE_CODE"].ToString().Trim() == "" || dr[j]["STATION_TYPE_CODE"].ToString().Trim() == "")
{
table.Cell(m + , ).Range.Text = "□ " + dr[j]["PRINT_TAG_NAME"].ToString().Trim();
if (strModType != dr[j]["MODTYPE"].ToString().Trim())
{
strModType = dr[j]["MODTYPE"].ToString().Trim();
if (strCollingNo.IndexOf(" 排号 " + dr[j]["CALLING_NO"].ToString()) < )
{
strCollingNo = strCollingNo + "\r\n" + dr[j]["MODTYPE"].ToString().Trim() + " 排号 " + dr[j]["CALLING_NO"].ToString();
}
}
}
else
{
table.Cell(m + , ).Range.Text = "□ " + dr[j]["PRINT_TAG_NAME"].ToString().Trim() + " 排号 " + dr[j]["CALLING_NO"].ToString();
}
table.Cell(m + , ).Range.Font.Name = "微软雅黑";
table.Cell(m + , ).Range.Font.Size = 10.5F;
}
else
{
table.Cell(m + , ).Range.Text = "□ " + dr[j]["PRINT_TAG_NAME"].ToString().Trim();
table.Cell(m + , ).Range.Font.Name = "微软雅黑";
table.Cell(m + , ).Range.Font.Size = 10.5F;
}
options.Width = ;
options.Height = ;
options.Margin = ;
options.PureBarcode = true;
Image BarCodeNew = bw.Write(dr[j]["OBSERVATION_NO"].ToString());
Clipboard.SetDataObject(BarCodeNew);
table.Cell(m + , ).Range.Paste();
table.Cell(m + , ).Range.Text += dr[j]["OBSERVATION_NO"].ToString();
//table.Rows.Add(ref Nothing);
//table.Cell(m + 2, 2).Range.Text = dr[j]["OBSERVATION_NO"].ToString();
BarCodeNew.Dispose();
}
if (strMemo != "" && dr[j]["SHEET_REMARKS"].ToString().Trim() != "" && strMemo.IndexOf(dr[j]["SHEET_REMARKS"].ToString().Trim() + ",") < )
{
strMemo += dr[j]["SHEET_REMARKS"].ToString().Trim() + ",";
}
}
else
{
continue;
}
#endregion
}
#endregion
}
WordDoc.Tables[x].Cell(iRow, ).Range.Text = dr[]["STATION_NAME"].ToString().Trim() + strCollingNo;
}
if (dttemp.Rows[i]["FLOW_SHEET_MEMO"].ToString().Trim() != "" || strMemo != "")
{
WordDoc.Content.Tables[x].Rows.Add(ref Nothing);
iRow++;
WordDoc.Tables[x].Cell(iRow, ).Merge(WordDoc.Tables[x].Cell(iRow, ));
WordDoc.Tables[x].Cell(iRow, ).Width = + 70.5f;
WordDoc.Tables[x].Cell(iRow, ).Width = ;
WordDoc.Tables[x].Cell(iRow, ).Range.Text = (dttemp.Rows[i]["FLOW_SHEET_MEMO"].ToString().Length > ? dttemp.Rows[i]["FLOW_SHEET_MEMO"].ToString() + "," : "") + strMemo;
WordDoc.Tables[x].Cell(iRow, ).Select();
WordDoc.Paragraphs.Last.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphRight; blMerge = true;
}
}
WordDoc.Content.Tables[x].Rows.Add(ref Nothing);
WordDoc.Tables[x].Cell(iRow + , ).Range.Text = "(1)登记报到 指引单缴回";
if (dtMome.Rows.Count > )
{
WordDoc.Tables[x].Cell(, ).Range.Text = dtMome.Rows[]["MEMO_HEAD"].ToString();
} if (WordDoc.Bookmarks.Exists("MEMO_TAIL"))
{
WordDoc.Bookmarks.get_Item("MEMO_TAIL").Range.Text = dtMome.Rows[]["MEMO_TAIL"].ToString();
}
if (strPrintFlag != "Y")
{
SaveFileDialog sfd = new SaveFileDialog();
string strFileName = DateTime.Now.ToString("yyyyMMddHHmmss");
sfd.FileName = strFileName + ".doc";
object oMissing = System.Reflection.Missing.Value;
object ofilename = sfd.FileName;
WordDoc.SaveAs(ref ofilename, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing);
WordApp.Visible = false;
WordDoc.Close();
WordApp.Quit();
}
else
{
string defaultPrinter = WordApp.ActivePrinter;
WordApp.PrintPreview = false;
WordApp.ActivePrinter = strWordPrint;
WordApp.PrintOut();
object oMissing = System.Reflection.Missing.Value; WordApp.DisplayAlerts = WdAlertLevel.wdAlertsNone;
WordDoc.Saved = true;
WordApp.ActivePrinter = defaultPrinter;
WordApp.Quit();
}
BarCode.Dispose();
}
catch (Exception ex)
{
WordApp.Quit();
throw ex;
}
finally
{
foreach (System.Diagnostics.Process p in System.Diagnostics.Process.GetProcessesByName("WINWORD"))
{
p.Kill();
}
GC.Collect();
}
} private Table CreatTable(int iColumn)
{
object Nothing = System.Reflection.Missing.Value;
Range rng = WordApp.Selection.Range;
rng.ParagraphFormat.LineSpacing = 15F;
Microsoft.Office.Interop.Word.Table table = WordDoc.Tables.Add(rng, , iColumn, ref Nothing, ref Nothing);
if (iColumn == )
{
table.Columns[].Width = ;
table.Columns[].Width = ;
}
table.Rows.Alignment = WdRowAlignment.wdAlignRowLeft;
table.Range.Font.Name = "微软雅黑";
table.Range.Font.Size = 10.5F;
return table;
}

手动穿件Word.dot 模板文档格式如下,插入相应标签

Word报表生成的更多相关文章

  1. C# 生成word 文档 代码 外加 IIS报错解决方案

    using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.We ...

  2. iReport报表生成html,pdf,xls,word工具类

    package com.report; import java.io.ByteArrayOutputStream;import java.io.File;import java.io.InputStr ...

  3. C#服务器端生成报告文档:使用帆软报表生成Word、Pdf报告

    一.帆软报表简介 报表工具中,帆软报表相比Crystal Report(水晶报表).SQL Server Report Service(SSRS)等报表工具来说算是佼佼者,此外帆软报表在统计图表.数据 ...

  4. Delphi中编辑word

      其他(28)   //启动Word   try     wordapplication1.connect;   except     messagedlg('word may not be ins ...

  5. Delphi读取Word

    Delphi读取Word现在关于往Word中写入数据的方法比较多,现在专门开个贴子,希望大家把自己读取Word内容的心得体会说一下,包括读取word文档中,有几个段落,如何读取第几个段落,读取有拼音的 ...

  6. java操作office和pdf文件java读取word,excel和pdf文档内容

    在平常应用程序中,对office和pdf文档进行读取数据是比较常见的功能,尤其在很多web应用程序中.所以今天我们就简单来看一下Java对word.excel.pdf文件的读取.本篇博客只是讲解简单应 ...

  7. spring boot freemarker 导出word 带echarts图形报表

    创建word文件内容如下 将word导出为xml格式 将文件后缀名改为 .ftl 在springboot项目中添加freemarker依赖 <!-- 导出word文档--> <dep ...

  8. Word/Excel 在线预览

    前言 近日项目中做到一个功能,需要上传附件后能够在线预览.之前也没做过这类似的,于是乎就查找了相关资料,.net实现Office文件预览大概有这几种方式: ① 使用Microsoft的Office组件 ...

  9. C#中5步完成word文档打印的方法

    在日常工作中,我们可能常常需要打印各种文件资料,比如word文档.对于编程员,应用程序中文档的打印是一项非常重要的功能,也一直是一个非常复杂的工作.特别是提到Web打印,这的确会很棘手.一般如果要想选 ...

随机推荐

  1. bat脚本 定时删除备份的文件

    删除 D:\yswbak 目录下rar类型 6天前的 文件 @echo off forfiles /p D:\yswbak /m *.rar /d - /c "cmd /c del @pat ...

  2. vue.extend 拓展

    https://www.w3cplus.com/vue/vue-extend.html https://jspang.com/post/vue2-2.html https://blog.csdn.ne ...

  3. Linux运维---磁盘存储-2. RAID

    随着单块磁盘在数据安全.性能.容量上呈现出的局限,磁盘阵列(Redundant Arrays of Inexpensive/Independent Disks,RAID)出现了,RAID把多块独立的磁 ...

  4. 【渗透实战】web渗透实战,手动拿学校站点 得到上万人的信息(漏洞已提交)

    ------------恢复内容开始------------ ’‘’版权tanee转发交流学校请备注漏洞已经提交学校管理员关键过程的截图和脚本代码已经略去.希望大家学习技术和思路就好,切勿进行违法犯罪 ...

  5. GNU make doc - 3.8

    Note that the directory prefix (D), as described in Implicit Rule Search Algorithm, is appended (aft ...

  6. C#模拟POST上传文件帮助类(支持https、http)

    public static int PostFile(string getUrl, CookieContainer cookieContainer, HttpHeader header, string ...

  7. ELK学习002:Elasticsearch 7.x 的安装及配置

    Elasticsearch 的安装与启动 1.1 下载 Elasticsearch 7.6.0 下载地址:https://www.elastic.co/cn/downloads/elasticsear ...

  8. day19 几个模块的学习

    # 模块本质上就是一个 .py 文件# 数据类型# 列表.元组# 字典# 集合.frozenset# 字符串# 堆栈:特点:先进后出# 队列:先进先出 FIFO # from collections ...

  9. 小白的linux学习笔记10:安装nginx和第一个网页

    sudo yum install nginx sudo systemctl status nginx sudo systemctl start nginx 检查端口:netstat -tlpn sud ...

  10. 【算法】——递归:小白正在上楼梯,楼梯有n阶台阶,小白一次可以上1阶,2阶或者3阶,实现一个方法,计算小白有多少种走完楼梯的方式。

    分析:从最后一步分析,能有的情况有三种情况构成,写出如图所示的方程 //和斐波拉契相似 int void f(int n) { //考虑出口 ) ;//正常思路是返回0 ) ;//通过自己想可以得出只 ...