http://www.sufeinet.com/plugin.php?id=keke_group

苏飞论坛

 找回密码
 马上注册

QQ登录

只需一步,快速开始

分布式系统框架(V2.0) 轻松承载百亿数据,千万流量!讨论专区 - 源码下载 - 官方教程

HttpHelper爬虫框架(V2.7-含.netcore) HttpHelper官方出品,爬虫框架讨论区 - 源码下载 - 在线测试和代码生成

HttpHelper爬虫类(V2.0) 开源的爬虫类,支持多种模式和属性 源码 - 代码生成器 - 讨论区 - 教程- 例子

查看: 8048|回复: 3

[Asp.Net] asp.net生成PPT、word问题

[复制链接]
发表于 2013-11-21 11:58:00 | 显示全部楼层 |阅读模式
之前页面上查询出来的数据要生成PPT,有PPT模板,现在要生成word,不知道改动大不大,代码太多了实在看不懂……飞哥帮帮忙,有个生成PPT的例子,我要改哪些地方去生成word
在线等……


1. 开通SVIP会员,免费下载本站所有源码,不限次数据,不限时间
2. 加官方QQ群,加官方微信群获取更多资源和帮助
3. 找站长苏飞做网站、商城、CRM、小程序、App、爬虫相关、项目外包等点这里
发表于 2013-11-21 12:54:42 | 显示全部楼层
稍等
回复

使用道具 举报

发表于 2013-11-21 12:56:31 | 显示全部楼层
[C#] 纯文本查看 复制代码
 context.Response.Clear();
        context.Response.AddHeader("Content-Disposition", "attachment;filename=" + 文件名);
        context.Response.ContentType = "application/octet-stream";
        context.Response.Write(“内容”);
        context.Response.End();

我是这样生成的,
 楼主| 发表于 2013-11-21 13:01:40 | 显示全部楼层
站长苏飞 发表于 2013-11-21 12:56
[C#] 纯文本查看 复制代码
 context.Response.Clear();
        context.Response.AddHeader("Content-Dis ...[/quote]
我贴段代码你看看

[mw_shl_code=html,true]protected void btnExport_Click(object sender, EventArgs e)
        {

            if (File.Exists(pptFileName))
            {
                pi = 0;
                string[] photopath = new string[16];
                DataSet ds = WQWuXiFO.getPPTimg("tblwxjsz", new string[] { "zd=2" }, "D4", Convert.ToDateTime(txtStartDate.Text.Trim()), "dt");
                photopath[0] = draw(ds, new string[] { "溶解氧", "D4" }, "dt", "samplename", "望亭自动站");
                ds = WQWuXiFO.getPPTimg("tblwqwuxi", new string[] { "samplename='虞义大桥'", "samplename='常熟枢纽闸内'", "samplename='张桥'", "samplename='大桥角新桥'", "samplename='望亭立交闸下'" }, "ph", Convert.ToDateTime(txtStartDate.Text.Trim()), "wqdate");
                photopath[1] = draw(ds, new string[] { "溶解氧", "PH" }, "wqdate", "samplename", "望虞河干流");
                ds = WQWuXiFO.getPPTimg("tblwqwuxi", new string[] { "samplename='大义桥'", "samplename='新师桥'", "samplename='鸟嘴渡'", "samplename='大坊桥'" }, "ph", Convert.ToDateTime(txtStartDate.Text.Trim()), "wqdate");
                photopath[2] = draw(ds, new string[] { "溶解氧", "PH" }, "wqdate", "samplename", "望虞河西岸支流");

                ds = WQWuXiFO.getPPTimg("tblwxjsz", new string[] { "zd=2" }, "D8", Convert.ToDateTime(txtStartDate.Text.Trim()), "dt");
                photopath[3] = draw(ds, new string[] { "高锰酸盐指数", "D8" }, "dt", "samplename", "望亭自动站");
                ds = WQWuXiFO.getPPTimg("tblwqwuxi", new string[] { "samplename='虞义大桥'", "samplename='常熟枢纽闸内'", "samplename='张桥'", "samplename='大桥角新桥'", "samplename='望亭立交闸下'" }, "CODmn", Convert.ToDateTime(txtStartDate.Text.Trim()), "wqdate");
                photopath[4] = draw(ds, new string[] { "高锰酸盐指数", "CODmn" }, "wqdate", "samplename", "望虞河干流");
                ds = WQWuXiFO.getPPTimg("tblwqwuxi", new string[] { "samplename='大义桥'", "samplename='新师桥'", "samplename='鸟嘴渡'", "samplename='大坊桥'" }, "CODmn", Convert.ToDateTime(txtStartDate.Text.Trim()), "wqdate");
                photopath[5] = draw(ds, new string[] { "高锰酸盐指数", "CODmn" }, "wqdate", "samplename", "望虞河西岸支流");

                ds = WQWuXiFO.getPPTimg("tblwxjsz", new string[] { "zd=2" }, "D12", Convert.ToDateTime(txtStartDate.Text.Trim()), "dt");
                photopath[6] = draw(ds, new string[] { "总磷", "D12" }, "dt", "samplename", "望亭自动站");
                ds = WQWuXiFO.getPPTimg("tblwqwuxi", new string[] { "samplename='虞义大桥'", "samplename='常熟枢纽闸内'", "samplename='张桥'", "samplename='大桥角新桥'", "samplename='望亭立交闸下'" }, "TP", Convert.ToDateTime(txtStartDate.Text.Trim()), "wqdate");
                photopath[7] = draw(ds, new string[] { "总磷", "TP" }, "wqdate", "samplename", "望虞河干流");
                ds = WQWuXiFO.getPPTimg("tblwqwuxi", new string[] { "samplename='大义桥'", "samplename='新师桥'", "samplename='鸟嘴渡'", "samplename='大坊桥'" }, "TP", Convert.ToDateTime(txtStartDate.Text.Trim()), "wqdate");
                photopath[8] = draw(ds, new string[] { "总磷", "TP" }, "wqdate", "samplename", "望虞河西岸支流");

                ds = WQWuXiFO.getPPTimg("tblwxjsz", new string[] { "zd=1" }, "D8", Convert.ToDateTime(txtStartDate.Text.Trim()), "dt");
                photopath[9] = draw(ds, new string[] { "高锰酸盐指数", "D8" }, "dt", "samplename", "贡湖自动站");

                ds = WQWuXiFO.getPPTimg("tblwxjsz", new string[] { "zd=1" }, "D10", Convert.ToDateTime(txtStartDate.Text.Trim()), "dt");
                photopath[10] = draw(ds, new string[] { "氨氮", "D10" }, "dt", "samplename", "望亭自动站");
                ds = WQWuXiFO.getPPTimg("tblwqwuxi", new string[] { "samplename='虞义大桥'", "samplename='常熟枢纽闸内'", "samplename='张桥'", "samplename='大桥角新桥'", "samplename='望亭立交闸下'" }, "Ammonia", Convert.ToDateTime(txtStartDate.Text.Trim()), "wqdate");
                photopath[11] = draw(ds, new string[] { "氨氮", "Ammonia" }, "wqdate", "samplename", "望虞河干流");
                ds = WQWuXiFO.getPPTimg("tblwqwuxi", new string[] { "samplename='大义桥'", "samplename='新师桥'", "samplename='鸟嘴渡'", "samplename='大坊桥'" }, "Ammonia", Convert.ToDateTime(txtStartDate.Text.Trim()), "wqdate");
                photopath[12] = draw(ds, new string[] { "氨氮", "Ammonia" }, "wqdate", "samplename", "望虞河西岸支流");

                ds = WQWuXiFO.getPPTimg("tblwqwuxi", new string[] { "samplename='锡东水厂取水口'", "samplename='贡湖水厂取水口'", "samplename='金墅湾水厂取水口'" }, "Ammonia", Convert.ToDateTime(txtStartDate.Text.Trim()), "wqdate");
                photopath[13] = draw(ds, new string[] { "高锰酸盐指数", "Ammonia" }, "wqdate", "samplename", "贡湖水源地");


                ds = WQWuXiFO.getPPTimg("tblwxjsz", new string[] { "zd=5" }, "D10", Convert.ToDateTime(txtStartDate.Text.Trim()), "dt");
                photopath[14] = draw(ds, new string[] { "氨氮", "D10" }, "dt", "samplename", "太浦闸站");
                ds = WQWuXiFO.getPPTimg("tblwqwuxi", new string[] { "samplename='太浦闸下'", "samplename='平望大桥'", "samplename='金泽'" }, "Ammonia", Convert.ToDateTime(txtStartDate.Text.Trim()), "wqdate");
                photopath[15] = draw(ds, new string[] { "氨氮", "Ammonia" }, "wqdate", "samplename", "太浦河水质");


                string filename = "值班专题演示材料" + CurrentUser.Id.ToString() + "," + DateTime.Now.ToString("yyyyMMddHHmmss") + ".ppt";
                string newfile = Server.MapPath("~/Upload/PresentationDocument/") + filename;
                strfilepath = newfile;
                if (File.Exists(newfile))
                {
                    File.Delete(newfile);
                }
                File.Copy(pptFileName, newfile);
                searchPPT(WQWuXiFO.GetPPTSource(txtStartDate.Text.Trim(), txtEndDate.Text.Trim() + " 23:59:59", "Keyword"), WQWuXiFO.GetPPTSource(txtStartDate.Text.Trim(), txtEndDate.Text.Trim() + "  23:59:59", null), newfile, photopath);
                //searchPPTPic(photopath, newfile);

                if (pager.SortConditions.Count < 1)
                {
                    SortCondition item = new SortCondition();
                    item.SortDirection = SLinker.Model.Search.SortDirection.Ascending;
                    item.SortField = "GenDate";

                    pager.SortConditions.Push(item);
                }
                IList<PresentationDocumentEntity> il = PresentationDocumentFO.GetPresentationDocumentList(pager, null);
                if (il.Count > 50)
                {
                    PresentationDocumentFO.DeletePresentationDocument(il[0].ID.ToString());
                }

                
                pdentity = PresentationDocumentFO.GetPresentationDocumentByFileName(filename);
                //信息存到数据库
                pdentity.DocumentName = filename;
                pdentity.StartDate = Convert.ToDateTime(txtStartDate.Text);
                pdentity.EndDate = Convert.ToDateTime(txtEndDate.Text);
                pdentity.GenDate = DateTime.Now;
                pdentity.GenUser = CurrentUser.Id;

                PresentationDocumentFO.SavePresentationDocument(pdentity);

                BindListData();
                
                //Response.Flush();

                //System.IO.FileInfo file = new System.IO.FileInfo(newfile);
                //Response.Clear();
                //Response.Charset = "GB2312";
                //Response.ContentEncoding = System.Text.Encoding.UTF8;
                //// 添加头信息,为"文件下载/另存为"对话框指定默认文件名 
                //Response.AddHeader("Content-Disposition", "attachment; filename=" + Server.UrlEncode(file.Name));
                //// 添加头信息,指定文件大小,让浏览器能够显示下载进度 
                //Response.AddHeader("Content-Length", file.Length.ToString()); 

                //// 指定返回的是一个不能被客户端读取的流,必须被下载 
                //Response.ContentType = "application/ms-excel";

                //// 把文件流发送到客户端 
                //Response.WriteFile(file.FullName);
                
                //// 停止页面的执行 

                //Response.End();
                ClientScript.RegisterStartupScript(Page.GetType(), "sc", "<script>upfile();</script>");
                
            }
        }

        #region===========操作方法==============
        private void searchPPT(string[] Keyword, string[] Keywordvalue, string pptFileName, string[] Piclist)//在指定的ppt文档中搜索keyWord
        {
            //其中Presentation代表一个 PowerPoint 文档,Slide表示PowerPoint文档中的单张幻灯片
            //TextFrame是幻灯片上的文本框,TextRange是文本框中的文本。

            pa = null;
            pp = null;
            bool[] found = new bool[Keyword.Length];
            bool[] img = new bool[Piclist.Length];
            int foundCount = 0;
            int founcimg = 0;
            for (int i = 0; i <= found.Length - 1; i++)
            {
                found = false;
            }
            for (int i = 0; i <= img.Length - 1; i++)
            {
                img = false;
            }
            //try
            //{
            //打开ppt文档
            pa = new Microsoft.Office.Interop.PowerPoint.ApplicationClass();
            pp = pa.Presentations.Open(pptFileName,
                Microsoft.Office.Core.MsoTriState.msoTrue,
                Microsoft.Office.Core.MsoTriState.msoTrue, Microsoft.Office.Core.MsoTriState.msoFalse);
您需要登录后才可以回帖 登录 | 马上注册

本版积分规则

QQ|手机版|小黑屋|手机版|联系我们|关于我们|广告合作|苏飞论坛 ( 豫ICP备18043678号-2)

GMT+8, 2024-11-15 17:27

© 2014-2021

快速回复 返回顶部 返回列表