添加程序包 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. 答CsdnBlogger问-关于职业发展和团队管理问题

    本文来自http://blog.csdn.net/liuxian13183/ ,引用必须注明出处! 问1:关于职业发展以及团队管理?(正能同學_) 请问在二线城市的小公司里,普通Android开发者的 ...

  2. C++ 自动指针 共享指针

    #include <iostream> #include <string> #include <memory> class Item { public: Item( ...

  3. 添加事件(jquery)

    对盒子内部的盒子添加跟本身盒子相同的事件的时候,需要小心谨慎一点. 诸如: 从表象上看似乎没有什么太大问题,但是却存在一个致命的问题,就是每次点击box的时候,都会给test添加一个点击事件,而添加的 ...

  4. css“变形”效果

    <html <head> <title></title> <style> .test { margin-left:300px; margin-to ...

  5. Ajax无刷新提交

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  6. MAGENTO程序结构图

    Magento程序结构图(Program Structure Diagram): /app – 程序根目录 /app/etc – 全局配置文件目录 /app/code – 所有模块安装其模型和控制器的 ...

  7. 搜索框UISearchController的使用(iOS8.0以后替代UISearchBar + UISearchDisplayController)

    1.searchResultsUpdater:设置显示搜索结果的控制器 ? 1     _mySearchController.searchResultsUpdater = self; 2.dimsB ...

  8. linux bq20z75 驱动

    新的项目中使用到了电池.电池的guage使用TI的bq20z75.kernel的驱动中已经有bq20z75的驱动,只要稍加修改就可以使用. 参考链接 http://www.ti.com/lit/er/ ...

  9. 通过iphone蓝牙与经过苹果MFI授权认证的硬件通讯,传输图片(转)

    http://blog.csdn.net/hwj2012/article/details/7883711 相关: http://blog.csdn.net/xufeidll/article/detai ...

  10. POJ 1028题目描述

    Description Standard web browsers contain features to move backward and forward among the pages rece ...