一、.net 页面导出为word
npoi可以导出为docx格式的word文档,具体怎么用表格,没有试过,给你一段导出的代码,你可以参考
using (DocX document = DocX.Create(Server.MapPath("~/Temp/ScoreResultDoc") + "/ScoreResultDoc.docx"))
{
Paragraph p = document.InsertParagraph();
// Append some text and add formatting.
p.Append("河北省信用档案\n")
.Font(new FontFamily("Times New Roman"))
.FontSize(24)
.Color(Color.Black)
.Bold();
p.Alignment = Alignment.center;
//p.Direction = Direction;
p.Append("记分告知单\n")
.Font(new FontFamily("Times New Roman"))
.FontSize(24)
.Color(Color.Black)
.Bold();
p.Alignment = Alignment.center;
Paragraph p1 = document.InsertParagraph();
//p1.Append(" ")
// .Font(new FontFamily("Times New Roman"))
// .FontSize(14)
// .Color(Color.Black)
// .Bold();
//float ff = 14.0f * 1.0f / 2.83f / 10.0f;
p1.IndentationFirstLine = f14;
p1.Append(businessName).UnderlineStyle(UnderlineStyle.singleLine)
.Font(new FontFamily("宋体"))
.FontSize(14)
.Color(Color.Black)
.Bold();
p1.Alignment = Alignment.left;
p1.Append(": 编号:[ ]号")
.Font(new FontFamily("宋体"))
.FontSize(14);
p1.Alignment = Alignment.left;
p1.SetLineSpacing(LineSpacingType.Line, 1.5f);
document.Save();
}
二、.net winfrom程序怎么把一个页面导出存为word文档
供参考: Response.Clear(); Response.Buffer= true; Response.AppendHeader("Content-Disposition","attachment;filename="+DateTime.Now.ToString("yyyyMMdd")+".xls"); Response.ContentEncoding=System.Text.Encoding.UTF8; Response.ContentType = "vnd.ms-excel/msword"; this.EnableViewState = false;。
三、请教.net生成word文档的方法
注意引用using Microsoft.Office.Interop.Word;
创建代码如下:
Microsoft.Office.Interop.Word.Application myWordApp = new Microsoft.Office.Interop.Word.Application();//初始化wordApp组件
Document myWordDoc;//创建文档对象
Object Nothing = System.Reflection.Missing.Value;
myWordDoc = myWordApp.Documents.Add(ref Nothing, ref Nothing, ref Nothing, ref Nothing);
//中间可以向word中插入文字、图片、表格等内容
myWordDoc.SaveAs2(docPath, null, ref Nothing);//保存word文档
//关闭WordDoc文档对象
myWordDoc.Close(ref Nothing, ref Nothing, ref Nothing);
//关闭WordApp组件对象
myWordApp.Quit(ref Nothing, ref Nothing, ref Nothing);
四、在.NET中怎样实现word的文档导入导出
npoi可以导出为docx格式的word文档,具体怎么用表格,没有试过,给你一段导出的代码,你可以参考using(DocXdocument=DocX。
Create(Server。MapPath("~/Temp/ScoreResultDoc")+"/ScoreResultDoc。
docx")){Paragraphp=document。InsertParagraph();//Appendsometextandaddformatting。
p。Append("河北省信用档案 ")。
Font(newFontFamily("TimesNewRoman"))。 FontSize(24)。
Color(Color。Black)。
Bold();p。Alignment=Alignment。
center;//p。Direction=Direction;p。
Append("记分告知单 ")。Font(newFontFamily("TimesNewRoman"))。
FontSize(24)。Color(Color。
Black)。Bold();p。
Alignment=Alignment。center;Paragraphp1=document。
InsertParagraph();//p1。Append("")//。
Font(newFontFamily("TimesNewRoman"))//。FontSize(14)//。
Color(Color。Black)//。
Bold();//floatff=14。0f*1。
0f/2。83f/10。
0f;p1。IndentationFirstLine=f14;p1。
Append(businessName)。UnderlineStyle(UnderlineStyle。
singleLine)。Font(newFontFamily("宋体"))。
FontSize(14)。Color(Color。
Black)。 Bold();p1。
Alignment=Alignment。left;p1。
Append(":编号:[]号")。Font(newFontFamily("宋体"))。
FontSize(14);p1。Alignment=Alignment。
left;p1。 SetLineSpacing(LineSpacingType。
Line,1。5f);document。
Save();}。
五、.net怎么把整个页面导出excel
绑定数据后
System.Web.HttpContext.Current.Response.Clear();
System.Web.HttpContext.Current.Response.Charset = "GB2312";
// System.Web.HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.UTF8;
// 添加头信息,为"文件下载/另存为"对话框指定默认文件名
System.Web.HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment; filename=myU.xls");
// 添加头信息,指定文件大小,让浏览器能够显示下载进度
// System.Web.HttpContext.Current.Response.AddHeader("Content-Length",sb.ToString());
// 指定返回的是一个不能被客户端读取的流,必须被下载
System.Web.HttpContext.Current.Response.ContentType = "application/ms-excel";
// 把文件流发送到客户端
System.Web.HttpContext.Current.Response.Write(sb.ToString());
// 停止页面的执行
System.Web.HttpContext.Current.Response.End();
六、我要用C#,NET 导出一个word文档
楼上的 你能不能改写下这个例子啊? 我这个只能导出字符 不能导出表格 string title = "个人信息"; object titleLengh = title.Length; string first = "\n 公司最近需要利用C#对项目进行编程,其" + "中存在一个功能就是可自动生成WORD文档,但一直以来都" + "找不到什么好办法,无奈之下,只有自已学着写一个了."; object firstLengh = first.Length; string second = "\n 如果能真正生成WORD文档的好处有:"; object secondLengh = second.Length; string third = "\n1、根据数据库信息自动生成文档;"; object thirdLengh = third.Length; string forth = "\n2、免去书写文档之苦;"; object forthLengh = forth.Length; string fifth = "\n3、可以通过邮件方式传出文档。
"; object fifthLengh = fifth.Length; object missing; object zero = 0; object c = 10; object one = 1; object two = 2; object tree = 3; object four = 4; object five = 5; object six = 6; object seven = 7; object eight = 8; object nine = 9; object ten = 10; Object Nothing = System.Reflection.Missing.Value; Microsoft.Office.Interop.Word.ApplicationClass wa = new Microsoft.Office.Interop.Word.ApplicationClass(); Microsoft.Office.Interop.Word.Document WordDoc = wa.Documents.Add(ref Nothing, ref Nothing, ref Nothing, ref Nothing); missing = System.Reflection.Missing.Value; wa.Visible = true; wa.Documents.Add(ref missing, ref missing, ref missing, ref missing); Microsoft.Office.Interop.Word.Range myRange = wa.ActiveDocument.Range(ref zero, ref zero); object r = myRange; Microsoft.Office.Interop.Word.Paragraph p = wa.ActiveDocument.Paragraphs.Add(ref r); p.Range.InsertBefore(title); //p.Range.Font.Size = 1; Microsoft.Office.Interop.Word.Range titleRange = wa.ActiveDocument.Range(ref zero, ref titleLengh); //titleRange.Font.Size = 1; titleRange.Font.Name = "幼圆"; titleRange.Font.Color = Microsoft.Office.Interop.Word.WdColor.wdColorBlue; //MessageBox.Show("NO.1"); //titleRange.Paragraphs.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphRight; Microsoft.Office.Interop.Word.Range firstR = wa.ActiveDocument.Paragraphs[1].Range;//.Item(2).Range; Microsoft.Office.Interop.Word.Table table = WordDoc.Tables.Add(titleRange, 3, 3, ref Nothing, ref Nothing); r = firstR; p = wa.ActiveDocument.Paragraphs.Add(ref r); firstR.Font.Size = 40; firstR.Paragraphs.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter;//在表格第一单元格中添加自定义的文字内容 table.Cell(1, 1).Range.Text = "lllll"; firstR.InsertAfter(first);//firstR.InsertParagraphAfter(); //firstR=wa.ActiveDocument.Paragraphs.Item(3).Range; firstR.InsertAfter(second); firstR.InsertAfter(third); firstR.InsertAfter(forth); firstR.InsertAfter(fifth); Context.Response.Write("成功");。
七、C#怎么导出word文档
net导出文件操作类 using System; using System.Web; namespace FLX.ComplexQuery { /**//// /// /// 数据存入word或execl文件 /// /// public class ExportData { 构造函数#region 构造函数 public ExportData() { // // TODO: 在此处添加构造函数逻辑 // } #endregion 导出页面或web控件方法#region 导出页面或web控件方法 /**//// /// 将Web控件或页面信息导出(不带文件名参数) /// /// 控件实例 /// 导出类型:Excel或Word public void ExportControl(System.Web.UI.Control source, string DocumentType) { //设置Http的头信息,编码格式 if (DocumentType == "Excel") { //Excel HttpContext.Current.Response.AppendHeader("Content-Disposition","attachment;filename="+ HttpUtility.UrlEncode("下载文件.xls",System.Text.Encoding.UTF8)); HttpContext.Current.Response.ContentType = "application/ms-excel"; } else if (DocumentType == "Word") { //Word HttpContext.Current.Response.AppendHeader("Content-Disposition","attachment;filename="+ HttpUtility.UrlEncode("下载文件.doc",System.Text.Encoding.UTF8)); HttpContext.Current.Response.ContentType = "application/ms-word"; } HttpContext.Current.Response.Charset = "UTF-8"; HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.UTF8; //关闭控件的视图状态 source.Page.EnableViewState =false; //初始化HtmlWriter System.IO.StringWriter writer = new System.IO.StringWriter() ; System.Web.UI.HtmlTextWriter htmlWriter = new System.Web.UI.HtmlTextWriter(writer); source.RenderControl(htmlWriter); //输出 HttpContext.Current.Response.Write(writer.ToString()); HttpContext.Current.Response.End(); } /**//// /// 将Web控件或页面信息导出(带文件名参数) /// /// 控件实例 /// 导出类型:Excel或Word /// 保存文件名 public void ExportControl(System.Web.UI.Control source, string DocumentType, string filename) { //设置Http的头信息,编码格式 if (DocumentType == "Excel") { //Excel HttpContext.Current.Response.AppendHeader("Content-Disposition","attachment;filename="+ HttpUtility.UrlEncode(filename+".xls",System.Text.Encoding.UTF8)); HttpContext.Current.Response.ContentType = "application/ms-excel"; } else if (DocumentType == "Word") { //Word HttpContext.Current.Response.AppendHeader("Content-Disposition","attachment;filename="+ HttpUtility.UrlEncode(filename+".doc",System.Text.Encoding.UTF8)); HttpContext.Current.Response.ContentType = "application/ms-word"; } HttpContext.Current.Response.Charset = "UTF-8"; HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.UTF8; //关闭控件的视图状态 source.Page.EnableViewState =false; //初始化HtmlWriter System.IO.StringWriter writer = new System.IO.StringWriter() ; System.Web.UI.HtmlTextWriter htmlWriter = new System.Web.UI.HtmlTextWriter(writer); source.RenderControl(htmlWriter); //输出 HttpContext.Current.Response.Write(writer.ToString()); HttpContext.Current.Response.End(); } #endregion 调用说明#region 调用说明 //方法ExportControl(System.Web.UI.Control source, string DocumentType,string filename)中 //第一个参数source表示导出的页面或控件名,当为datagrid或dataList控件时,在导出Excel/word文件时,必须把控件的分页、排序等属性去除并重新绑定, //第二个参数DocumentType表示导出的文件类型word或excel //第三个参数filename表示需要导出的文件所取的文件名 //调用方法: //ExportData export=new ExportData(); //export.ExportControl(this, "Word","testfilename");//当为this时表示当前页面 //这是将整个页面导出为Word,并命名为testfilename #endregion }}。
转载请注明出处51数据库 » net导出word行数