C#动态生成Word文档并填充数据(一)

[C#]用C#动态生成Word文档并将数据填入Word表格中(续) 再补充一些关于C#动态生成Word文档的操作WordDoc.PageSetup.Orientation = Word.WdOrientation.wdOrientLandscape;//页面设置为横向WordApp.Selection.ParagraphFormat.SpaceAfter = 10f;//段后距离WordApp.Selection.TypeText("产品材料表");//在 阅读详情

 忽然觉得生成word这个东东很好玩,就搜来看看,自己动手了一下,还是比较有意思的哦~~
【摘要】
要利用 C# 的自动化功能创建新的 Word 文档,请执行以下8个步骤

【全文】

要利用 C# 的自动化功能创建新的 Word 文档,请执行以下步骤:
1. 启动 Microsoft Visual Studio .NET。在文件菜单上,单击新建,然后单击项目。在项目类型下,单击 Visual C# 项目,然后单击模板下的 Windows 应用程序。默认情况下会创建 Form1。
2. 添加对 Microsoft Word 对象库的引用。为此,请按照下列步骤操作:
a. 在项目菜单上,单击添加引用。
b. 在 COM 选项卡上,找到 Microsoft Word 对象库,然后单击选择。
c. 在添加引用对话框中单击确定,接受您的选择。如果系统提示您为选定的库生成包装,请单击是。
3. 在视图菜单上,选择工具箱以显示工具箱,然后向 Form1 添加一个按钮。
4. 双击 Button1。出现该窗体的代码窗口。
5. 在代码窗口中,将以下代码
private void button1_Click(object sender, System.EventArgs e)
{
    object oMissing = System.Reflection.Missing.Value;
    object oEndOfDoc = "//endofdoc"; /* /endofdoc is a predefined bookmark */

    //Start Word and create a new document.
    Word._Application oWord;
    Word._Document oDoc;
    oWord = new Word.Application();
    oWord.Visible = true;
    oDoc = oWord.Documents.Add(ref oMissing, ref oMissing,
        ref oMissing, ref oMissing);

    //Insert a paragraph at the beginning of the document.
    Word.Paragraph oPara1;
    oPara1 = oDoc.Content.Paragraphs.Add(ref oMissing);
    oPara1.Range.Text = "Heading 1";
    oPara1.Range.Font.Bold = 1;
    oPara1.Format.SpaceAfter = 24;    //24 pt spacing after paragraph.
    oPara1.Range.InsertParagraphAfter();

    //Insert a paragraph at the end of the document.
    Word.Paragraph oPara2;
    object oRng = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range;
    oPara2 = oDoc.Content.Paragraphs.Add (ref oRng);
    oPara2.Range.Text = "Heading 2";
    oPara2.Format.SpaceAfter = 6;
    oPara2.Range.InsertParagraphAfter();

    //Insert another paragraph.
    Word.Paragraph oPara3;
    oRng = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range;
    oPara3 = oDoc.Content.Paragraphs.Add(ref oRng);
    oPara3.Range.Text = "This is a sentence of normal text. Now here is a table:";
    oPara3.Range.Font.Bold = 0;
    oPara3.Format.SpaceAfter = 24;
    oPara3.Range.InsertParagraphAfter();

    //Insert a 3 x 5 table, fill it with data, and make the first row
    //bold and italic.
    Word.Table oTable;
     Word.Range wrdRng = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range;
    oTable = oDoc.Tables.Add(wrdRng, 3, 5, ref oMissing, ref oMissing);
    oTable.Range.ParagraphFormat.SpaceAfter = 6;
    int r, c;
    string strText;
    for(r = 1; r <= 3; r++)
        for(c = 1; c <= 5; c++)
        {
            strText = "r" + r + "c" + c;
            oTable.Cell(r, c).Range.Text = strText;
        }
    oTable.Rows[1].Range.Font.Bold = 1;
    oTable.Rows[1].Range.Font.Italic = 1;

    //Add some text after the table.
    Word.Paragraph oPara4;
    oRng = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range;
    oPara4 = oDoc.Content.Paragraphs.Add(ref oRng);
    oPara4.Range.InsertParagraphBefore();
    oPara4.Range.Text = "And here's another table:";
    oPara4.Format.SpaceAfter = 24;
    oPara4.Range.InsertParagraphAfter ();

    //Insert a 5 x 2 table, fill it with data, and change the column widths.
    wrdRng = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range;
    oTable = oDoc.Tables.Add(wrdRng, 5, 2, ref oMissing, ref oMissing);
    oTable.Range.ParagraphFormat.SpaceAfter = 6;
    for(r = 1; r <= 5; r++)
        for(c = 1; c <= 2; c++)
        {
            strText = "r" + r + "c" + c;
            oTable.Cell (r, c).Range.Text = strText;
        }
    oTable.Columns[1].Width = oWord.InchesToPoints(2); //Change width of columns 1 & 2
    oTable.Columns[2].Width = oWord.InchesToPoints(3);

    //Keep inserting text. When you get to 7 inches from top of the
    //document, insert a hard page break.
    object oPos;
    double dPos = oWord.InchesToPoints(7);
    oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range.InsertParagraphAfter();
    do
    {
        wrdRng = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range;
        wrdRng.ParagraphFormat.SpaceAfter = 6;
        wrdRng.InsertAfter("A line of text");
        wrdRng.InsertParagraphAfter();
        oPos = wrdRng.get_Information
                       (Word.WdInformation.wdVerticalPositionRelativeToPage);
    }
    while(dPos >= Convert.ToDouble(oPos));
    object oCollapseEnd = Word.WdCollapseDirection.wdCollapseEnd;
    object oPageBreak = Word.WdBreakType.wdPageBreak;
    wrdRng.Collapse(ref oCollapseEnd);
    wrdRng.InsertBreak(ref oPageBreak);
    wrdRng.Collapse(ref oCollapseEnd);
    wrdRng.InsertAfter("We're now on page 2. Here's my chart:");
    wrdRng.InsertParagraphAfter();

    //Insert a chart.
    Word.InlineShape oShape;
    object oClassType = "MSGraph.Chart.8";
    wrdRng = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range;
    oShape = wrdRng.InlineShapes.AddOLEObject(ref oClassType, ref oMissing,
        ref oMissing, ref oMissing, ref oMissing,
        ref oMissing, ref oMissing, ref oMissing);

    //Demonstrate use of late bound oChart and oChartApp objects to
    //manipulate the chart object with MSGraph.
    object oChart;
    object oChartApp;
    oChart = oShape.OLEFormat.Object;
    oChartApp = oChart.GetType().InvokeMember("Application",
         BindingFlags.GetProperty, null, oChart, null);

    //Change the chart type to Line.
    object[] Parameters = new Object[1];
    Parameters[0] = 4; //xlLine = 4
    oChart.GetType().InvokeMember("ChartType", BindingFlags.SetProperty,
        null, oChart, Parameters);

    //Update the chart image and quit MSGraph.
    oChartApp.GetType().InvokeMember("Update",
        BindingFlags.InvokeMethod, null, oChartApp, null);
    oChartApp.GetType().InvokeMember("Quit",
        BindingFlags.InvokeMethod, null, oChartApp, null);
    //... If desired, you can proceed from here using the Microsoft Graph
    //Object model on the oChart and oChartApp objects to make additional
    //changes to the chart.

    //Set the width of the chart.
    oShape.Width = oWord.InchesToPoints(6.25f);
    oShape.Height = oWord.InchesToPoints(3.57f);

    //Add text after the chart.
    wrdRng = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range;
    wrdRng.InsertParagraphAfter();
    wrdRng.InsertAfter("THE END.");

    //Close this form.
    this.Close();
}

6. 滚动到代码窗口的顶部。将下面的代码行添加到 using 指令列表的末尾:
using Word = Microsoft.Office.Interop.Word;
   using System.Reflection;

7. 按 F5 键生成并运行程序。
8. 单击 Button1,启动 Word 自动化功能并创建文档。
代码执行完成后,检查为您创建的文档。该文档包含两页设置了格式的段落、表格和图表。

如果您要使用自动化功能创建的文档都是通用格式,则利用基于预设格式的模板的新文档来开始创建过程会更加容易。与从头创建文档相比,将某个模板与 Word 自动化客户端配合使用有两大优点:
您可以对整个文档中的对象的格式设置和布局施加更多控制。
可以使用较少的代码创建文档.

通过使用模板,可以精确地调整表格、段落和其他对象在文档中的布局,并可为这些对象添加格式设置。通过使用自动化功能,可以基于包含下面这样的代码的模板创建新文档:
object oTemplate = "c://MyTemplate.dot";
   oDoc = oWord.Documents.Add (ref oTemplate, ref oMissing,
   ref oMissing, ref oMissing);

在模板中,可以定义书签,这样,自动化客户端就可以在文档的特定位置加入可变文本,如下所示:
object oBookMark = "MyBookmark";
   oDoc.Bookmarks.Item (ref oBookMark).Range.Text = "Some Text Here";

使用模板的另一个优点在于,您可以创建和存储希望在运行时应用的格式样式,如下所示:

object oStyleName = "MyStyle";
   oDoc.Bookmarks.Item (ref oBookMark).Range.set_Style(ref oStyleName);

- 或者 -
object oStyleName = "MyStyle";
   oWord.Selection.set_Style(ref oStyleName);

C#使用NPOI获取Word模板文档,并填充数据 Word模板:原文档很长,这里只展示一部分。 阅读详情

相关推荐

C# 实现 Word 标签模板批量填充:自动插入文本和图片的完整教程

通过上述步骤,你可以轻松地将多条数据记录(包括文本和图片)批量填充到 Word 标签模板中,并生成新的文档。这种方法非常适合用于生成动态文档,如报告、合同、发票等,尤其在需要插入图片时。使用来操作 Word 文件的好处是它不依赖于 Office 软件,适合在服务器端或自动化任务中使用。同时,它也非常高效,可以处理大量文档的生成任务。希望这篇教程能帮助你更好地理解如何通过 C# 操作 Word 文件,处理批量数据填充和图片插入的任务!

这里只有干货:从 Modbus 通信到 MES 对接,从 YOLO 训练到工控机部署,带你搞定工业软件开发全流程。 1816

C# word文件填充导出数据

在项目中对于word文件的操作大多需要使用微软的依赖或是WPS或使用其他收费应用,在使用过程中不可避免的问题能够浪费开发者的大量时间,所以才有了此教程。首先,教程中只写了一个功能“建好word模板文件后,存在占位后进行填充数据”。环境:.Net6.0。

互联网民工手记 1535

用C#实现动态生成Word文档,在Word文档中插入表格,并将读出的数据填入到表格中

要使用C#操作word,首先要添加引用:       1、添加引用->COM->Microsoft Word 11.0 Object Library       2、在.cs文件中添加using Word;using NewWord = Microsoft.Office.Interop.Word;下面的例子中包括C#对Word文档的创建、插入表格、设置样式等操作:(例子中代码有些涉

Mr.King 2041

C#向带有书签的word模板自动填充内容的方法

本篇文章经过转载而来,自己在项目中进行运用,效果确实不错,推荐大家尝试! 这篇文章主要介绍了C#实现通过模板自动创建Word文档的方法,详细讲述了C#生成Word文档的实现方法,是非常实用的技巧,需要的朋友可以参考下 本文实例讲述了C#实现通过模板自动创建Word文档的方法,是非常实用的技巧。分享给大家供大家参考。具体实现方法如下: 引言:前段时间有项目要用c#生成Word格式的计算报...

weixin_30955617的博客 1097

C# NPOI生成word插入图片和表格

通过C#调用NPOI组件生成Word文档,在生成Word文档过程中插入表格以及插入图片,使用到了C#,扩展等技术

解决Android 14兼容性问题:NDK中arm64-v8a的正确配置方法

本文详细解析Android 14系统架构变化对NDK开发的影响,重点介绍arm64-v8a架构的正确配置方法。针对常见的兼容性问题如so库缺失、ABI不匹配等提供解决方案,并分享性能优化与自动化测试实践,助力开发者高效适配Android 14设备。

algae的博客 1235

[C#]用C#动态生成Word文档并将数据填入Word表格中

刚刚实现了个功能:用C#实现动态生成Word文档,在Word文档中插入表格,并将读出的数据填入到表格中。要使用C#操作word,首先要添加引用:       1、添加引用->COM->Microsoft Word 11.0 Object Library       2、在.cs文件中添加using Word;下面的例子中包括C#对Word文档的创建、插入表格、设置样式等

有了大树的幸福树懒~~~的专栏 4563

无人机遥控Lora信号时域、频域与时频图分析指南

面对一段未知的射频信号,如何判断它是否是Lora调制?时域波形、频域谱线与时频图是信号分析的三个互补维度。Lora采用chirp扩频调制,恒包络特性使其在时域上看似噪声,频域上能量均匀分布,唯有时频图能清晰呈现符号结构与调制参数。通过短时傅里叶变换(STFT),可直观提取信号带宽、符号周期与扩展因子,从而为无人机遥控信号的解调解码提供可靠依据。本文结合实际采集样本,系统讲解三域分析的核心方法、参数反推技巧与常见陷阱,帮助工程师快速建立对Lora信号的直观认知,提升信号逆向分析与工程实践效率。

weixin_29164091的博客 278

C#动态生成Word文档并填充数据

WordDoc.Paragraphs.Last.Range.Text = "文档创建时间:" + DateTime.Now.ToString();WordApp.ActiveWindow.ActivePane.Selection.InsertAfter("[页眉内容]");//设置文档的行间距。

biyusr的专栏 1054

Modelsim 安装步骤详解

Modelsim 安装步骤详解目录一、modelsim简述及下载1、简介及特点2、modelsim版本3、modelsim下载二、安装步骤详解三、注册简述四、总结与参考资料1、总结2、参考资料 目录 本篇文章主要对Modelsim SE版本安装步骤的介绍。 一、modelsim简述及下载 1、简介及特点 简介 modelsim是Mentor公司开发的优秀的HDL语言仿真软件。 它能提供友好的仿真环境,采用单内核支持VHDL和Verilog混合仿真的仿真器。它采用直接优化的编译技术、Tcl/Tk技术和单

执迷不悟 15万+

淘宝x-mini-wua生成机制与硬件信息关联性深度解析

本文深度解析了淘宝x-mini-wua的生成机制与硬件信息的关联性,详细介绍了其作为设备指纹令牌的核心作用及技术实现细节。通过分析基础硬件层、环境特征层和行为特征层的数据采集,揭示了淘宝如何利用AES加密和分级加密策略防止破解,并探讨了其安全防护与对抗策略。

weixin_29243279的博客 242

C#也能动态生成Word文档并填充数据, 导出EXCEL 方法

要使用C#操作word,首先要添加引用:         1、添加引用->COM->Microsoft Word 11.0 Object Library        2、在.cs文件中添加 using Word; 下面的例子中包括C#对Word文档的创建、插入表格、设置样式等操作: (例子中代码有些涉及数据信息部分被省略,重要是介绍一些C#操作word文档的方法)        

wang463584281的专栏 3426

【python】geopandas库安装出现各种问题?可以看看这篇文章

geopandas的安装方法

jgsecurity的博客 3897

C#编程实现动态生成Word文档

<br />C#编程实现动态生成Word文档   如何用C#编程实现动态生成Word文档并填充数据的效果呢?要使用C#操作word,首先要添加引用:<br />    1、添加引用->COM->Microsoft Word 11.0 Object Library<br />    2、在.cs文件中添加<br />    using  Word;<br />    下面的例子中包括C#对Word文档的创建、插入表格、设置样式等操作:<br />    (例子中代码有些涉及数据信息部分被省略,重要是介绍一些C

天使的天空 829

MATLAB下pdf文件操作读取示例

当遇到一些需要大量数据的项目,数据的读取与储存显得尤为重要。怎样把数据从其他格式的文件中读取,并运用到程序中是很多时候我们要解决的问题。对于平常的.txt,和.xlsx文件,MATLAB有对应的函数帮助读取,但是遇到pdf文件时MATLAB很难读取内容。本文以一个操作实例提供了一个从pdf文件中读取数据的方法。

UESTC 五高考3模拟的博客 6565

合肥工业大学嵌入式系统原理实验报告

GPKDAT 的6、7引脚设置低电平,设置GPKDAT = 0x30则34灯亮12灯灭,GPKDAT 的4、5、6、7引脚全为高电平,设置GPKDAT = 0xf0,则led灯全灭。注意在烧写时要连接主机后面的USB接口,烧写完成后,要关闭开发板电源,将S2拨动开关置于NAND位置,然后重新开启开发板电源, 则开发板运行刚刚烧入的裸机程序。实验修改要求:在延时不变的条件下,将原程序中四个LED全亮,然后全灭的显示状态,修改为“四个全亮,然后1和2亮(3和4灭),然后3和4亮(1和2灭),最后全灭”。

Martin-share的博客 3102

用C#动态生成Word文档并将数据填入Word表格中

刚刚实现了个功能:用C#实现动态生成Word文档,在Word文档中插入表格,并将读出的数据填入到表格中。 要使用C#操作word,首先要添加引用:       1、添加引用->COM->Microsoft Word 11.0 Object Library        2、在.cs文件中添加using Word;下面的例子中包括C#对Word文档的创建、插入表格、设置样

1197

TC3XX - MCAL知识点(二十九):FLS MCAL配置及代码实战(英飞凌DFLASH)

FLS驱动程序为DFlash 0的初始化、读取、写入和擦除提供了定义良好的配置和标准服务。除此之外,我们还提供一些非autosar服务示例 Fls_17_Dmu_CompareWordsSync、Fls_17_Dmu_CancelNonEraseJobs、Fls_17_Dmu_VerifyErase,LFls_17_Dmu_VerifySectorErase、Fls_17_Dmu_GetNotifCaller等。用户通过FLS驱动程序获得对底层DFlash0的封装访问。

梦想技术家 2372

C#也能动态生成Word文档并填充数据

要使用C#操作word,首先要添加引用:       1、添加引用->COM->Microsoft Word 11.0 Object Library       2、在.cs文件中添加using Word;下面的例子中包括C#对Word文档的创建、插入表格、设置样式等操作:(例子中代码有些涉及数据信息部分被省略,重要是介绍一些C#操作word文档的方法)        public

夏风鱼的专栏 912

LinePhone3.2.7(android端最新版本) sip客户端

SIP客户端For android:LinePhone3.2.7(最新版本),官网地址:http://www.linphone.org/

深度学习工具包 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")

实现动态生成Word文档

  如何用C#编程实现动态生成Word文档并填充数据的效果呢?要使用C#操作word,首先要添加引用:    1、添加引用->COM->Microsoft Word 11.0 Object Library    2、在.cs文件中添加    using Word;   [注意:using Word = Microsoft.Office.Interop.Word;]    下面的例子中包括C#对Wo

№快乐因你♂ 1236

迈瑞BS系列全自动生化分析仪LIS协议接口手册(内含HL7和ASTM)

迈瑞BS系列全自动生化分析仪LIS协议接口手册,内含HL7和ASTM)

Asp.net动态生成Word文档并填充数据

 操作步骤如下:首先要添加引用:        1、添加引用->COM->Microsoft Word 11.0 Object Library       2、在.cs文件中添加 using Word;代码如下:public string CreateWordFile(string CheckedInfo)    {        string message = "";     

朩冰雲的专栏 4069

RU DOS版、EFI版32bit/64bit BIOS常用工具

DOS版、EFI版的RU工具,可用来查看IO、MEM、PCI、SMBIOS等资源。亲测在EFI SHELL下可用。

上一篇: 一个可以用来站内检索的简单爬虫
下一篇: C#动态生成Word文档并填充数据(二)
wangicter
博客等级 码龄17年 405粉丝 205原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值