当前位置: 首页 > news >正文

php网站建设教程 电子书指数平滑法

php网站建设教程 电子书,指数平滑法,个人网站 备案 名称,采集类淘宝客网站怎么做今天编写了一个c#的windows应用程序,主窗口是一个form,现在有一些计算出来的数据,想做成word格式输出来,在该应用程序中生成一个word文档 Word._Application app new Word.ApplicationClass(); app.Visible fal…

今天编写了一个c#的windows应用程序,主窗口是一个form,现在有一些计算出来的数据,想做成word格式输出来,
在该应用程序中生成一个word文档

Word._Application   app   =   new   Word.ApplicationClass();  
  app.Visible   =   false;  
   
  object   nothing   =   System.Reflection.Missing.Value;  
  object   temp   =   Environment.CurrentDirectory   +   @"/resume.doc";  
   
  Word.Document   doc  
  =   app.Documents.Open(ref   temp,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);  
   
  for   (i   =   0;   i   <   ds.Tables[3].Rows.Count;   i   ++)  
  {  
  int   intTableID   =   "";     //需要添加内容的tableID  
   
  intRow   =   doc.Tables[intTable].Rows.Count;  
  doc.Tables[intTable].Cell(intRow,1).Range.Text  
  =   ds.Tables[3].Rows[i]["ExperenceDate"].ToString();  
  doc.Tables[intTable].Cell(intRow,2).Range.Text  
  =   ds.Tables[3].Rows[i]["Company"].ToString();  
  doc.Tables[intTable].Cell(intRow,3).Range.Text  
  =   ds.Tables[3].Rows[i]["Department"].ToString();  
  doc.Tables[intTable].Cell(intRow,4).Range.Text  
  =   ds.Tables[3].Rows[i]["Station"].ToString();  
  doc.Tables[intTable].Rows.Add(ref nothing);  
  }  
 
 
 
  在CreateWord.cs文件里面添加:

using System.Reflection;

using Microsoft.Office.Interop.Word;

 

然后在按钮事件里面添加如下代码:

ApplicationClass wordApp = new ApplicationClass();

object missing = System.Reflection.Missing.Value;

object tempName = @"d:/Temp.dot";   // 模板名称,本例中的模板如后面的图

     object docName = @"D:/WebSite/a.doc"; // 生成的word文件,可以不放在web目录下,当然,实际应用中可能会涉及到动态生成文件名,相信这点难不倒你吧 ^_^

    

     // 生成新文档,这里使用了上面提到的模板,如果不想使用指定的模板,可使用missing,这是会使用默认的模板。关于生成word文件的几个方法,参阅MSDN

     Document MyDoc = wordApp.Documents.Add(ref tempName, ref missing, ref missing, ref    missing);

 

     wordApp.Visible = true;

     MyDoc.Activate();

      

     wordApp.Selection.Font.Size = 30;           // 字体大小

     wordApp.Selection.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphCenter;  // 居中

     wordApp.Selection.Font.Bold = (int)WdConstants.wdToggle;    // 黑体

     // 还有很多很多的格式可以在这里设置,发挥你的想像力尽情研究吧,吼吼~~~~~~~~

 

     wordApp.Selection.TypeText("hello");                        // 文字内容,这里我没有从数据库里面读取,只是测试了一下写入的内容

    

     // 保存word文档

    MyDoc.SaveAs(ref docName, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing);

 

     // 关闭,释放

     MyDoc.Close(ref missing, ref missing, ref missing);

     wordApp.Quit(ref missing, ref missing, ref missing);

     MyDoc = null;

     wordApp = null;

 

     Response.Redirect("DownloadWord.aspx?id=" + "a.doc");

下载页面的代码(DownloadWord.aspx.CS):

     string FullFileName = Request.QueryString["id"];

     FileInfo DownloadFile = new FileInfo(HostingEnvironment.ApplicationPhysicalPath + FullFileName); // 需要转换为绝对路径,否则会自动认到C盘系统里那个IIS目录下面去,而且,无法通过URI的方式来进行数据流读取。如果你生成的文件不在web目录下,也需要明确指出。  

     // 下面到就是读取文件,通过数据流的方式下载了。

     Response.Clear();

     Response.ClearHeaders();

     Response.Buffer = false;

     Response.ContentType = "application/octet-stream";

     Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(FullFileName, System.Text.Encoding.UTF8));

     Response.AppendHeader("Content-Length", DownloadFile.Length.ToString());

     Response.WriteFile(DownloadFile.FullName);

     Response.Flush();

     Response.End();

又一方法:
private void WriteFile()
   {

    strFileName=System.Windows.Forms.Application.StartupPath+"//试题库【"+GetRandomString()+"】.doc";
    Object Nothing=System.Reflection.Missing.Value;
    myWordDoc=myWordApp.Documents.Add(ref Nothing,ref Nothing,ref Nothing,ref Nothing);

    #region 将数据库中读取得数据写入到word文件中

    strContent="d://试题库/n/n/r";
    Response.WriteFile(strContent);

    strContent="试题库";
    Response.WriteFile(strContent);


    #endregion

    //将WordDoc文档对象的内容保存为DOC文档
    myWordDoc.SaveAs(ref strFileName,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文档对象
    myWordDoc.Close(ref Nothing, ref Nothing, ref Nothing);
    //关闭WordApp组件对象
    myWordApp.Quit(ref Nothing, ref Nothing, ref Nothing);
   }
        string   title="C#生成文档";  
     object   titleLengh=title.Length;  
     string   first="/n         公司最近需要利用C#对项目进行编程,其"+  
      "中存在一个功能就是可自动生成WORD文档,但一直以来都"+  
      "找不到什么好办法,无奈之下,只有自已学着写一个了.";  
     object   firstLengh=first.Length;  
     string   second="/n         如果能真正生成WORD文档的好处有:";  
     object   secondLengh=second.Length;  
     string   third="/n1、根据数据库信息自动生成文档;";  
     object   thirdLengh=third.Length;  
     string   forth="/n2、免去书写文档之苦;";  
     object   forthLengh=forth.Length;  
     string   fifth="/n3、可以通过邮件方式传出文档。";  
     object   fifthLengh=fifth.Length;  
     object   missing;  
     object   zero=0;  
     object   one=1;  
     object   two=2;  
     object   tree=3;  
     object   four=4;  
     object   five=5;  
     object   six=6;  
     object   seven=7;  
     object   eight=8;  
     object   nine=9;  
     object   ten=10;  
     Word.ApplicationClass   wa=new   Word.ApplicationClass();  
     missing=System.Reflection.Missing.Value;  
     wa.Visible=true;  
     wa.Documents.Add(ref   missing,ref   missing,ref   missing,ref   missing);  
     Word.Range   myRange=wa.ActiveDocument.Range(ref   zero,ref   zero);  
     object   r=myRange;  
     Word.Paragraph   p=wa.ActiveDocument.Paragraphs.Add(ref   r);  
     p.Range.InsertBefore(title);  
     Word.Range   titleRange=wa.ActiveDocument.Range(ref   zero,ref   titleLengh);  
     titleRange.Font.Size=24;  
     titleRange.Font.Name="隶书";  
     titleRange.Font.Color=Word.WdColor.wdColorBlue;  
     //MessageBox.Show("NO.1");  
     titleRange.Paragraphs.Alignment=Word.WdParagraphAlignment.wdAlignParagraphCenter;  
     Word.Range firstR=wa.ActiveDocument.Paragraphs.Item(2).Range;  
     r=firstR;  
     p=wa.ActiveDocument.Paragraphs.Add(ref   r);  
     firstR.Font.Size=12;  
     firstR.Paragraphs.Alignment=Word.WdParagraphAlignment.wdAlignParagraphJustify;  
     firstR.InsertAfter(first);  
     firstR.InsertParagraphAfter();  
     //firstR=wa.ActiveDocument.Paragraphs.Item(3).Range;  
     firstR.InsertAfter(second);  
     firstR.InsertAfter(third);  
     firstR.InsertAfter(forth);  
     firstR.InsertAfter(fifth);  

 

转载于:https://www.cnblogs.com/teacherz/archive/2006/05/14/2353858.html

http://www.lbrq.cn/news/2693359.html

相关文章:

  • wordpress 部署关键词推广优化排名品牌
  • 专业的画册设计网站百度长尾关键词挖掘
  • 好的企业型网站模板交换友链是什么意思
  • 问卷调查微信小程序怎么做江门seo
  • 公司品牌网站建设价格糕点烘焙专业培训学校
  • 在百度上做网站seo服务是什么
  • b2c的平台有哪些谷歌搜索优化
  • 最便宜做公司网站广州网站开发多少钱
  • 网站制作 长沙b2b网站平台有哪些
  • 电商网站设计工作内容seo搜索引擎优化到底是什么
  • 成都网站建设推广投放广告的渠道有哪些
  • 厦门微信网站开发百度ai助手入口
  • b2c商城网站建设及运营方案网站推广的方式
  • 网站做ddns解析网站域名查询ip
  • 网业协同重庆企业网站排名优化
  • 中小企业的网站建设论文推广资源seo
  • wordpress插件 ftp银徽seo
  • 网站建设试题品牌推广策略怎么写
  • 私服网站空间seo整站优化费用
  • wordpress 商城 app上海网站推广优化
  • 专门做辅助的扎金花网站seo教程下载
  • 网站建设制作设计优化如何推广小程序
  • 技术难度高的网站开发北京网站优化方式
  • 新公司注册后需要办理哪些好搜seo软件
  • 四川旅游seo整站优化站优化seo价格是多少
  • 网站建设代理多少钱seo推广的公司
  • 电影网站建设公司seo排名优化关键词
  • 化妆品网站建设可行性分析sem推广和seo的区别
  • 潍坊诸城疫情window优化大师官网
  • 泰安医院网站建设企业查询网
  • C#自定义日期时间选择器
  • ASP.NET 上传文件安全检测方案
  • 使用 6 种方法将文件从 Android 无缝传输到iPad
  • 【递归、搜索与回溯算法】穷举、暴搜、深搜、回溯、剪枝
  • GitHub分支保护介绍(Branch Protection)(git分支保护)(通过设置规则和权限来限制对特定分支的操作的功能)
  • 【自动化备份全网服务器数据项目】