C# 替换Word文档中的书签内容【详细步骤】

C# 操作Word书签(二)——插入图片、表格到书签;读取、替换书签 概要 书签的设置可以帮助我们快速的定位某段文字,使用起来很方便,也很节省时间。在前一篇文章“C# 如何添加/删除Word书签”中介绍了插入、删除书签的方法,本篇文章将对C# 操作Word书签的功能做进一步介绍。示例内容将包含以下要点: 在现有书签位置插入图片 在现有书签位置插入表格 读取书签位置的文档内容 替换现有书签位置内容 使用工具 Spire.Doc... 阅读详情

Word书签不但可以帮助读者快速跳转到想要查看的位置,而且可以用做“占位符”,程序员获取“占位符”之后,就可以更新这些“占位符”,即替换书签内容。替换模板文档中的书签内容,可以帮助我们快速生成Word报表或文档。

本文总结了一个将常见的Word文档元素(文字、图片和表格)替换进书签的C#解决方案,具体步骤见下文。

使用工具:

  • Spire.Doc.dll 6.4.5
  •  Visual Studio 2013
步骤一 制作模板

1.  新建Word文档


图1 创建文档

2.  插入书签


图2 插入书签

3.  保存模板,命名为“bookmark_template.docx”


图3 保存模板文档

步骤二 在项目中添加引用

1.  右键点击“解决方案资源管理”中的“引用”,选择“添加引用”


图4 添加引用

2.  选择要引用的Spire.Doc.dll文件,添加至项目中



图5 引用Spire.Doc.dll

步骤三 编码

Spire.Doc提供了BookmarksNavigator类来获取和操作文档中的书签,但方法不是很直观。为了方便,我自己封装了Bookmark类,其中包括RepalceContent及其2个重载方法来分别应对插入文字、图片和表格三种情况。

  • public TextRange ReplaceContent(string bookmarkName, string text, bool saveFormatting)
  • public void ReplaceContent(string bookmarkName, string picPath, float widthScale, float heightScale, TextWrappingStyle wrapStyle, ShapeHorizontalAlignment horizontalAlignment)
  • public void ReplaceContent(string bookmarkName, Table table)

第一部分:Bookmark.cs编码

using Spire.Doc;
using Spire.Doc.Fields;
using System.Drawing;
using Spire.Doc.Interface;
using Spire.Doc.Documents;

namespace ReplaceBookmarkContent
{
    class Bookmark
    {
        private Document doc = null;
        public Bookmark(Document document)
        {
            doc = document;
        }

        /// <summary>
        /// 用文本替换指定书签的内容
        /// </summary>
        /// <param name="bookmarkName">书签名</param>
        /// <param name="text">文本</param>
        /// <param name="saveFormatting">删除原始书签内容时,是否保留格式</param>
        /// <returns>TextRange</returns>
        public TextRange ReplaceContent(string bookmarkName, string text, bool saveFormatting)
        {
            BookmarksNavigator navigator = new BookmarksNavigator(doc);
            navigator.MoveToBookmark(bookmarkName);//指向特定书签
            navigator.DeleteBookmarkContent(saveFormatting);//删除原有书签内容     
            Spire.Doc.Interface.ITextRange textRange = navigator.InsertText(text);//写入文本
            return textRange as TextRange;
        }

        /// <summary>
        /// 用图片替换指定书签的内容
        /// </summary>
        /// <param name="bookmarkName">书签名</param>
        /// <param name="picPath">图片路径</param>
        /// <param name="widthScale">宽度缩放比例,0以上正整数</param>
        /// <param name="heightScale">高度缩放比例,0以上正整数</param>
        /// <param name="wrapStyle">环绕方式</param>
        /// <param name="horizontalAlignment"></param>
        public void ReplaceContent(string bookmarkName, string picPath, float widthScale, float heightScale, TextWrappingStyle wrapStyle, ShapeHorizontalAlignment horizontalAlignment)
        {
            BookmarksNavigator navigator = new BookmarksNavigator(doc);
            navigator.MoveToBookmark(bookmarkName);
            navigator.DeleteBookmarkContent(false);
            IParagraphBase paragraphBase = navigator.InsertParagraphItem(ParagraphItemType.Picture);//插入类型为图片
            Image image = Image.FromFile(picPath);//加载图片
            DocPicture picture = paragraphBase.OwnerParagraph.AppendPicture(image);//插入图片
            picture.WidthScale = widthScale;
            picture.HeightScale = heightScale;
            picture.TextWrappingStyle = wrapStyle;
            picture.HorizontalAlignment = horizontalAlignment;
        }

        /// <summary>
        /// 用表格替换指定书签的内容
        /// </summary>
        /// <param name="bookmarkName">书签名</param>
        /// <param name="table">Table实例</param>
        public void ReplaceContent(string bookmarkName, Table table)
        {
            BookmarksNavigator navigator = new BookmarksNavigator(doc);
            navigator.MoveToBookmark(bookmarkName);
            TextBodyPart body = new TextBodyPart(doc);
            body.BodyItems.Add(table);
            navigator.ReplaceBookmarkContent(body);
        }

        /// <summary>
        /// 创建表格并写入数据,返回Table对象
        /// </summary>
        /// <param name="rowsNum">行数</param>
        /// <param name="columnsNum">列数</param>
        /// <param name="columnWidth">列宽</param>
        /// <param name="horizontalAlignment">水平对齐方式</param>
        /// <param name="datatable">DataTable实例</param>
        /// <returns></returns>
        public Table CreateTable(int rowsNum, int columnsNum, float columnWidth, RowAlignment horizontalAlignment, System.Data.DataTable datatable)
        {
            Table table = new Table(doc, true, 1f);//初始化Table对象
            table.ResetCells(rowsNum, columnsNum);//设置行数和列数
            //填充数据
            for (int i = 0; i < datatable.Rows.Count; i++)
            {
                for (int j = 0; j < datatable.Columns.Count; j++)
                {
                    table.Rows[i].Cells[j].AddParagraph().AppendText(datatable.Rows[i][j].ToString());
                }
            }
            //设置列宽
            for (int i = 0; i < rowsNum; i++)
            {
                for (int j = 0; j < columnsNum; j++)
                {
                    table.Rows[i].Cells[j].Width = columnWidth;
                }               
            }
            table.TableFormat.HorizontalAlignment = horizontalAlignment;//表格水平对齐方式
            return table;
        }
    }
}

第二步部分:生成文件的编码

//加载模板文档
Document doc = new Document();
doc.LoadFromFile(@"C:\Users\Administrator\Desktop\bookmark_template.docx");

//初始化Bookmark对象
Bookmark bookmark = new Bookmark(doc);

//用文本替换书签bookmark_text的内容
string text = "XXX科技股份有限公司成立于2010年12月,是一家致力于高新技术产品研发、生产、销售的高科技股份制企业,"
    + "公司坚持以技术创新为核心,以知识产权为基础,以人才战略为支撑,经过多年的砺练与发展,公司已逐步成以创新为引导的,"
    + "产品具有竞争力,人才素质优良的新兴科技企业。";
bookmark.ReplaceContent("bookmark_text", text, true);

//用图片替换书签bookmark_picture的内容
string picPath = @"C:\Users\Administrator\Desktop\company_logo.jpg";
bookmark.ReplaceContent("bookmark_picture", picPath, 80f, 80f, TextWrappingStyle.TopAndBottom, ShapeHorizontalAlignment.Center);

//创建模拟数据
DataTable dt = new DataTable();
dt.Columns.Add("employee_id", typeof(string));
dt.Columns.Add("name", typeof(string));
dt.Columns.Add("age", typeof(string));
dt.Columns.Add("sex", typeof(string));
dt.Columns.Add("title", typeof(string));
dt.Rows.Add(new string[] {"工号", "姓名", "年龄", "性别", "职位" });
dt.Rows.Add(new string[] {"1023","Nancy", "28", "女", "Java程序员" });
dt.Rows.Add(new string[] { "1024","James", "34", "男", ".NET程序员" });
dt.Rows.Add(new string[] { "1025","Kobe", "38", "男", "系统管理员" });

//创建表格,并填充数据
Table table = bookmark.CreateTable(dt.Rows.Count, dt.Columns.Count, 100f, RowAlignment.Left, dt);

//用表格替换书签bookmark_table的内容
bookmark.ReplaceContent("bookmark_table", table);

//生成Word文件
doc.SaveToFile("output.docx", FileFormat.Docx2013);

运行代码,得到下面的结果:


图6 生成的文件

注:

1. Spire.Doc本身也有Bookmark类,但仅用于添加书签到文档中,请注意本文中的Bookmark类是自定义的方便自己使用的方法的集合。

2.  Spire.Doc 6.4.5 为商业版,在不应用许可证的情况下,生成的文档会有水印信息。笔者写文章时已应用临时许可证(官方提供的用于测试软件的License)。

3.  笔者使用免费版的Spire.Doc测试过,以上效果基本都能实现,但图片的环绕方式只能设置为“InLine”,且水平位置为靠右,设置其他环绕方式时,图片位置会出错。这应该是免费版的Bug。

(原创内容,转载请注明出处)

利用.net替换Word的内容(从数据库中取数据来替换word里面的书签) 我在现在的项目中,用户需要打印办文单,一开始做的时候,就用是用表格,按照他们的格式划了一个,可是,打出来的东西总是和他们自己的不一样,(一句话,不好看),我也头疼一阶段没什么好的办法,后来想,干脆把他们word模板拿过来,自己来替换.刚开始的时候,不知道怎么做问了,google找了,但没有一样的满意的.后来还是在msdn上找了一点点,然后请教了同事.在总算搞定.效果还不错.整个过程是这样的:(本人 阅读详情

相关推荐

C#_Word_通过书签替换文字、图片等

通过Word书签替换文字,图片 /// <summary> /// /// </summary> /// <param name="filePath"></param> Word地址 /// <param name="oldStr"></pa...

qq_36267404的博客 2859

C#打开word进行操作,文字替换、书签处插入图片、读取文档中的表格、修改表格数据

C#打开word进行操作,文字替换、书签处插入图片、读取文档中的表格、修改表格数据 public class WordHelp { private string _JpgsPath = string.Format("{0}\\Jpgs\\", CommenPara.STR_TempPath); public void OpenWord(string templateFile, object saveFile, ReportInfo reprortInfo,

坐听风雨 1623

TOPCon vs PERC:2024年光伏电站投资,哪种技术更划算?

本文深入分析了2024年光伏电站投资中TOPCon与PERC技术的财务表现。通过对比初始系统成本、全生命周期发电量及环境适应性,指出当前TOPCon组件与PERC价差已显著缩小,其更高的转换效率和更低的衰减率能有效降低度电成本并提升项目内部收益率,为投资者提供更具长期价值的方案。

p5l2m9n4o6q的博客 273

Spire.Doc在标签位置替换成图片,并设置居中样式

Document doc = new Document(); Paragraph paragraph = doc.createParagraph(); DocPicture picture = paragraph.appendPicture(imagePath);//imagePath图片路径 picture.setWidth(width); picture.setHeight(height); picture...

weixin_43823942的博客 3088

Mac 不小心断开移动硬盘导致磁盘无法读取和加载(顺利解决!)

Mac移动硬盘不正确断开连接导致无法读取加载的解决方法,亲测有效

Robin_Pi的博客 1万+

单细胞轨迹分析实战:基于Monocle和CytoTRACE的细胞分化潜能与状态解析

本文提供了基于Monocle和CytoTRACE的单细胞轨迹分析实战指南。通过乳腺癌数据集,详细演示了从数据准备、伪时序分析、细胞分化潜能评估到分支点功能挖掘的全流程。结合两种工具的优势,能有效解析细胞状态动态演变,为发育和疾病研究提供关键见解。

weixin_29070861的博客 487

c# 在 word指定位置插入文字和图片(替换 书签)

c# word 插入文字和图片(替换 书签)

chen1231985111的博客 2809

JMeter脚本录制-快速上手篇

有的项目应用场景下,压测时,需要考虑带宽因素,压测不只是压测接口,静态资源也要一起压测。一般来说,静态资源比较多,如果一个个手工去写请求,是比较繁琐的,此时,可以使用Jmeter的脚本录制功能。 步骤1,创建脚本录制模版。 JMeter菜单:文件>模版,下拉选择到Recording,点击“Create”按钮; 填写录制参数: hostToRecord:填写要录制的主机域名,例如,我们这里填入:www.baidu.com schemeToRecord:填写要录制的模式,例如,htt...

软件测试大叔 5735

# 段落 读取word_C# 操作Word书签(二)——读取、替换Word书签

在上一篇文章中介绍了关于C#如何插入Word书签、插入图片或表格到word、删除word书签等内容,本篇文章将继续介绍C#操作word书签的方法。下面的示例中将介绍C# 如何读取Word书签C# 如何替换Word书签工具使用Spire.Doc for .NET 示例代码原文档中的书签内容:1. 读取word书签using Spire.Doc; using Spire.Doc.Documents; ...

weixin_35227213的博客 434

完美解决LBP2900打印机安装驱动提示无法识别USB及连接错误等问题(附Win11全新安装支持及卸载方案)

LBP2900打印机虽然经典老旧,但在Win11上依然可以完美使用!许多网上教程都无视安装失败后的问题,在此分享一种全新、100%有效的方法来解决驱动连接错误和无法识别USB设备的问题。无论是新安装还是卸载重装,这个方法都适用。本文整合了通用驱动包,支持Win2000到Win11系统,操作简单,轻松摆脱安装困扰,享受无忧打印体验!

心开始の未来~的博客 2万+

基于PLC的全自动洗衣机控制系统+控制程序

本设计使用PLC控制系统替换了传统的继电器控制系统,实现了全自动洗衣机在硬件方面的提升,丰富了全自动洗衣机在软件方面的功能,提高了全自动洗衣机的洗衣效率,基本可以满足用户的洗衣需求。

zzzz114231的博客 8965

Word控件Spire.Doc 【书签】教程(3): 使用 HTML 代码编辑/替换 Word 书签的内容

功能类库Spire 系列文档处理组件均由中国本土团队研发,不依赖第三方软件,不受其他国家的技术或法律法规限制,同时适配国产操作系统如中科方德、中标麒麟等,兼容国产文档处理软件 WPS(如 .wps/.et/.dps 等格式。以上便是如何在 C#、VB.NET 中使用 HTML 代码编辑/替换 Word 书签的内容,如果您有其他问题也可以继续浏览本系列文章,获取相关教程,你还可以给我留言或者加入我们的官方技术交流群。书签可以定位一个范围。假设range的内容是一些html代码,如何改变range的内容。

励志做最业余的专业博主,控件产品可以私我~ 1397

国产化操作系统shell常用脚本

国产操作系统常用脚本:统信、麒麟。

Reyn_观极 605

C#操作Word书签实例浅析

 Word.Application app = new Word.Application();   //模板文件   //C#操作Word书签string TemplateFile = @"D:/lin/Invoice.doc";   //生成的具有模板样式的新文件   //C#操作Word书签string FileName = @"D:/lin/" +   DateTime.Now.ToStri

skylarkzcc的专栏 1566

efm32 入门.pdf

本PDF共计22页,介绍的是操作驱动API,下载与否自己斟酌。

Devexpress16.2.6破解工具

Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具

js读取word文档内容_C# 操作Word书签(二)——读取、替换Word书签

在上一篇文章中介绍了关于C#如何插入Word书签、插入图片或表格到word、删除word书签等内容,本篇文章将继续介绍C#操作word书签的方法。下面的示例中将介绍C# 如何读取Word书签C# 如何替换Word书签工具使用Spire.Doc for .NET 示例代码原文档中的书签内容:1. 读取word书签using 读取结果如下2. 替换书签内容using 测试结果:(完)...

weixin_39882623的博客 206

文档:亲测可用解决vnc灰屏,黑屏,鼠标大黑叉情况

主要解决vnc-viewer灰屏,黑屏,鼠标大黑叉等现象,详细见文档。

c#endread怎么打印出来_C#如何打印word模板

if(wApp.ActiveDocument.Bookmarks.Exists(strbook[i].ToString())){wApp.ActiveDocument.Bookmarks.get_Item(reftempobject).Select();wApp.Selection.Text=demostr[i].ToString();}}Microsoft.Office.Interop.Word...

weixin_39529443的博客 112

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

c# word

None

zhongjie的专栏 719

word c#模板

需要添加com组件添加using Microsoft.Office.Interop.Word;具体是读word模版 写数据保存新wordApplicationClass wordApp = new ApplicationClass();object missing = System.Reflection.Missing.Value;...........object rea

天使的天空 668

C# WORD操作实现代码

在当前项目开发过程中,客户有根据数据库数据生成WORD文档的需求,在和同事沟通的过程中,找到了两个解决方案1.先通过程序生成报表样式的HTML页面,然后修改HTML页面的后缀名为DOC。  2.定制WORD文档的模板文件,在C#中操作WORD模板,生成新的WORD文档。 第一方案简单,只需要改动文件的扩展名就行了,但是也存在了一些问题,譬如生成的WORD文档样式的丢失。这样对于客户来说可能是一个无...

weixin_34004576的博客 103

C# WORD操作实现代码 笔记

1.先通过程序生成报表样式的HTML页面,然后修改HTML页面的后缀名为DOC。2.定制WORD文档的模板文件,在C#中操作WORD模板,生成新的WORD文档。第一方案简单,只需要改动文件的扩展名就行了,但是也存在了一些问题,譬如生成的WORD文档样式的丢失。这样对于客户来说可能是一个无法通过的方案。第二方案比较复杂,需要调用OFFICE的WORD组件通过C#来操作WORD,进而生成WORD。此方...

各研发管理 273

C# 读取Word中的书签

本文介绍如何在C#程序中如何来读取Word文档中的书签内容。关于C#如何添加,替换和删除书签的话,可参考这篇文章。 使用工具:Spire.Doc for .NET pack 8.1 原文档中的书签内容如下: 【C#】 using Spire.Doc; using Spire.Doc.Documents; using Spire.Doc.Fields; using System; namespace GetTextOfBookmark_Doc { class Program {

Eiceblue的专栏 1766

C# 使用书签替换word中的公式

C# 使用书签替换word中的公式 先创建一个word,随便添加一个公式在里面,选中添加的公式,添加一个书签,我这边添加的书签名为bookmark_10 上代码 需要引用Microsoft.Office.Interop.Word; try { Word.Application app = new Word.Application(); //生成word程序对象 Word.Document doc = new Word.D

qq_41485698的博客 475

c# winform word模板 利用WORD 书签 定位替换 生成 WORD

private void button1_Click(object sender, EventArgs e) { //模板文件 string templateFile = @"Word模板.doc"; //生成的具有模板样式的新文件 string fileName = @"F:\弘和...

书写人生 1969
下一篇: 详解Spire.PDF中的坐标体系及应用
ssw_jack
博客等级 码龄12年 5粉丝 4原创
评论 5
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值