/// <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. UI自动化框架搭建

    1.目录结构 大概分为以下几个文件 common :主要是用来放一些封装的公共函数 outputs :主要是输出一些文件,失败截图.用例执行完的测试报告 pagelocate :主要是元素的定位 pa ...

  2. mysql中大数据表alter增加字段报错:"1034 Incorrect key file for table 'table_name'; try to repair it"

    mysql中大数据表alter增加字段报错:"1034 Incorrect key file for table 'table_name'; try to repair it" 现 ...

  3. SpringCloud学习之—Eureka集群搭建

    Eureka集群的搭建 上次说过了在SpringCloud应用中使用Eureka注册中心,用来对服务提供者进行服务注册与发现,但同时,它也是一个"微服务",单个应用使用空间有限,因 ...

  4. [PHP] 使用PHP在mongodb中进行count查询

    在php7的mongodb扩展中,当要查询某个集合在某个条件下的数据个数时,可以使用下面的方式来获取. 比原生的命令要复杂许多 比旧版mongo扩展也复杂许多 需要使用到MongoDB\Driver\ ...

  5. java 入门如何设计类

    2019/12/24   |    在校大二上学期    |    太原科技大学 初学java后,我们会发现java难点不在于Java语法难学,而是把我们挂在了如何设计类的“吊绳”上了.这恰恰也是小白 ...

  6. SQLServer之查询当前服务器下所有目录视图表

    SQL脚本 /*************1:删除临时表*************/ if exists(select * from tempdb..sysobjects where id=object ...

  7. mybatis 自学笔记

    MyBatis 是一款优秀的持久层框架,它支持定制化 SQL.存储过程以及高级映射.本页作为自学整理资料,信息来源网络,侵权速联,但大部份经过自己测试.使用说明:本人测试用编辑软件eclipse_st ...

  8. The server cannot be started because one or more of the ports are invalid. Open the server editor and correct the invalid ports.

    在eclipse里运行jsp文件最初迟迟没有反应,重启报了这个错误,tomcat的端口设置有问题.需要打开服务器设置一下端口号. 点击Servers,如果没有这一项,按照Window-Show Vie ...

  9. 记一个开发是遇到的坑之Oralce 字符串排序

    简单描述一下情况,就是存储过程中用一个字符串类型的字段作为患者就诊的排序号,结果莫名发现叫完1号后叫了11.12等患者.用户的反馈不一定准确,自己加了日志的,赶紧拷贝日志来观察一下.结果发现实际情况就 ...

  10. (三)LoadRunner术语认识

    场景:主要表现为controller中设计与执行测试用例中的用户场景.主要工作有,在controller中选择虚拟用户脚本.设置虚拟用户数量.配置虚拟用户运行时的行为.选择负载发生器.设置执行时间等. ...