添加程序包 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. ecshop insert用法

    1 {insert name='ads' id=$ads_id num=$ads_num} 控制语句是在 /includes/lib_insert.php 文件.这个文件是ecshop动态内容函数库. ...

  2. Maven实战(一)安装与配置

    1. 简介 Maven是基于项目对象模型(POM),可以通过一小段描述信息来管理项目的构建,报告和文档的软件项目管理工具. 如果你已经有十次输入同样的Ant targets来编译你的代码.jar或者w ...

  3. JavaScript操作数组

    数组被描述为一个存储元素的线性集合,元素可以通过索引来任意存取. 几乎所有的编程语言都有类似的数据结构,但是Javascript中的数组却略有不同. Javascript中的数组是一种特殊的对象,所以 ...

  4. 根据IP查主机名和MAC地址

    根据IP查主机名: nbtstat -a XXX.XXX.XXX.XXX根据IP查MAC地址: arp -a XXX.XXX.XXX.XXXXXX.XXX.XXX.XXX指代要查的主机的IP

  5. iOS UPYUN(又拍云)使用总结

    UPYUN,原来没用过,上个周用了一次,觉得蛮方便的,对于个人开发者,且没有服务器的,上传图片和文件,是个不二选择. 首先,先明白原理: 1.又拍云有一个上传空间,在这个空间里,有空间名称.密钥,其他 ...

  6. Java学习-014-文本文件写入实例源代码(两种写入方式)

    此文源码主要为应用 Java 读取文本文件内容实例的源代码.若有不足之处,敬请大神指正,不胜感激! 第一种:文本文件写入,若文件存在则删除原文件,并重新创建文件.源代码如下所示: /** * @fun ...

  7. Sequential Read Ahead For SQL Server

    Balancing CPU and I/O throughput is essential to achieve good overall performance and to maximize ha ...

  8. zookeeper session tracker机制分析

    说到zookeeper session管理 ,免不了要问 什么是session? session id/session是如何产生的? session 信息如何存储? 本文以session tracke ...

  9. SWIFT 闭包的简单使用

    import UIKit @UIApplicationMain class AppDelegate: UIResponder, UIApplicationDelegate { var window: ...

  10. cocos2dx 3.x以上(Sprite精灵类的相关属性与创建)

    // //  MainScene.cpp //  helloworld // //  Created by apple on 16/9/19. // // #include "MainSce ...