[转载].Net将数据导出Word
来源:互联网 发布:海贼王周边 淘宝 编辑:程序博客网 时间:2024/06/11 12:50
protected void Button2_Click(object sender, EventArgs e)
{
Test();
}
private void Test()
{
Object nothing = System.Reflection.Missing.Value;
//获取Word文档保存路径
object fileName = System.Web.HttpRuntime.AppDomainAppPath +"wj.doc";
//创建一个名为WordApp的组件对象
Word.ApplicationClass WordApp = new Word.ApplicationClass();
//创建一个名为WordDoc的文档对象
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 = "在表格第一单元格中添加自定义的文字内容,如:我我我我我";
//在文档空白地方添加文字内容
WordDoc.Paragraphs.Last.Range.Bold = 72;
WordApp.Visible = true;
WordDoc.Activate();
#region 标题
WordApp.Selection.Font.Size = 15;
WordApp.Selection.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter; // 居中
WordApp.Selection.Font.Bold = 1; // 黑体
WordApp.Selection.TypeText("我是标题");
#endregion
#region 时间和来源
WordApp.Selection.TypeParagraph();
WordApp.Selection.Font.Size = 10;
WordApp.Selection.Font.Bold = 0; // 取消黑体
WordApp.Selection.TypeText("发布时间:" + "我是时间" + " 来源:" + "我是文件来源");
#endregion
#region 摘要
WordApp.Selection.TypeParagraph();
WordApp.Selection.TypeParagraph();
WordApp.Selection.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphLeft; // 居左
WordApp.Selection.TypeText("摘要:");
WordApp.Selection.TypeParagraph();
//WordApp.Selection.ParagraphFormat.CharacterUnitFirstLineIndent = 2.0f; //首行缩进2个字符
WordApp.Selection.TypeText(" " + "我是内容摘要");
#endregion
#region 内容
WordApp.Selection.TypeParagraph();
WordApp.Selection.TypeParagraph();
WordApp.Selection.TypeText("内容:");
string strPageContent = "我是内容";
//将一个<br>变成两个<br>
//strPageContent = Regex.Replace(strPageContent, "(<br>[/s]*)+", "<br /><br />");
//将所有标签去掉,只剩下rn
strPageContent = Regex.Replace(strPageContent, @"<[^>]+/?>|</[^>]+>", "", RegexOptions.IgnoreCase);
string[] strContents = strPageContent.Split(new string[] { "rn" }, StringSplitOptions.RemoveEmptyEntries);
foreach (string strContent in strContents)
{
WordApp.Selection.TypeParagraph();
WordApp.Selection.TypeText(" " + strContent);
}
#endregion
//WordDoc.Paragraphs.Last.Range.Text += SaveShowInfo.PictureUrl;
//将WordDoc文档对象的内容保存为DOC文档
WordDoc.SaveAs(ref fileName, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing);
//关闭WordDoc文档对象
WordDoc.Close(ref nothing, ref nothing, ref nothing);
//关闭WordApp组件对象
WordApp.Quit(ref nothing, ref nothing, ref nothing);
//返回结果
//lblMsg.Text = "文档路径:<a href='/c:/111.doc'>c:/111.doc</a>(点击链接查看)<br>生成结果:成功!";
//使导出文件清除特殊符号
//string outFileName ;
//outFileName = outFileName.Replace("", " ");
//outFileName = outFileName.Replace(":", " ");
//outFileName = outFileName.Replace("*", " ");
//outFileName = outFileName.Replace("?", " ");
//outFileName = outFileName.Replace(""", " ");
//outFileName = outFileName.Replace("<", " ");
//outFileName = outFileName.Replace(">", " ");
//outFileName = outFileName.Replace("|", " ");
//Response.WriteFile(outFileName + ".doc",System.Web.HttpRuntime.AppDomainAppPath + "/XMLFiles/EduceWordFiles/" + this.Context.User.Identity.Name + ".doc",1024000);
}
- [转载].Net将数据导出Word
- .Net将数据导出Word
- ASP.NET(C#)将数据导出到Word或Excel
- 将gridview数据导出到word
- 将DBGrid中的数据导出到Word
- 在.NET环境下将报表数据导出EXCEL和WORD
- 在.NET环境下将报表数据导出EXCEL和WORD
- 将ASP.NET页面内的数据导出到Excel 或 Word中
- 将ASP.NET页面内的数据导出到Excel或Word中
- 将ASP.NET页面内的数据导出到Excel或Word中
- 将ASP.NET页面内地数据导出到Excel 或 Word里面
- 黑马程序员之ASP.NET学习笔记:将数据导出到Word或Excel
- asp.net数据导出到word
- asp.net数据导出到word
- 在.NET环境下将报表导出EXCEL和WORD
- 在.NET环境下将报表导出EXCEL和WORD
- 在.NET环境下将报表导出Excel和Word
- 在.NET环境下将报表导出Excel和Word
- NPOI中文技术文档网站
- 从store中获取数据
- 敢问路在何方——项目经理
- 努力啊努力~
- BUIW系列笔记之BUIW基础(一)
- [转载].Net将数据导出Word
- http协议学习 - 深入了解篇
- bW 笔记
- 【操作系统】linux--NFS驱动服务启动方法
- Oracle表连接
- Wily EM Server进程异常终止,日志记录license过期
- explode() 字符串分割函数 用法详解
- 煜邦电力实习总结
- asp.net中的服务器端控件 textbox 设为只读属性后无法获取 javascript给其赋的值