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 ...
随机推荐
- nodejs爬虫
前言 几个月之前,有同事找我要PHP CI框架写的OA系统.他跟我说,他需要学习PHP CI框架,我建议他学习大牛写的国产优秀框架QeePHP. 我上QeePHP官网,发现官方网站打不开了,GOOGL ...
- HBase的二级索引,以及phoenix的安装(需再做一次)
一:HBase的二级索引 1.讲解 uid+ts 11111_20161126111111:查询某一uid的某一个时间段内的数据 查询某一时间段内所有用户的数据:按照时间 索引表 rowkey:ts+ ...
- 【Java 进阶篇】【第二课】异常处理
概念 异常处理的存在是为了: 允许程序员跳过无法处理的问题,继续开发后续的工作,或根据异常做出更加聪明的处理方式. Java中存在一类对象叫“异常对象”. 当异常情况发生时,就会暗战预先的设定,抛 ...
- zepto源码--fragment--学习笔记
文档片段fragment函数默认传递三个参数: html文档片段字符串 name标签 properties额外添加的属性 函数内部实现过程: var dom, nodes, container; 中间 ...
- EChars学习-1
Echarts,编写来自Enterprise Charts,商业级数据图表,是百度的一个开源的数据可视化工具 官网地址:http://echarts.baidu.com/ 一.引入Echarts &l ...
- MVC4怎么设置@Html.TextBoxFor这样的输入框的css样式
在传统webForm中,输入框的这样的: <input id="userName" name="userName" type="text&quo ...
- https://www.zhihu.com/question/52020960#answer-47024535
https://www.zhihu.com/question/52020960#answer-47024535
- RHEL6解决无法使用YUM源问题
RHEL的YUM源需要注册用户才能更新使用,由于CentOS和RHEL基本没有区别,并且CentOS已经被REHL收购.所以将RHEL的YUM源替换为CentOS即可.问题如下:[root@bogon ...
- 加州wonders教材扫盲
加州语文教材主要包含以下内容: 1.主教材Reading/Writing Workshop(读写研讨) 2.拓展教材Literature Anthology(文学选集) 3.延伸阅读材料Leveled ...
- ubuntu 更新 rtl8192cu 驱动
ubuntu 更新 rtl8192cu 驱动 手上有个 tplink wr823n 的 usb 无线网卡,在 windows 下工作正常,但在 linux 上的比较差,速度没有 windows 上的快 ...