MVC4 导出word
添加程序包 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的更多相关文章
- java 导出word 并下载
记录一下导出操作 源码: /************ * 导出word 并下载 * @param id 房号记录编号 * ***********************/ @RequestMappin ...
- Asp.net通过模板(.dot/Html)导出Word,同时导出图片
一.Office组件导出Word(服务器配置麻烦) 需要引用Office的DLL,在下文的附件中,不同的Offic版本用的不一样,虽然高级版本可以兼容低级的,不过,还是统一版本最好 贴上核心代码(转载 ...
- 导出Excel And 导出word
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default6.aspx. ...
- 使用NPOI2.1.3.1版本导出word附带表格和图片
原文:http://www.cnblogs.com/afutureBoss/p/4074397.html?utm_source=tuicool&utm_medium=referral 最近项目 ...
- Java使用velocity导出word
效果展示: 使用word编辑好模板
- 【吉光片羽】MVC 导出Word的两种方式
1.直接将Html转成Word.MVC自带FileResult很好用.Html中我们也可以嵌入自己的样式. html: <div id="target"> <st ...
- java导出word的6种方式(复制来的文章)
来自: http://www.cnblogs.com/lcngu/p/5247179.html 最近做的项目,需要将一些信息导出到word中.在网上找了好多解决方案,现在将这几天的总结分享一下. 目前 ...
- 【MVC】 非常简单的页面导出 WORD, EXCEL方法
[MVC] 页面导出 WORD, EXCEL 前端 js function output() { var para = new Object(); para.html = getHtml(" ...
- 网页内容导出word/excel的js代码
IE设置: 工具-> Internet选项-> 安全->自定义级别-> 对没有标记安全级别的ActiveX控件进行初始化 设为启用! 1.导出word //指定区域导出到Wo ...
随机推荐
- php--group_concat()函数总结
group_concat(),手册上说明:该函数返回带有来自一个组的连接的非NULL值的字符串结果. 比较抽象,难以理解. 通俗点理解,其实是这样的:group_concat()会计算哪些行属于同一组 ...
- RelativeLayout不能调用measure去直接测量子元素
RelativeLayout在实现onMeasure方法时并没有像LinearLayout一样去重写如下代码: @Override protected void onMeasure(int width ...
- Arbitrage---poj2240(floyd)
题目链接:http://poj.org/problem?id=2240 题意:有n个国家的,有m个关系,每个关系的格式是:A B C表示1单位的A国货币可以换B单位C国货币:求是否存在一种方法使得货币 ...
- Selenium2学习-032-WebUI自动化实战实例-030-JavaScript 在 Selenium 自动化中的应用实例之五(高亮标示元素)
在自动化脚本编写过程中,操作元素之前,需要对元素进行高亮显示(通过修改元素的边框样式),同时进行截图,以记录操作的元素对象.在实际应用中较为少见,通常用于演示,或者发生错误时的屏幕截图捕捉,用于错误报 ...
- Windows7下 配置 Apache + PHP + MySQL + Zend Studio配置
相关软件下载: Apache 版本:(httpd-2.2.25) PHP ...
- SQL Server 取日期时只要年月或年月日
select CONVERT(varchar(7) ,getdate(), 120) as 'Date' from 表名;--只取年月且日期格式为 xxxx-xx select CONVERT(var ...
- Nosql之Redis篇
一.QuickStart 1.Redis简介: redis是一个性能优秀的内存数据库,通过key-value存储系统.和Memcached类似,它支持存储的value类型相对更多,包括string(字 ...
- C++经典编程题#6:分配病房
总时间限制: 1000ms 内存限制: 65536kB 描述 某个科室的病房分为重症和普通,只有当病人的疾病严重程度超过了入住重症病房的最低严重值,才可以安排入住重症病房. 现在要求设计一个程序, ...
- 有了JSON.stringify(),处理json将变得更简单!!
之前处理json 需要拼接json字符串,但是,如果用上JSON.stringify()的话,忘了json语法以没关系了..... @{ ViewBag.Title = "GetStr&qu ...
- Windows Server 2008标准证书使用记录
Windows Server 2008标准证书使用记录 近期准备将单位的服务器全部升级到Windows Server 2008,但有一些“遗留”问题需要解决: (1)现在单位还有一台Windows ...