1.请问asp.net如何将整个页面或部分页面导出到word
//EnableEventValidation="false" //页面上的设定 Response.ContentType = "application/ms-word";//指定到word Response.AddHeader("Content-Disposition", "inline;filename=test.doc"); StringBuilder sb = new StringBuilder();//没用上 StringWriter sw = new StringWriter(sb); HtmlTextWriter hw = new HtmlTextWriter(sw); sb.Append("");//没用上 pnlToWord.RenderControl(hw);//指定一个区域pnlToWord是Panel控件 //Page.RenderControl(hw);//整个页面 Response.Write(sw.ToString()); Response.End();。
2..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();
}
3.asp.net如何打印网页,将网页导出为word
你用第三方类库很容易实现,下面这个例子里面是用Spire.Doc.dll来实现的HTML转Word的方法,你可以参考一下:
using System;
using Spire.Doc;
using Spire.Doc.Documents;
namespace Html2Doc
{
class Program
{
static void Main(string[] args)
{
Document document = new Document();
document.LoadFromFile(@"D:\test.html",FileFormat.Html,XHTMLValidationType.None);
document.SaveToFile("test.doc", FileFormat.Doc);
}
}
}详细内容可以参阅原教程的内容网页链接
4.asp.net导出word
public void Download()
{
Random rd = new Random();
string fileName = DateTime.Now.ToString("yyyyMMddhhmm") + rd.Next() + ".doc";
//存储路径
string path = Server.MapPath(fileName);
//创建字符输出流
StreamWriter sw = new StreamWriter(path, true, System.Text.UnicodeEncoding.UTF8);
//需要导出的内容
string str = "<html><head><title>;无标题文档</title></head><body>;这里放从数据库导出的word文档内容</body></html>";
//写入
sw.Write(str);
sw.Close();
Response.Clear();
Response.Buffer = true;
this.EnableViewState = false;
Response.Charset = "utf-8";
Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8));
Response.ContentType = "application/octet-stream";
Response.WriteFile(path);
Response.Flush();
Response.Close();
Response.End();
}
标准word文档的格式微软暂未公布,由此我们可将需要导出的内容转为标准HTML文件储存,后缀名为.doc
也可以将要导出内容转为标准XML格式存储,改后缀为.doc
具体格式随意新建个word文档,输入内容,另存为.XML可见
另外一种导出方式为word导出标准格式,服务器需要安装Microsoft Office word,需要预先设置好一个word文档并在要插入内容的地方设置书签做为模版,导出word文档时需要先遍历模版文件中的所有书签,然后给书签赋值就能实现导出数据了
还有不懂的可以直接百度HI我
是否可以解决您的问题?
5.如何将Asp.net页面导入到World里
有图片就没试过哦!下面是关键性代码,但只是生成文字!希望对您有用添加引用:using Microsoft.Office.Interop.Word; //============================ private unsafe void ThreadWork() { try { this.SetBtnDisable(); string str = "数据库名:" + this.dbname; int count = this.listTable2.Items.Count; this.SetprogressBar1Max(count); this.SetprogressBar1Val(1); this.SetlblStatuText("0"); object template = Missing.Value; object obj3 = @"\endofdoc"; Microsoft.Office.Interop.Word._Application application = new Microsoft.Office.Interop.Word.ApplicationClass(); application.Visible = false; Microsoft.Office.Interop.Word._Document document = application.Documents.Add(ref template, ref template, ref template, ref template); application.ActiveWindow.View.Type = Microsoft.Office.Interop.Word.WdViewType.wdOutlineView; application.ActiveWindow.View.SeekView = Microsoft.Office.Interop.Word.WdSeekView.wdSeekPrimaryHeader; application.ActiveWindow.ActivePane.Selection.InsertAfter("导出到Word"); application.Selection.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphRight; application.ActiveWindow.View.SeekView = Microsoft.Office.Interop.Word.WdSeekView.wdSeekMainDocument; Microsoft.Office.Interop.Word.Paragraph paragraph = document.Content.Paragraphs.Add(ref template); paragraph.Range.Text = str; paragraph.Range.Font.Bold = 1; paragraph.Range.Font.Name = "宋体"; paragraph.Range.Font.Size = 12f; paragraph.Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter; paragraph.Format.SpaceAfter = 5f; paragraph.Range.InsertParagraphAfter(); for (int i = 0; i columnInfoList = this.dbobj.GetColumnInfoList(this.dbname, tableName); int num3 = columnInfoList.Count; if ((columnInfoList != null) && (columnInfoList.Count > 0)) { object obj4 = document.Bookmarks.get_Item(ref obj3).Range; Microsoft.Office.Interop.Word.Paragraph paragraph2 = document.Content.Paragraphs.Add(ref obj4); paragraph2.Range.Text = str3; paragraph2.Range.Font.Bold = 1; paragraph2.Range.Font.Name = "宋体"; paragraph2.Range.Font.Size = 10f; paragraph2.Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter; paragraph2.Format.SpaceBefore = 15f; paragraph2.Format.SpaceAfter = 1f; paragraph2.Range.InsertParagraphAfter(); obj4 = document.Bookmarks.get_Item(ref obj3).Range; Microsoft.Office.Interop.Word.Paragraph paragraph3 = document.Content.Paragraphs.Add(ref obj4); paragraph3.Range.Text = ""; paragraph3.Range.Font.Bold = 0; paragraph3.Range.Font.Name = "宋体"; paragraph3.Range.Font.Size = 9f; paragraph3.Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter; paragraph3.Format.SpaceBefore = 1f; paragraph3.Format.SpaceAfter = 1f; paragraph3.Range.InsertParagraphAfter(); Microsoft.Office.Interop.Word.Range range = document.Bookmarks.get_Item(ref obj3).Range; Microsoft.Office.Interop.Word.Table table = document.Tables.Add(range, num3 + 1, 10, ref template, ref template); table.Range.Font.Name = "宋体"; table.Range.Font.Size = 9f; table.Borders.Enable = 1; table.Rows.Height = 10f; table.AllowAutoFit = true; table.Cell(1, 1).Range.Text = "序号"; table.Cell(1, 2).Range.Text = "列名"; table.Cell(1, 3).Range.Text = "数据类型"; table.Cell(1, 4).Range.Text = "长度"; table.Cell(1, 5).Range.Text = "小数位"; table.Cell(1, 6).Range.Text = "标识"; table.Cell(1, 7).Range.Text = "主键"; table.Cell(1, 8).Range.Text = "允许空"; table.Cell(1, 9).Range.Text = "默认值"; table.Cell(1, 10).Range.Text = "说明"; table.Columns[1].Width = 33f; table.Columns[3].Width = 60f; table.Columns[4].Width = 33f; table.Columns[5].Width = 43f; table.Columns[6].Width = 33f; table.Columns[7].Width = 33f; table.Columns[8].Width = 43f; for (int j = 0; j 评论0 0 0。
6.如何将一个asp的页面用word输出出来
你安装完vs2005 tool for office后,在新建项目就有word模板了。
你就可以对word进行操作了。
补充: 首先引入类库,Microsoft.Office.Interop.Word,然后进行编程。代码如下: using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using Microsoft.Office.Interop.Word; namespace WordTest { public partial class Form1 : Form { object strFileName; Object Nothing; Microsoft.Office.Interop.Word.Application myWordApp = new Microsoft.Office.Interop.Word.ApplicationClass(); Document myWordDoc; string strContent = ""; public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { createWord(); //openWord(); } private void createWord() { strFileName = System.Windows.Forms.Application.StartupPath "test.doc"; if (System.IO.File.Exists((string)strFileName)) System.IO.File.Delete((string)strFileName); Object Nothing = System.Reflection.Missing.Value; myWordDoc = myWordApp.Documents.Add(ref Nothing, ref Nothing, ref Nothing, ref Nothing); #region 将数据库中读取得数据写入到word文件中 strContent = "你好\n\n\r"; myWordDoc.Paragraphs.Last.Range.Text = strContent; strContent = "这是测试程序"; myWordDoc.Paragraphs.Last.Range.Text = strContent; #endregion //将WordDoc文档对象的内容保存为DOC文档 myWordDoc.SaveAs(ref strFileName, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing); //关闭WordDoc文档对象 myWordDoc.Close(ref Nothing, ref Nothing, ref Nothing); //关闭WordApp组件对象 myWordApp.Quit(ref Nothing, ref Nothing, ref Nothing); this.richTextBox1.Text = strFileName "\r\n" "创建成功"; } private void openWord() { fontDialog1.ShowDialog(); System.Drawing.Font font = fontDialog1.Font; object filepath = "D:\\asp.docx"; object oMissing = System.Reflection.Missing.Value; myWordDoc = myWordApp.Documents.Open(ref filepath, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing); myWordDoc.Content.Font.Size = font.Size; myWordDoc.Content.Font.Name = font.Name; myWordDoc.Save(); richTextBox1.Text = myWordDoc.Content.Text; myWordDoc.Close(ref oMissing, ref oMissing, ref oMissing); myWordApp.Quit(ref oMissing, ref oMissing, ref oMissing); } }。
7..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;。
8.如何将Asp.net页面导入到World里
有图片就没试过哦!下面是关键性代码,但只是生成文字!希望对您有用添加引用:using Microsoft.Office.Interop.Word; //============================ private unsafe void ThreadWork() { try { this.SetBtnDisable(); string str = "数据库名:" + this.dbname; int count = this.listTable2.Items.Count; this.SetprogressBar1Max(count); this.SetprogressBar1Val(1); this.SetlblStatuText("0"); object template = Missing.Value; object obj3 = @"\endofdoc"; Microsoft.Office.Interop.Word._Application application = new Microsoft.Office.Interop.Word.ApplicationClass(); application.Visible = false; Microsoft.Office.Interop.Word._Document document = application.Documents.Add(ref template, ref template, ref template, ref template); application.ActiveWindow.View.Type = Microsoft.Office.Interop.Word.WdViewType.wdOutlineView; application.ActiveWindow.View.SeekView = Microsoft.Office.Interop.Word.WdSeekView.wdSeekPrimaryHeader; application.ActiveWindow.ActivePane.Selection.InsertAfter("导出到Word"); application.Selection.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphRight; application.ActiveWindow.View.SeekView = Microsoft.Office.Interop.Word.WdSeekView.wdSeekMainDocument; Microsoft.Office.Interop.Word.Paragraph paragraph = document.Content.Paragraphs.Add(ref template); paragraph.Range.Text = str; paragraph.Range.Font.Bold = 1; paragraph.Range.Font.Name = "宋体"; paragraph.Range.Font.Size = 12f; paragraph.Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter; paragraph.Format.SpaceAfter = 5f; paragraph.Range.InsertParagraphAfter(); for (int i = 0; i < count;="" i++)="" {="" string="" tablename="this.listTable2.Items[i].ToString();" string="" str3="表名:" +="" tablename;="">
dot模版文件中插入标签。对应读入数据中的值。问题是如何动态通过数据内容改变word生成的字体或样子。 //第一步生成word文档 //定义书签变量 object Name = "Name";//项目名 object BidNo = "BidNo";//招标编号 //第二步 读取数据,填充数据集 //SqlDataReader dr = XXXXX;//读取出来的数据集 //第三步 给书签赋值 docFile.Bookmarks.get_Item(ref Name).Range.Text = ds.Tables[0].Rows[0][2].ToString(); docFile.Bookmarks.get_Item(ref BidNo).Range.Text = ds.Tables[0].Rows[0][3].ToString(); appWord.Selection.TypeParagraph();//换行 appWord.Selection.Font.Bold = 0;//正常体 appWord.Selection.Font.Color = word.WdColor.wdColorBlack;//黑色字体 appWord.Selection.ParagraphFormat.Alignment = word.WdParagraphAlignment.wdAlignParagraphJustify;//两端对齐 转载请注明出处51数据库 » asp.net页面导出word9.asp.net实现将数据输出到word
格里芬给力芬