zoukankan      html  css  js  c++  java
  • 第一个C#窗体应用程序开发总结-----单号单面法调整单操作程序

    1、总体布局:

      总体分为了三个部分:窗体、计算、打印、Modle

      ①、窗体方面没用到啥特别的控件,没啥好说的

      ②、写计算过程时粗心导致的错误,真的是既浪费时间,又浪费精力

      ③、打印,这个是以前从来没有用到过的,这里真的是学到不少,这次主要是用到了根据word模板生成word文档代码,主要借鉴了

    灵魂重铸写的-------C#:简单实现动态数据生成Word文档并保存,原链接:https://blog.csdn.net/fujie724/article/details/5443322

        不过这里我稍做了些改动,具体代码如下:  

     1   public static void Dayin()
     2   {   
     3      object oMissing = System.Reflection.Missing.Value;
     4             //创建一个Word应用程序实例  
     5             Word._Application oWord = new Word.Application();
     6             //设置为不可见  
     7             oWord.Visible = false;
     8             
     9             //*********************以下为寻找word模板代码************************
    10             
    11             //获取当前启动项目的路径
    12             string path = Directory.GetCurrentDirectory();
    13             //进行拼接,形成一个绝对路径
    14             object oTemplate = path + "\参数及几何尺寸.dot";
    15             //***********************************************************************
    16             //以模板为基础生成文档  
    17             Word._Document oDoc = oWord.Documents.Add(ref oTemplate, ref oMissing, ref oMissing, ref oMissing);
    18             //声明书签数组  
    19             object[] oBookMark = new object[45];
    20             //赋值书签名  
    21             oBookMark[0] = "AL";
    22             //后面略。。。。。
    23 
    24             //赋值任意数据到书签的位置  
    25             oDoc.Bookmarks.get_Item(ref oBookMark[0]).Range.Text = Elements.AL.ToString("0.#######");
    26             //后面略    。。。。。。。。。。。。。。。。。。。。。。。
    27             //弹出保存文件对话框,保存生成的Word  
    28             SaveFileDialog sfd = new SaveFileDialog();
    29             //文件名默认生成为word模板名加上时间
    30             sfd.FileName = "参数及几何尺寸_" + DateTime.Now.ToString("f");
    31 
    32             sfd.Filter = "Word Document(*.doc)|*.doc";
    33             sfd.DefaultExt = "Word Document(*.doc)|*.doc";
    34             if (sfd.ShowDialog() == DialogResult.OK)
    35             {
    36                 object filename = sfd.FileName;
    37 
    38                 oDoc.SaveAs(ref filename, ref oMissing, ref oMissing, ref oMissing,
    39                 ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
    40                 ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
    41                 ref oMissing, ref oMissing);         
    42             }
    43             //关闭wordDoc文档对象             
    44             oDoc.Close(ref oMissing, ref oMissing, ref oMissing);
    45             //关闭word  
    46             oWord.Quit(ref oMissing, ref oMissing, ref oMissing);
    47 }
    根据模板生成word文档代码

      ④、由于不涉及安全性,所以就将所有的变量类为了精度都设成double类型,而且是public的,这样方便所有类库和窗体中都能调用                      

      

  • 相关阅读:
    vue 给嵌套的iframe子页面传数据 postMessage
    左边宽度固定,右边宽度自适应的三种写法
    全局变量声明的规范化
    利用__index和__newindex实现默认值表、监控表、只读表
    Metatable和Metamethod
    Lua中的协同程序 coroutine
    Lua中的require
    Lua基础
    D3D的绘制
    效率相关笔记
  • 原文地址:https://www.cnblogs.com/ShiroKa-X/p/8891425.html
Copyright © 2011-2022 走看看