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 ...
随机推荐
- 【Android测试】【第六节】Monkey——认识和使用
◆版权声明:本文出自carter_dream的博客,转载必须注明出处. 转载请注明出处:http://www.cnblogs.com/by-dream/p/4688880.html 自动化工具 接触安 ...
- MongoDB的find用法
0.查询符合条件数据的总条数 如:db.list名.find({条件}).count(); 1.返回指定的键值:db.list.find({条件},{name:"任意值",age: ...
- C#中Dynamic关键字
dynamic关键字和动态语言运行时(DLR)是.Net 4.0中新增的功能. 什么是"动态"? 编程语言有时可以划分为静态类型化语言和动态类型化语言.C#和Java经常被认为是静 ...
- 20145211 《Java程序设计》实验报告五————Java网络编程及安全实验报告
实验内容 1.掌握Socket程序的编写: 掌握密码技术的使用: 设计安全传输系统. 实验步骤 这一部分是与我的partner合作的,详见他的博客- [20145326 <Java程序设计> ...
- 【转】Android各种Adapter的用法
转自:http://my.oschina.net/u/658933/blog/372151 Android各种Adapter的用法 发表于5个月前(2015-01-27 10:56) 阅读(143 ...
- ajax 调用asp.net后台方法
ajax 调用asp.net后台方法 这种做法有好几种,如调用xx.asxh 页面,或者直接调用xx.aspx也面,在page_Load中进行一些判断然后调用后面的其他方法, 或者你可以直接调用we ...
- java中String.valueOf()和toString()方法的区别
http://www.ztyhome.com/android-tostring-string-valueof-diff/
- Python线程指南
本文介绍了Python对于线程的支持,包括“学会”多线程编程需要掌握的基础以及Python两个线程标准库的完整介绍及使用示例. 注意:本文基于Python2.4完成,:如果看到不明白的词汇请记得百度谷 ...
- keepalived对nginx高可用演练脚本
keepalived对nginx高可用演练脚本 参考文章:http://deidara.blog.51cto.com/400447/302402/ .安装nginx.keepalived.epel-r ...
- 使用APICloud写“华为商城”(前端+后端) 无保留提供源码
第一次分享了一个可以算是完整的手机商城项目,之前从别人的源码中得到了许多帮助,现在入门了也希望能帮一下大家. 注: 前端,后端都有 数据用的是APICloud的MCM,所以小心流量. 目前只有Andr ...