添加程序包 DocX

using System.IO;
using Novacode;

        /// <summary>
/// 导出Word
/// </summary>
public FileResult GetExportWord()
{
var items = _service.GetAll(); //string path = @"~/Content/Templates/Vote.docx";
//string path = @"/Content/Templates/Vote.docx"; string path = Server.MapPath("/Content/Templates/Vote.docx");
string fileName = "票决结果.docx";
DocX doc;
try
{
// Store a global reference to the loaded document.
doc = DocX.Load(path);
var table = doc.Tables[]; var row = table.Rows[];
for (var i = ; i < items.Count; i++)
{
table.InsertRow(row, i + );
}
for (var i = ; i < items.Count; i++)
{
var item = items[i];
var curRow = table.Rows[i + ]; curRow.Cells[].MarginTop = ;
curRow.Cells[].MarginBottom = ;
curRow.Cells[].Paragraphs[].InsertText((i + ).ToString());
curRow.Cells[].MarginTop = ;
curRow.Cells[].MarginBottom = ;
curRow.Cells[].Paragraphs[].InsertText(item.Name ?? "");
curRow.Cells[].MarginTop = ;
curRow.Cells[].MarginBottom = ;
curRow.Cells[].Paragraphs[].InsertText(item.Company ?? "");
curRow.Cells[].MarginTop = ;
curRow.Cells[].MarginBottom = ;
curRow.Cells[].Paragraphs[].InsertText(item.Email ?? "");
curRow.Cells[].MarginTop = ;
curRow.Cells[].MarginBottom = ;
curRow.Cells[].Paragraphs[].InsertText(item.Location ?? "");
curRow.Cells[].MarginTop = ;
curRow.Cells[].MarginBottom = ;
curRow.Cells[].Paragraphs[].InsertText(item.Location ?? "");
curRow.Cells[].MarginTop = ;
curRow.Cells[].MarginBottom = ;
curRow.Cells[].Paragraphs[].InsertText(item.Location ?? "");
curRow.Cells[].MarginTop = ;
curRow.Cells[].MarginBottom = ;
curRow.Cells[].Paragraphs[].InsertText(item.Location ?? "");
} var stream = new MemoryStream();
doc.SaveAs(stream);
stream.Position = ; return File(stream, "application/vnd.ms-word", fileName);
} // The template 'InvoiceTemplate.docx' does not exist, so create it.
catch (Exception er)
{
throw er;
}
}

MVC4 导出word的更多相关文章

  1. java 导出word 并下载

    记录一下导出操作 源码: /************ * 导出word 并下载 * @param id 房号记录编号 * ***********************/ @RequestMappin ...

  2. Asp.net通过模板(.dot/Html)导出Word,同时导出图片

    一.Office组件导出Word(服务器配置麻烦) 需要引用Office的DLL,在下文的附件中,不同的Offic版本用的不一样,虽然高级版本可以兼容低级的,不过,还是统一版本最好 贴上核心代码(转载 ...

  3. 导出Excel And 导出word

      <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default6.aspx. ...

  4. 使用NPOI2.1.3.1版本导出word附带表格和图片

    原文:http://www.cnblogs.com/afutureBoss/p/4074397.html?utm_source=tuicool&utm_medium=referral 最近项目 ...

  5. Java使用velocity导出word

    效果展示: 使用word编辑好模板

  6. 【吉光片羽】MVC 导出Word的两种方式

    1.直接将Html转成Word.MVC自带FileResult很好用.Html中我们也可以嵌入自己的样式. html: <div id="target"> <st ...

  7. java导出word的6种方式(复制来的文章)

    来自: http://www.cnblogs.com/lcngu/p/5247179.html 最近做的项目,需要将一些信息导出到word中.在网上找了好多解决方案,现在将这几天的总结分享一下. 目前 ...

  8. 【MVC】 非常简单的页面导出 WORD, EXCEL方法

    [MVC] 页面导出 WORD, EXCEL 前端 js function output() { var para = new Object(); para.html = getHtml(" ...

  9. 网页内容导出word/excel的js代码

    IE设置: 工具-> Internet选项-> 安全->自定义级别-> 对没有标记安全级别的ActiveX控件进行初始化  设为启用! 1.导出word //指定区域导出到Wo ...

随机推荐

  1. mysql binlog恢复

    MySQL Binary Log也就是常说的bin-log, ,是mysql执行改动产生的二进制日志文件,其主要作用有两个: * 数据回复 * 主从数据库.用于slave端执行增删改,保持与maste ...

  2. hive中的常用方法(case,cast,unix_timestamp)

    1.case的用法 )格式1 case col when value then '' when value then '' else '' end )格式2 case when col='value' ...

  3. Delphi xe7 FireMonkey / Mobile (Android, iOS)生成 QR Code完整实例

    这个实例在windows.OS X.IOS和Android等平台运行正常.本文参考这个网站提供的方法:http://zarko-gajic.iz.hr/firemonkey-mobile-androi ...

  4. net use

    net use * \\ipaddr\share "password" /user:"username" /persistent:yes 在运行中输入“\\”+ ...

  5. Python 时间 日期常见操作

    import datetime,time dtstr = '2014-02-14 21:32:12' a = datetime.datetime.strptime(dtstr, "%Y-%m ...

  6. JS中注意原型链的“指向”

    昨天压缩Js文件时发现了项目中的一个prototype的问题代码如下所示: 1. <script> var XXX = function(){ }; var x1 = new XXX(); ...

  7. js跳转方法

    很有用的东西,参考自http://www.zhuoda.org/lunzi/66097.html 第一种 <script language="javascript" type ...

  8. logback详细配置(三)

    转自:http://blog.csdn.net/haidage/article/details/6794540 <filter>: 过滤器,执行一个过滤器会有返回个枚举值,即DENY,NE ...

  9. 进度太慢了,扫频仪PCB

    实在是画过最纠结的一块PCB,左边布线很轻松,但是右边32芯片用到FSMC,还有很多个引出的IO口,相互交叉纠结在了一起,有几根线一路打了3,4个过孔,实在是难布. 工程查了下是6月17号画原理图的, ...

  10. sequelize翻译(1)

    第一次翻译(由mongoose转了mysql) v 3.0.0 1.Sequelize类 2.sequelize对象 3.sequelize.define()返回的表对象 4.表对象的方法 1.Seq ...