用户登录
用户注册

分享至

导出word代码

  • 作者: 挂念DJQ-miss
  • 来源: 51数据库
  • 2020-04-21

1.如何生成word文档的源码

/// public class WebForm1 : System.Web.UI.Page{protected System.Web.UI.WebControls.TextBox SaveAs; protected System.Web.UI.WebControls.Label Label2; protected System.Web.UI.WebControls.Label Label1; protected System.Web.UI.WebControls.Label result; protected System.Web.UI.WebControls.Button Button1; protected System.Web.UI.WebControls.TextBox wordText; private void Page_Load(object sender, System.EventArgs e){// 在此处放置用户代码以初始化页面}#region Web 窗体设计器生成的代码 override protected void OnInit(EventArgs e){//// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。

//InitializeComponent(); base.OnInit(e);} ///

/// 设计器支持所需的方法 - 不要使用代码编辑器修改 /// 此方法的内容。 /// private void InitializeComponent(){this.Button1.Click += new System.EventHandler(this.Button1_Click); this.Load += new System.EventHandler(this.Page_Load);}#endregionprivate void Button1_Click(object sender, System.EventArgs e){Object Nothing=System.Reflection.Missing.Value; object filename=@SaveAs.Text; Word.Application WordApp=new Word.ApplicationClass(); Word.Document WordDoc=WordApp.Documents.Add(ref Nothing,ref Nothing,ref Nothing,ref Nothing); Word.Table table=WordDoc.Tables.Add(WordApp.Selection.Range,1,1,ref Nothing,ref Nothing); table.Cell(1,1).Range.Text=wordText.Text; WordDoc.Paragraphs.Last.Range.Text="Wellcome To Aspxcn.Com"; WordDoc.SaveAs(ref filename,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.Close(ref Nothing, ref Nothing, ref Nothing); WordApp.Quit(ref Nothing, ref Nothing, ref Nothing); result.Text="文档路径:"+SaveAs.Text+"(点击链接查看)生成结果:成功!";}} }在web.config中要设置权限。

2.html导出word有哪些好的解决方案

1、实现富文本中样式代码的分离;

2、保留CSS样式;

其实以上两个步骤是相互矛盾的处理过程,无法通过Jacob或POI组件加正则表达式过滤解决,于是进行了以下步骤的实验:

1、首先创建了一个空白word文档,格式(office 2003格式或office 2007格式)不限;

2、将word格式保存为html格式,通过Edit Plus打开,发现代码中使用了office的命名空间,同时使用了office命名空间的标签定义了CSS样式,自己测试了一下,将生成的html文件头和尾拷贝出来:代码如下:

以上HTML头是office的命名空间定义。

3、将使用富文本代码粘贴到红色标识的中,并以doc或docx格式保存文件;

4、大功告成,打开文件时,Word将会以“Web版视图”完美显示了富文本样式,成功解决了富文本代码中样式代码,并同时保留了格式;

目前研究的仅能保存文字,未处理有图片的代码,朋友们可以再研究一下带图片的富文本代码的转换;

3.求个JS控制导出WORD的代码(将多个word附件整合成一个并打印出

Set objWord = CreateObject("Word.Application")

Set objWord = CreateObject("Word.Application") objWord.Caption = "Test Caption" objWord.Visible = True Set objDoc = objWord.Documents.Add() Set objSelection = objWord.Selection objSelection.Font.Name = "Arial" objSelection.Font.Size = "18" objSelection.TypeText "Network Adapter Report" objSelection.TypeParagraph() Next objDoc.SaveAs("C:\Scripts\Word\testdoc.doc") objWord.Quit

4.excel怎样导出word为可编辑模式

方法如下:

1、首先,打开媒介工具“记事本”,将word文件里需要导入的数据,复制粘贴到记事本当中,然后保存成为txt文件,本例中将txt文件取名为“1.txt”。

2、打开excel表格,点击“数据”选项卡,在“获取外部数据”当中,找到“自文本”。

3、点击“自文本”,弹出下一窗口,选择刚才保存的名为1的txt类型文件,点击“导入”。因“自文本”方式数据导入默认的只有三种文件类型txt、csv、prn,所以需要事先将word转变为txt。

4、弹出文本导入对话框,选择默认的固定宽度,意思就是数据与单元格一一对应。如果选择分隔符号,则导入的所有数据将会在一个单元格当中,接着,点击下一步。

5、设置分行线,其实就是导入数据列数的控制,单击鼠标,可以在任意位置增加分行线。双击任意分行线,就会删除。完成设定后,点击下一步。

6、设置输出数据的格式,一般不需要进行任何设置,选择常规即可,点击“完成”。

7、导入完成。

转载请注明出处51数据库 » 导出word代码

软件
前端设计
程序设计
Java相关