当前位置: 首页 > news >正文

帝国做的网站打开速度wordpress插件聊天室小人

帝国做的网站打开速度,wordpress插件聊天室小人,哪里有最新的网站源码,软件开发专业词汇目录 应用需求 设计 范例运行环境 配置Office DCOM 实现代码 组件库引入 ​核心代码 调用示例 小结 应用需求 在我的文章《C# 读取多条数据记录导出到 Word 标签模板》里,讲述读取多条数据记录结合 WORD 标签模板输出文件的功能,原有输出图片的…

目录

应用需求

设计

范例运行环境

配置Office DCOM

实现代码

组件库引入

​核心代码

调用示例

小结


应用需求

在我的文章《C# 读取多条数据记录导出到 Word 标签模板》里,讲述读取多条数据记录结合 WORD 标签模板输出文件的功能,原有输出图片的约定是在 WORD 模板文件中借助书签设置进行输出,如下图:

该书签名称代表了一条指令,格式为(输出关键字_图片宽度_图片高度)。如图中书签名称设置,当系统遇到 ds_qz 关键字时,输出按后继设置进行,图片宽度为100、图片高度为 50。

现有一模板需求如下图:

我们需要在考官评语和考官本人签字位置输出手写图片,原有的书签模式输出会遇到一些问题:

(1)只能为嵌入式,位置输出无法设置,无法进一步调整到较优呈现位置。

(2)只能插入式输出,无法实现嵌入式如文字浮动、环绕效果。

(3)需要在无关位置插入书签,否则会在输出关键字时被替换掉,而无法识别配置。

(4)书签的名称不能输入一些特定字符,如%,减号等,给配置带来一些麻烦。

(5)如果在文档里真需要设置书签,容易造成混乱。

设计

设计提供一个 ArrayList 类型参数取代书签模式的设计,其格式为 (输出关键字_图片宽度_图片高度_图片 Left 相对值_图片 Top 相对值 )。如添加 ds_qz_100_50_500_-20 字符串,当系统遇到 ds_qz 关键字时,输出按后继设置进行,图片宽度为100、图片高度为 50、图片 Left 为500、图片 Top 为 -20。后四个参数如果设置null则表示忽略,ds_qz_null_null_500_-20 ,则表示忽略宽度和高度设置,即表示原始大小输出。

定位到的图片输出,采取浮动于文字下方的处理。

范例运行环境

操作系统: Windows Server 2019 DataCenter

操作系统上安装 Office Word 2016

数据库:Microsoft SQL Server 2016

.net版本: .netFramework4.7.2 或以上

开发工具:VS2019  C#

配置Office DCOM

配置方法可参照我的文章《C# 读取Word表格到DataSet》进行处理和配置。

实现代码

组件库引入

核心代码

public string DataTableToWord(string _filename,string _repeatKey,object _dataset,ArrayList DataSetPictureConfig),该方法提供4个参数,WORD模板文件名、自定义关键字、System.Data.DataSet,配置图片用的 ArrayList 列表指令。

public void DataTableToWord(string _filename,string _repeatKey,object _dataset,ArrayList DataSetPictureConfig){if (DataSetPictureConfig == null) { DataSetPictureConfig = new ArrayList(); }Object Nothing = System.Reflection.Missing.Value;object filename = _filename;//创建一个名为WordApp的组件对象Word.Application WordApp = new Word.Application();//创建一个名为WordDoc的文档对象WordApp.DisplayAlerts = Word.WdAlertLevel.wdAlertsNone;Word.Document WordDoc = WordApp.Documents.Open(ref filename, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing);WordDoc.SpellingChecked = false;//关闭拼写检查WordDoc.ShowSpellingErrors = false;//关闭显示拼写错误提示框WordApp.Selection.WholeStory();WordApp.Selection.Cut();DataSet ds=(DataSet)_dataset;System.Data.DataTable  dt=ds.Tables[0];for(int i=0;i<dt.Rows.Count;i++){WordApp.Selection.Paste();for(int j=0;j<dt.Columns.Count;j++){string _repKey=_repeatKey+dt.Columns[j].ColumnName.ToString();string _repValue=string.Format("{0}",dt.Rows[i][j].ToString());bool isPhoto=false;if(dt.Columns[j].DataType==typeof(System.Byte[])){isPhoto=true;_repValue="";}WordApp.Options.ReplaceSelection=true;Word.Find fnd = WordApp.Selection.Find;fnd.ClearFormatting();Object findText = _repKey;Object matchCase = false;Object matchWholeWord = Type.Missing;Object matchWildcards = false;Object matchSoundsLike = false;Object matchAllWordForms = false;Object forward = true;Object wrap =Word.WdFindWrap.wdFindContinue;Object format = false;Object replaceWith ="";Object replace =Type.Missing;;Object matchKashida = Type.Missing;Object matchDiacritics = Type.Missing;Object matchAlefHamza = Type.Missing;Object matchControl = Type.Missing;while(fnd.Execute(ref findText, ref matchCase, ref matchWholeWord,ref matchWildcards, ref matchSoundsLike, ref matchAllWordForms, ref forward, ref wrap, ref format, ref replaceWith,ref replace, ref matchKashida, ref matchDiacritics,ref matchAlefHamza, ref matchControl)){string r_f=WordApp.Selection.Font.Name.ToString();WordApp.Selection.Range.Text=_repValue;if(isPhoto==true){string _jpgfile=_path+System.Guid.NewGuid()+".jpg";if (dt.Rows[i][j] == System.DBNull.Value){continue;}byte[] filedata = (byte[])dt.Rows[i][j];System.IO.MemoryStream ms = new MemoryStream(filedata);System.Drawing.Image img1 = System.Drawing.Image.FromStream(ms);img1.Save(@_jpgfile);ms.Close();Word.InlineShape pic= WordApp.Selection.InlineShapes.AddPicture(@_jpgfile,false,true);foreach (string bm in  DataSetPictureConfig){string _findkey=_repKey+"_";int _f1 =bm.IndexOf(_findkey);if(_f1==0 && bm.Length>(_findkey.Length)){string[] _paras=bm.Substring(_findkey.Length,bm.Length-_findkey.Length).Split('_');if(_paras.GetLength(0)>1){if (_paras[0] != "null"){int def_width = int.Parse(_paras[0]);pic.Width = def_width;}if (_paras[1] != "null"){int def_height = int.Parse(_paras[1]);pic.Height = def_height;}}}}Word.Shape pic2 = pic.ConvertToShape();pic2.WrapFormat.Type = Word.WdWrapType.wdWrapThrough;pic2.WrapFormat.Type = Word.WdWrapType.wdWrapBehind;pic2.Left = 0;pic2.Top = 0;foreach (string bm in DataSetPictureConfig){string _findkey = _repKey + "_";int _f1 = bm.IndexOf(_findkey);if (_f1 == 0 && bm.Length > (_findkey.Length)){string[] _paras = bm.Substring(_findkey.Length, bm.Length - _findkey.Length).Split('_');if (_paras.GetLength(0) > 3){if (_paras[2] != "null")pic2.Left = float.Parse(_paras[2]);if (_paras[3] != "null")pic2.Top =float.Parse(_paras[3]);}}}File.Delete(@_jpgfile);}}}object dummy = System.Reflection.Missing.Value;object what = Word.WdGoToItem.wdGoToLine;object which = Word.WdGoToDirection.wdGoToLast;object count = System.Reflection.Missing.Value;
//					WordApp.Selection.GoTo(ref oGoToItem, ref oGoToLast, ref Nothing, ref Nothing);WordApp.Selection.GoTo(ref what, ref which, ref count, ref dummy);//default 表示每行记录之间插入分页符,最后一行时不再插入分页符,以免造成多余一空白页if(i!=dt.Rows.Count-1){object ib = Word.WdBreakType.wdPageBreak; WordApp.Selection.InsertBreak(ref ib);}}}WordDoc.Save();WordDoc.Close(ref Nothing, ref Nothing, ref Nothing);//关闭WordApp组件对象WordApp.Quit(ref Nothing, ref Nothing, ref Nothing);}

调用示例

示例代码如下:

DataSet rv = GetDataSet("select * from tabble");ArrayList picconfig = new ArrayList();   //可配置每个图片字段的大小及位置
picconfig.Add("ds_kg_sign_100_50_500_-20");   //格式为: key_width_height_left_top
string ModuleFile = "d:\\bfile\\word\\面试评分表.docx";  //假设的模板文件
string _lastfile = DataTableToWord(ModuleFile,"ds_",ds,picconfig);MessageBox.Show(string.Format("已成功导出文件:{0}", _lastfile));

运行结果预览如下图:

 

小结

核心代码中需要将 Word.InlineShape 转换为 Word.Shape 后,可以进行环绕文字的操作,如下:

Word.Shape pic2 = pic.ConvertToShape();
pic2.WrapFormat.Type = Word.WdWrapType.wdWrapThrough;
pic2.WrapFormat.Type = Word.WdWrapType.wdWrapBehind;
pic2.Left = 0;
pic2.Top = 0;

使用 ConvertToShape() 方法转换为 pic2 , pic2.WrapFormat.Type = Word.WdWrapType.wdWrapBehind;  可以浮动于文字下方,然后初始图片的 Left 和 Top ,否则有可能无法正常显示位置。

我们可以根据自己的实际情况设置环绕格式,可参阅读如下地址:

https://learn.microsoft.com/zh-cn/office/vba/api/word.wdwraptypemerged

这些代码我们提供了一些操作WORD相关的关键方法,这里仅作参考,欢迎大家评论指教!

http://www.yayakq.cn/news/667296/

相关文章:

  • 企业邮箱入口登录大连seo关键词排名
  • 如何查看网站的死链接做电影网站用什么服务器
  • 选择网站建设公司好住房和城乡建设部网站招聘
  • 国外优秀电商设计网站潮州网站搭建找谁
  • 新网站百度收录深圳网站公司建设
  • 做网站移交资料怎么做自己网站产品seo
  • 东莞网站建设推广服务建设工程教育网app下载
  • 文本编辑器做网站体育直播网站源码
  • 个人导航网站如何赚钱凡科网站的排名做不上去
  • 网站开发与设计实训企业网站视觉设计
  • 外贸商城网站开发书discuz修改网站标题
  • 网站停留时间中山网站制作建设
  • 电影网站开发源代码网络营销概念是谁提出的
  • 做微信公众号的网站有哪些企业管理培训课程有哪些内容
  • 免费flash网站源码网站设计策划方案
  • 档案网站建设与档案信息化个人建设网站难吗
  • 自适应网站做多大尺寸源代码管理网站
  • 响应式网站建设好么wordpress图书主题
  • 部门子网站建设领导小组有没有免费查公司的软件
  • 门户网站建设jz190免费下载应用软件
  • 网站建设 思路广西南宁网站建设公司
  • 网站怎么才能被百度收录腾讯科技微信小程序
  • 上海做衣服版的网站网站的建设费用预算策划书
  • 网站空间排行榜微信群推广
  • 潍坊网站建设科技有限公司做内贸哪个网站找客户
  • 网站字体标准网站建设前端岗位职责
  • 网站权重一般有几个等级菲律宾做网站
  • 资源网站推荐天津建设工程信息网招聘
  • 建设银行咸阳交费网站网站开站
  • 网站微信建设经验OA网站建设分析