Csharp: Create Excel Workbook or word from Template File using aspose.Word 14.5 and aspose.Cell 8.1
来源:互联网 发布:朔州seo快速优化软件 编辑:程序博客网 时间:2024/06/15 09:16
winform:
/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnGenWord_Click(object sender, EventArgs e) { Dictionary<string, string> dictSource = new Dictionary<string, string>(); dictSource.Add("NO", "T0001"); dictSource.Add("INDUSTRY", "捷为工作室"); dictSource.Add("NAME", "塗聚文"); string templateFile =("Templates/Templates.doc"); Aspose.Words.Document doc = new Aspose.Words.Document(templateFile); //使用文本方式替换 foreach (string name in dictSource.Keys) { doc.Range.Replace(name, dictSource[name], true, true); } #region 使用书签替换模式 Aspose.Words.Bookmark bookmark = doc.Range.Bookmarks["SEX"]; if (bookmark != null) { bookmark.Text = "男"; } bookmark = doc.Range.Bookmarks["TEL"]; if (bookmark != null) { bookmark.Text = "13824350518*"; } #endregion doc.Save("testAdvice"+DateTime.Now.ToString("yyyyMMddHHmmssfff")+".docx",Aspose.Words.SaveFormat.Docx); } /// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnGenExcel_Click(object sender, EventArgs e) { Dictionary<string, string> dictSource = new Dictionary<string, string>(); dictSource.Add("NO", "T0001"); dictSource.Add("INDUSTRY", "捷为工作室"); dictSource.Add("NAME", "塗聚文"); string templateFile = ("Templates/Templates.xls"); WorkbookDesigner designer = new WorkbookDesigner(); //designer.Workbook.FileName=templateFile; Aspose.Cells.Workbook work = new Workbook(templateFile); designer.Workbook.Copy(work); Aspose.Cells.Worksheet worksheet = designer.Workbook.Worksheets[0]; worksheet.Name = "geovindu"; //使用文本替换 foreach (string name in dictSource.Keys) { worksheet.Replace(name, dictSource[name]); } //使用绑定数据方式替换 designer.SetDataSource("SEX", "男"); designer.SetDataSource("TEL", "13824350518*"); designer.Process(); designer.Workbook.Save("testAdvice.xlsx",Aspose.Cells.SaveFormat.Xlsx); }
webform:
/// <summary> /// https://github.com/aspose-words/Aspose.Words-for-.NET /// https://asposewords.codeplex.com/ /// https://asposednn.codeplex.com/ /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnGenWord_Click(object sender, EventArgs e) { Dictionary<string, string> dictSource = new Dictionary<string, string>(); dictSource.Add("NO", "T0001"); dictSource.Add("INDUSTRY", "捷為工作室"); dictSource.Add("NAME", "涂聚文"); string templateFile = Server.MapPath("./Templates/Templates.doc"); Aspose.Words.Document doc = new Aspose.Words.Document(templateFile); //veb: 14.5 //使用文本方式替换 foreach (string name in dictSource.Keys) { doc.Range.Replace(name, dictSource[name], true, true); } #region 使用书签替换模式 Aspose.Words.Bookmark bookmark = doc.Range.Bookmarks["SEX"]; if (bookmark != null) { bookmark.Text = "男"; } //书签方式 bookmark = doc.Range.Bookmarks["TEL"]; if (bookmark != null) { bookmark.Text = "13824350518*"; } #endregion string savefile = Server.MapPath("./DuFile/geovindu.docx"); doc.Save(savefile, Aspose.Words.SaveFormat.Docx); Response.Clear(); Response.Buffer = true; //以字符流的形式下载文件 string fileName = "geovindu.docx"; //下載文件名稱 FileStream fs = new FileStream(savefile, FileMode.Open); byte[] bytes = new byte[(int)fs.Length]; fs.Read(bytes, 0, bytes.Length); fs.Close(); Response.ContentEncoding = System.Text.Encoding.UTF8; Response.HeaderEncoding = System.Text.Encoding.UTF8; Response.ContentType = "application/octet-stream"; //通知浏览器下载文件而不是打开 Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8)); //Response.AddHeader("Content-Length", fs.Length.ToString()); Response.BinaryWrite(bytes); Response.Flush(); Response.End(); } /// <summary> /// http://aspose.github.io/ /// https://github.com/asposemarketplace/Aspose_for_OpenXML /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void Button1_Click(object sender, EventArgs e) { Dictionary<string, string> dictSource = new Dictionary<string, string>(); dictSource.Add("NO", "T0002"); dictSource.Add("INDUSTRY", "捷為工作室"); dictSource.Add("NAME", "涂聚文"); string templateFile = Server.MapPath("./Templates/Templates.xls"); WorkbookDesigner designer = new WorkbookDesigner(); //Veb:8.1 Aspose.Cells.Workbook work = new Workbook(templateFile); designer.Workbook.Copy(work); //designer.Open(templateFile); Aspose.Cells.Worksheet worksheet = designer.Workbook.Worksheets[0]; worksheet.Name = "geovindu"; //使用文本替换 foreach (string name in dictSource.Keys) { worksheet.Replace(name, dictSource[name]); } //使用绑定数据方式替换 designer.SetDataSource("SEX", "男"); designer.SetDataSource("TEL", "13824350518*"); designer.Process(); string savefile = Server.MapPath("./DuFile/geovindu.xlsx"); designer.Workbook.Save(savefile, Aspose.Cells.SaveFormat.Xlsx); string fileName = "geovindu.xlsx"; //下載文件名稱 FileStream fs = new FileStream(savefile, FileMode.Open); byte[] bytes = new byte[(int)fs.Length]; fs.Read(bytes, 0, bytes.Length); fs.Close(); Response.ContentEncoding = System.Text.Encoding.UTF8; Response.HeaderEncoding = System.Text.Encoding.UTF8; Response.ContentType = "application/octet-stream"; //通知浏览器下载文件而不是打开 Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8)); //Response.AddHeader("Content-Length", fs.Length.ToString()); Response.BinaryWrite(bytes); Response.Flush(); Response.End(); }
0 0
- Csharp: Create Excel Workbook or word from Template File using aspose.Word 14.5 and aspose.Cell 8.1
- Csharp: Create Excel Workbook or word from Template File using aspose.Word 14.5 and aspose.Cell 8.1
- csharp:asp.net Importing or Exporting Data from Worksheets using aspose cell
- Extracting Table Data from Word Document using Aspose Words
- csharp: read excel using Aspose.Cells
- csharp: read excel using Aspose.Cells
- Aspose操作Excel和Word
- 利用Aspose.Word控件和Aspose.Cell控件,实现Word文档和Excel文档的模板化导出
- 利用Aspose.Word控件和Aspose.Cell控件,实现Word文档和Excel文档的模板化导出
- Aspose.Words操作word excel ppt说明
- Aspose.Cell 导出Excel
- aspose导出word
- C#Aspose生成word
- Aspose Word 导入
- ASPOSE.WORD操作
- Aspose Word使用
- Aspose.word设置页眉
- C#Aspose生成word
- 函数 HELP_VALUES_GET_WITH_TABLE 功能﹕弹出用户所需要的信息﹐让用户选择﹐并把选种的信息付给输入框﹐相当与建立起SEARCH HELP
- 本地事务和分布式事务工作实践
- 使用iframe如何通过url传参把数据从一个页面传到另一个页面(contentWindow)
- iOS 手机横屏后需要做一些处理
- ABBYY PDF Transformer+该怎么安装
- Csharp: Create Excel Workbook or word from Template File using aspose.Word 14.5 and aspose.Cell 8.1
- 自定义View自定义属性
- Csharp: Create Excel Workbook or word from Template File using aspose.Word 14.5 and aspose.Cell 8.1
- CGContextDrawPath CGContextFillPath渲染的几种方式比较分析讲解
- Java基础课程-数组-反射机制
- POJ 1386Play on Words
- Linux workqueue工作原理
- actorIM平台 Server平台搭建
- 栈的压入、弹出序列