asp.net中读取word文档的内容
操作WORD配置说明引入:Word的对象库文件“MSWORD.OLB”(word 2000为MSWORD9.OLB) 1.运行Dcomcnfg.exe 2.组件服务――计算机――我的电脑――DCOM配置――找到microsoft word 文档 3.点击属性 4.选择“安全性” 5.选定“使用自定义访问权限”和“使用自定义启动权限” 6.分别编辑权限,添加Everyone(ASPNET,VS Developers,Debugger User) 7.选择“身份标识”,在选定“交互式用户” 即可 8.在Web.config里加
(如图一) 二、引用Word对象库文件 要操作Word,我们就需要Word的对象库文件“MSWORD.OLB”(word 2000为MSWORD9.OLB),通常安装了Office Word后,你就可以在office安装目录的Office10文件夹下面找到这个文件,当我们将这个文件引入到项目后,我们就可以在源码中使用各种操作函数来操作Word。具体做法是打开菜单栏中的项目>添加引用>浏览,在打开的“选择组件”对话框中找到MSWORD.OLB后按确定即可引入此对象库文件,vs.net将会自动将库文件转化为DLL组件,这样我们只要在源码中创建该组件对象即可达到操作Word的目的!三、Webform1.aspx.cs代码 完成添加引用后,MSWORD.OLB已经转化为相关DLL文件并放置于项目的BIN目录下了,这样我们只需在源码中创建该对象,并使用word库文件内置的操作函数即可轻松实现操作Word,Webform1.aspx.cs源码如下:using System; using System.Collections; using System.ComponentModel; using System.Data; using System.Drawing; using System.Web; using System.Web.SessionState; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.HtmlControls; namespace word {/// /// ///
如何将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。
如何用ASP读取word文档中的内容(表格+文字)然后写入数据库-百度
一改不是asp读取把,asp一般只负责做前台界面,后台处理需要其他语言,如C语言,C++,java等。
不知道你用的哪种语言。下面这一段代码是打开word的,你可以参考一下<% response.ContentType="application/msword" Const adTypeBinary = 1 Dim strFilePath strFilePath = "E:\website\test\doc.doc" Set objStream = Server.CreateObject("ADODB.Stream") objStream.Open objStream.Type = adTypeBinary objStream.LoadFromFile strFilePath Response.BinaryWrite objStream.Read objStream.Close Set objStream = Nothing %>。
ASP.NET读取word文档并在ASPX网页中显示,您解决了吗?能不能告
string path = "Word/" + model.vc_Word;//文档路径
using (Package package = Package.Open(Server.MapPath(path)))
{
Uri docxUri = new Uri("/word/document.xml", UriKind.Relative);
PackagePart docxPart = package.GetPart(docxUri);
XmlDocument docxXmlDocument = new XmlDocument();
docxXmlDocument.Load(docxPart.GetStream());
div_content.InnerHtml = docxXmlDocument.InnerText.ToString();//显示
}
我也在研究这个问题,你试试
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我
是否可以解决您的问题?
如何将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;="">
转载请注明出处51数据库 » asp.networdset_sty