c#制作word值班表 手动添加自启动 点击获取值班数量及时间

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using MSWord = Microsoft.Office.Interop.Word;
using System.IO;
using System.Reflection;
using Microsoft.Office.Interop.Word;
using System.Threading;
using IWshRuntimeLibrary;
//using System;
//using IWshRuntimeLibrary;
//MSWord.Document wordDoc;                  //Word文档变量
//using System.IO;

namespace WindowsApplication2
{
    
    



    public partial class Form1 : Form
    {
    
    
        public void zuo()
        {
    
    
            DateTime.Now.ToString();            // 2008-9-4 20:02:10
            string i = DateTime.Now.ToLocalTime().ToString();        // 2008-9-4 20:12:12
            label1.Text = i;


            xxx.app.Visible = true;//使文档可见
            object oMissing = System.Reflection.Missing.Value;

            object format = MSWord.WdSaveFormat.wdFormatDocument;// office 2007就是wdFormatDocumentDefault
            //将wordDoc文档对象的内容保存为DOCX文档
            // Section s = xxx.wordDoc.Sections[0];

            if (System.IO.File.Exists(@"C://Users//Administrator//Desktop//Test.doc"))
            {
    
    
                label2.Text = "666";
              //  MessageBox.Show("c");
                //wordApp = new MSWord.ApplicationClass();   
                // object oMissing = System.Reflection.Missing.Value;//初始化一个word程序
                xxx.wordDoc = xxx.app.Documents.Open(ref xxx.c, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref 

oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing);            //打开path指定的word文档
                xxx.app.Visible = true;                            //设置文档为可见
                //————————————————
                //版权声明:本文为CSDN博主「亨利先生」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
                //原文链接:https://blog.csdn.net/weixin_40212554/article/details/83796199
                int ip = xxx.wordDoc.Tables.Count;//获取表格数
                Microsoft.Office.Interop.Word.Table nowTable = xxx.wordDoc.Tables[ip];//获取表格中的行数
                //int ip = xxx.wordDoc.Tables.Count;
                int ip6 = nowTable.Rows.Count;
                // DataSet ds = new DataSet();

                //ds = xxx.wordDoc.Tables.;
               // MessageBox.Show(Convert.ToString(ip6));
                DateTime.Now.ToString();            // 2008-9-4 20:02:10
                string da = DateTime.Now.ToLocalTime().ToString("yyyy-MM-dd");        // 2008-9-4 20:12:12
                int i6 = 1;
                xxx.i = ip6 + 1;
                //  MSWord.Document wordDoc;

                // xxx.app.Quit(ref oMissing, ref oMissing, ref oMissing);




                int day = (int)DateTime.Now.DayOfWeek;//0是周日 1 2 3 4 5 6 0
                string[] weekday ={
    
     "sunday", "monday", "tuesday", "wednesday", "thursday", "friday", "saturday" };
                string week = weekday[Convert.ToInt32(DateTime.Now.DayOfWeek)];

                string[] kaishishijian ={
    
     "8:00", "17:00", "17:00", "17:00", "17:00", "17:00", "8:00" };
                string kaishi = kaishishijian[Convert.ToInt32(DateTime.Now.DayOfWeek)];

                string[] zhibanxingzhi ={
    
     "周末", "延值", "延值", "延值", "延值", "延值", "周末" };
                string zhiban = zhibanxingzhi[Convert.ToInt32(DateTime.Now.DayOfWeek)];

                string[] zhibanshichang ={
    
     "12", "3", "3", "3", "3", "3", "12" };
                string shichang = zhibanshichang[Convert.ToInt32(DateTime.Now.DayOfWeek)];
                // MessageBox.Show(Convert.ToString(day)); 
                // MessageBox.Show(week);

                object count = 9999;
                object WdLine = Microsoft.Office.Interop.Word.WdUnits.wdLine;//换一行;
                xxx.app.Selection.MoveDown(ref WdLine, ref count, ref oMissing);//移动焦点
                // xxx.app.Selection.TypeParagraph();//插入段落

                Microsoft.Office.Interop.Word.Table newTable = xxx.wordDoc.Tables.Add(xxx.app.Selection.Range, 1, 7, ref oMissing, ref oMissing);
                newTable.Borders.OutsideLineStyle = Microsoft.Office.Interop.Word.WdLineStyle.wdLineStyleSingle;//表格外面的边框线
                newTable.Borders.InsideLineStyle = Microsoft.Office.Interop.Word.WdLineStyle.wdLineStyleSingle;//表格里面的边框线
                newTable.Range.ParagraphFormat.Alignment = MSWord.WdParagraphAlignment.wdAlignParagraphCenter;//表格左右居中
                newTable.Range.Cells.VerticalAlignment = WdCellVerticalAlignment.wdCellAlignVerticalCenter;//表格垂直居中

                //newTable.Range.ParagraphFormat.Alignment = MSWord.WdParagraphAlignment.wdAlignParagraphCenter;
                //填充表格内容
                //   xxx.app.Selection.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter;//水平居中
                newTable.Cell(xxx.i, 1).Range.Text = da;

                newTable.Cell(xxx.i, 1).Range.Bold = 2;//设置单元格中字体为粗体
                // xxx.wordDoc.Paragraphs.Add(ref oMissing);

                newTable.Cell(xxx.i, 2).Range.Text = kaishi;
                // xxx.app.Selection.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter;//水平居中
                // xxx.app.Selection.Cells.VerticalAlignment = Microsoft.Office.Interop.Word.WdCellVerticalAlignment.wdCellAlignVerticalCenter;//垂直居中
                newTable.Cell(xxx.i, 2).Range.Bold = 2;//设置单元格中字体为粗体
                //xxx.app.Selection.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter;//水平居中
                newTable.Cell(xxx.i, 3).Range.Text = "20:00";

                newTable.Cell(xxx.i, 3).Range.Bold = 2;//设置单元格中字体为粗体

                // xxx.app.Selection.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter;//水平居中
                newTable.Cell(xxx.i, 4).Range.Text = "上传医保数据,处理his系统故障";

                newTable.Cell(xxx.i, 4).Range.Bold = 2;//设置单元格中字体为粗体

                // xxx.app.Selection.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter;//水平居中
                newTable.Cell(xxx.i, 5).Range.Text = zhiban;

                newTable.Cell(xxx.i, 5).Range.Bold = 2;//设置单元格中字体为粗体

                // xxx.app.Selection.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter;//水平居中
                newTable.Cell(xxx.i, 6).Range.Text = shichang + "小时";

                newTable.Cell(xxx.i, 6).Range.Bold = 2;//设置单元格中字体为粗体

                // xxx.app.Selection.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter;//水平居中
                newTable.Cell(xxx.i, 7).Range.Text = "刘畅";
                // 
                newTable.Cell(xxx.i, 7).Range.Bold = 2;//设置单元格中字体为粗体
                xxx.wordDoc.SaveAs(ref xxx.c, ref format, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref 

oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing);
              //  xxx.app.Quit(ref oMissing, ref oMissing, ref oMissing);
            }
            else
            {
    
    
                xxx.wordDoc = xxx.app.Documents.Add(ref oMissing, ref oMissing, ref oMissing, ref oMissing);
                xxx.app.ActiveWindow.ActivePane.Selection.InsertAfter("值班\n");
                xxx.app.Selection.Font.Size = 20;
                xxx.app.Selection.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter;//水平居中
                xxx.app.ActiveWindow.ActivePane.Selection.InsertAfter("值班\n");
                object count = 644;
                object WdLine = Microsoft.Office.Interop.Word.WdUnits.wdLine;//换一行;
                xxx.app.Selection.MoveDown(ref WdLine, ref count, ref oMissing);//移动焦点
                xxx.app.Selection.TypeParagraph();//插入段落

                Microsoft.Office.Interop.Word.Table newTable = xxx.wordDoc.Tables.Add(xxx.app.Selection.Range, 1, 7, ref oMissing, ref oMissing);
                newTable.Borders.OutsideLineStyle = Microsoft.Office.Interop.Word.WdLineStyle.wdLineStyleSingle;
                newTable.Borders.InsideLineStyle = Microsoft.Office.Interop.Word.WdLineStyle.wdLineStyleSingle;
                newTable.Range.ParagraphFormat.Alignment = MSWord.WdParagraphAlignment.wdAlignParagraphCenter;

                newTable.Range.Cells.VerticalAlignment = WdCellVerticalAlignment.wdCellAlignVerticalCenter;//设置单元格中字体为粗体
                //填充表格内容
                //   xxx.app.Selection.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter;//水平居中
                newTable.Cell(1, 1).Range.Text = "日期";

                newTable.Cell(1, 1).Range.Bold = 2;//设置单元格中字体为粗体
                // xxx.wordDoc.Paragraphs.Add(ref oMissing);

                newTable.Cell(1, 2).Range.Text = "开始时间";
                // xxx.app.Selection.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter;//水平居中
                // xxx.app.Selection.Cells.VerticalAlignment = Microsoft.Office.Interop.Word.WdCellVerticalAlignment.wdCellAlignVerticalCenter;//垂直居中
                newTable.Cell(1, 2).Range.Bold = 2;//设置单元格中字体为粗体
                //xxx.app.Selection.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter;//水平居中
                newTable.Cell(1, 3).Range.Text = "上传医保数据,处理his系统故障";

                newTable.Cell(1, 3).Range.Bold = 2;//设置单元格中字体为粗体

                // xxx.app.Selection.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter;//水平居中
                newTable.Cell(1, 4).Range.Text = "事由";

                newTable.Cell(1, 4).Range.Bold = 2;//设置单元格中字体为粗体

                // xxx.app.Selection.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter;//水平居中
                newTable.Cell(1, 5).Range.Text = "值班性质";

                newTable.Cell(1, 5).Range.Bold = 2;//设置单元格中字体为粗体

                // xxx.app.Selection.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter;//水平居中
                newTable.Cell(1, 6).Range.Text = "时长";

                newTable.Cell(1, 6).Range.Bold = 2;//设置单元格中字体为粗体

                // xxx.app.Selection.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter;//水平居中
                newTable.Cell(1, 7).Range.Text = "备注";
                // 
                newTable.Cell(1, 7).Range.Bold = 2;//设置单元格中字体为粗体

                xxx.app.Selection.Tables[1].Rows.Alignment = WdRowAlignment.wdAlignRowCenter;

                //   Console.Write("文本");

                // Selection.TypeText Text:="值班"
                //Selection.TypeText Text:="值班"
                //xxx.app.Selection.Font.Size = 10;
                //xxx.app.ActiveWindow.ActivePane.Font.Size = 36;
                //xxx.wordDoc.Paragraphs.Last.Alignment = xxx.aWdParagraphAlignment.wdAlignParagraphCenter;
                object oMissing6 = System.Reflection.Missing.Value;

                object format6 = MSWord.WdSaveFormat.wdFormatDocument;// office 2007就是wdFormatDocumentDefault


               // MessageBox.Show("c");
                //wordApp = new MSWord.ApplicationClass();   
                // object oMissing = System.Reflection.Missing.Value;//初始化一个word程序
               // object oMissing = System.Reflection.Missing.Value;
                //object format = MSWord.WdSaveFormat.wdFormatDocument;// office 2007就是wdFormatDocumentDefault
               // xxx.wordDoc = xxx.app.Documents.Open(ref xxx.c, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref 

//oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing);            //打开path指定的word文档
              //  xxx.app.Visible = true;                            //设置文档为可见
                //————————————————
                //版权声明:本文为CSDN博主「亨利先生」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
                //原文链接:https://blog.csdn.net/weixin_40212554/article/details/83796199
                int ip = xxx.wordDoc.Tables.Count;//获取表格数
                Microsoft.Office.Interop.Word.Table nowTable = xxx.wordDoc.Tables[ip];//获取表格中的行数
                //int ip = xxx.wordDoc.Tables.Count;
                int ip6 = nowTable.Rows.Count;
                // DataSet ds = new DataSet();

                //ds = xxx.wordDoc.Tables.;
               // MessageBox.Show(Convert.ToString(ip6));
                DateTime.Now.ToString();            // 2008-9-4 20:02:10
                string da = DateTime.Now.ToLocalTime().ToString("yyyy-MM-dd");        // 2008-9-4 20:12:12
                int i6 = 1;
                xxx.i = ip6 + 1;
                //  MSWord.Document wordDoc;

                // xxx.app.Quit(ref oMissing, ref oMissing, ref oMissing);




                int day = (int)DateTime.Now.DayOfWeek;//0是周日 1 2 3 4 5 6 0
                string[] weekday ={
    
     "sunday", "monday", "tuesday", "wednesday", "thursday", "friday", "saturday" };
                string week = weekday[Convert.ToInt32(DateTime.Now.DayOfWeek)];

                string[] kaishishijian ={
    
     "8:00", "17:00", "17:00", "17:00", "17:00", "17:00", "8:00" };
                string kaishi = kaishishijian[Convert.ToInt32(DateTime.Now.DayOfWeek)];

                string[] zhibanxingzhi ={
    
     "周末", "延值", "延值", "延值", "延值", "延值", "周末" };
                string zhiban = zhibanxingzhi[Convert.ToInt32(DateTime.Now.DayOfWeek)];

                string[] zhibanshichang ={
    
     "12", "3", "3", "3", "3", "3", "12" };
                string shichang = zhibanshichang[Convert.ToInt32(DateTime.Now.DayOfWeek)];
                // MessageBox.Show(Convert.ToString(day)); 
                // MessageBox.Show(week);

               // object count6 = 14;
                //object WdLine6 = Microsoft.Office.Interop.Word.WdUnits.wdLine;//换一行;
                xxx.app.Selection.MoveDown(ref WdLine, ref count, ref oMissing);//移动焦点
                // xxx.app.Selection.TypeParagraph();//插入段落

                Microsoft.Office.Interop.Word.Table newTable6 = xxx.wordDoc.Tables.Add(xxx.app.Selection.Range, 1, 7, ref oMissing, ref oMissing);
                newTable6.Borders.OutsideLineStyle = Microsoft.Office.Interop.Word.WdLineStyle.wdLineStyleSingle;//表格外面的边框线
                newTable6.Borders.InsideLineStyle = Microsoft.Office.Interop.Word.WdLineStyle.wdLineStyleSingle;//表格里面的边框线
                newTable6.Range.ParagraphFormat.Alignment = MSWord.WdParagraphAlignment.wdAlignParagraphCenter;//表格左右居中
                newTable6.Range.Cells.VerticalAlignment = WdCellVerticalAlignment.wdCellAlignVerticalCenter;//表格垂直居中

                //newTable.Range.ParagraphFormat.Alignment = MSWord.WdParagraphAlignment.wdAlignParagraphCenter;
                //填充表格内容
                //   xxx.app.Selection.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter;//水平居中
                newTable6.Cell(xxx.i, 1).Range.Text = da;

                newTable6.Cell(xxx.i, 1).Range.Bold = 2;//设置单元格中字体为粗体
                // xxx.wordDoc.Paragraphs.Add(ref oMissing);

                newTable6.Cell(xxx.i, 2).Range.Text = kaishi;
                // xxx.app.Selection.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter;//水平居中
                // xxx.app.Selection.Cells.VerticalAlignment = Microsoft.Office.Interop.Word.WdCellVerticalAlignment.wdCellAlignVerticalCenter;//垂直居中
                newTable6.Cell(xxx.i, 2).Range.Bold = 2;//设置单元格中字体为粗体
                //xxx.app.Selection.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter;//水平居中
                newTable6.Cell(xxx.i, 3).Range.Text = "20:00";

                newTable6.Cell(xxx.i, 3).Range.Bold = 2;//设置单元格中字体为粗体

                // xxx.app.Selection.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter;//水平居中
                newTable6.Cell(xxx.i, 4).Range.Text = "上传医保数据,处理his系统故障";

                newTable.Cell(xxx.i, 4).Range.Bold = 2;//设置单元格中字体为粗体

                // xxx.app.Selection.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter;//水平居中
                newTable6.Cell(xxx.i, 5).Range.Text = zhiban;

                newTable6.Cell(xxx.i, 5).Range.Bold = 2;//设置单元格中字体为粗体

                // xxx.app.Selection.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter;//水平居中
                newTable6.Cell(xxx.i, 6).Range.Text = shichang + "小时";

                newTable6.Cell(xxx.i, 6).Range.Bold = 2;//设置单元格中字体为粗体

                // xxx.app.Selection.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter;//水平居中
                newTable6.Cell(xxx.i, 7).Range.Text = "刘畅";
                // 
                newTable6.Cell(xxx.i, 7).Range.Bold = 2;//设置单元格中字体为粗体
                xxx.wordDoc.SaveAs(ref xxx.c, ref format, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref 

oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing);
                xxx.wordDoc.SaveAs(ref xxx.c, ref format6, ref oMissing6, ref oMissing6, ref oMissing6, ref oMissing6, ref oMissing6, ref oMissing6, ref oMissing6, ref oMissing6, ref oMissing6,

ref oMissing6, ref oMissing6, ref oMissing6, ref oMissing6, ref oMissing6);
                // xxx.app.ActiveDocument.Selection.TypeText Text="465";
                //xxx.app.Quit(ref oMissing, ref oMissing, ref oMissing);
                label2.Text = "66";
            }
        }
        public Form1()
        {
    
    
            InitializeComponent();

        }

        private void Form1_Load(object sender, EventArgs e)
        {
    
    
            Thread t = new Thread(PrintNumbers);
            t.Start();//线程开始执行
            // t.Join();
            Thread s = new Thread(shifoukai);
            s.Start();
            System.Windows.Forms.Control.CheckForIllegalCrossThreadCalls = false;
        }

        static void PrintNumbers()
        {
    
    
            for (xxx.xunhuan6 = 1; xxx.xunhuan6 > 0; xxx.xunhuan6++)
            {
    
    
                // Console.WriteLine("Starting...");
                xxx.da = DateTime.Now.ToLocalTime().ToString("HH");
                Console.Write(xxx.da);
                Thread.Sleep(TimeSpan.FromSeconds(2));

            }
        }

        void shifoukai()
        {
    
    
            string[] weekday ={
    
     "6", "0", "0", "0", "0", "0", "6" };
            string week = weekday[Convert.ToInt32(DateTime.Now.DayOfWeek)];
            //object zhouji = Convert.ToInt32(week);
            Console.Write(Convert.ToInt32(week));

            for (xxx.xunhuan = 1; xxx.xunhuan > 0; xxx.xunhuan++)
            {
    
    
                if (Convert.ToInt32(week) == 6)
                {
    
    
                    this.zuo();// z = new zuo();}
                }
                else
                {
    
    
                    //int shifou= 0;
                    object o = Convert.ToInt32(xxx.da);
                    //int.TryParse(xxx.da, out shifou);
                    //  int.Parse(xxx.da);

                    if (Convert.ToInt32(xxx.da) >= 12)
                    //{
    
    
                    {
    
    
                        this.zuo();// z = new zuo();
                        Console.Write(Convert.ToInt32(xxx.da) + ".....");
                        Thread.Sleep(TimeSpan.FromSeconds(4));
                        // }
                        xxx.xunhuan = -1;//将这个线程停了
                        xxx.xunhuan6 = -1;//将上面的线程停了
                        if (xxx.xunhuan== -1&&xxx.xunhuan6==-1) {
    
    
                            //MessageBox.Show("保存ok");
                            //this.Close();
                        }
                    }
                }
            }
        }
        enum Day {
    
     monday, tuesday, wednesday, thursday, friday, saturday, sunday };
        //   private void button1_Click(object sender, EventArgs e)
        // {
    
    


        //  }

        private void button1_Click_1(object sender, EventArgs e)
        {
    
    
            label2.Text = "666";
            object oMissing = System.Reflection.Missing.Value;

            object format = MSWord.WdSaveFormat.wdFormatDocument;// office 2007就是wdFormatDocumentDefault
            xxx.wordDoc = xxx.app.Documents.Open(ref xxx.c, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref 

oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing);            //打开path指定的word文档
            xxx.app.Visible = true;                            //设置文档为可见
            //————————————————
            //版权声明:本文为CSDN博主「亨利先生」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
            //原文链接:https://blog.csdn.net/weixin_40212554/article/details/83796199
            int ip = xxx.wordDoc.Tables.Count;//获取表格数
            Microsoft.Office.Interop.Word.Table nowTable = xxx.wordDoc.Tables[ip];//获取表格中的行数
            //int ip = xxx.wordDoc.Tables.Count;
            int ip6 = nowTable.Rows.Count;//获取行数
            // DataSet ds = new DataSet();

            //ds = xxx.wordDoc.Tables.;
            // MessageBox.Show(Convert.ToString(ip6));
           // DateTime.Now.ToString();            // 2008-9-4 20:02:10
            //string da = DateTime.Now.ToLocalTime().ToString("yyyy-MM-dd");        // 2008-9-4 20:12:12
            int i6 = 1;//从第一行开始读取
            //xxx.i = ip6 + 1;
            //  MSWord.Document wordDoc;

            // xxx.app.Quit(ref oMissing, ref oMissing, ref oMissing);
            int jici3 = 0;//获取有几个三小时
            int jici6 = 0;//获取有几个六小时
            for (int jitian=1; jitian < ip6;jitian++ ) {
    
    //从第一行开始读取  每次读完i6加1
                i6 = i6 + 1;
            string text = nowTable.Cell(i6, 6).Range.Text.ToString();//读表格的第i6行 第6列
            
            string c = text.Substring(0, 1);//读取的内容从头开始数的第一个字
            int duoshao = Convert.ToInt32(c);//将小时数转换为int
            label2.Text = c;
            string cc = label2.Text;
            if (duoshao == 3) {
    
     //判断有几个3小时
                jici3 = jici3 + 1; //给3小时加1 方便最后结算
            }
            else{
    
    
                jici6 = jici6 + 1;
            }
            MessageBox.Show(c);
        } MessageBox.Show("三小时:"+Convert.ToString(jici3)+"次"+","+"十二小时"+Convert.ToString(jici6)+"次");
        int hou = ip6+1;
        object count = 9999;
        object WdLine = Microsoft.Office.Interop.Word.WdUnits.wdLine;//换一行;
        xxx.app.Selection.MoveDown(ref WdLine, ref count, ref oMissing);//移动焦点
        // xxx.app.Selection.TypeParagraph();//插入段落

        Microsoft.Office.Interop.Word.Table newTable7 = xxx.wordDoc.Tables.Add(xxx.app.Selection.Range, 1, 4, ref oMissing, ref oMissing);
        newTable7.Borders.OutsideLineStyle = Microsoft.Office.Interop.Word.WdLineStyle.wdLineStyleSingle;//表格外面的边框线
        newTable7.Borders.InsideLineStyle = Microsoft.Office.Interop.Word.WdLineStyle.wdLineStyleSingle;//表格里面的边框线
        newTable7.Range.ParagraphFormat.Alignment = MSWord.WdParagraphAlignment.wdAlignParagraphCenter;//表格左右居中
        newTable7.Range.Cells.VerticalAlignment = WdCellVerticalAlignment.wdCellAlignVerticalCenter;//表格垂直居中

        //newTable.Range.ParagraphFormat.Alignment = MSWord.WdParagraphAlignment.wdAlignParagraphCenter;
        //填充表格内容
        //   xxx.app.Selection.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter;//水平居中
        newTable7.Cell(hou, 1).Range.Text = "审核人";

        newTable7.Cell(hou, 1).Range.Bold = 2;//设置单元格中字体为粗体

        newTable7.Cell(hou, 3).Range.Text = "批准人";

        newTable7.Cell(hou, 3).Range.Bold = 2;//设置单元格中字体为粗体
        xxx.app.Selection.MoveDown(ref WdLine, ref count, ref oMissing);//移动焦点
        xxx.app.ActiveWindow.ActivePane.Selection.InsertAfter("三小时:" + Convert.ToString(jici3) + "次" + "," + "十二小时" + Convert.ToString(jici6) + "次");
        // xxx.wordDoc.Paragraphs.Add(ref oMissing);

            //  xxx.app.Quit(ref oMissing, ref oMissing, ref oMissing);
       
        
        }

        private void button2_Click(object sender, EventArgs e)
        {
    
    
            WshShell shell = new WshShell();
            IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut(
            "C://Users//Administrator//Desktop//" +
            "\\" + "666.lnk");
            shortcut.TargetPath = System.Reflection.Assembly.GetExecutingAssembly().Location;
            shortcut.WorkingDirectory = System.Environment.CurrentDirectory;
            shortcut.WindowStyle = 1;
            shortcut.Description = "Launch Allen's Application";
            shortcut.IconLocation = "C://Users//Administrator//Desktop//6666.ico";
            shortcut.Save();
            //string src = "C://Users//Administrator//Desktop//666.lnk";
           // string dest = "C://Users//Administrator//Desktop//新建文件夹 (2)";
            //moveFiles(dest, src); // dest -> src
           System.IO.File.Copy("C://Users//Administrator//Desktop//666.lnk","C://Users//Administrator//AppData//Roaming//Microsoft//Windows//Start Menu//Programs666.lnk"); // src -> dest
        }




    }

    public class xxx
    {
    
    
        public static int i = 1;
        public static int xunhuan = 1;
        public static int xunhuan6 = 1;
        public static MSWord.Application wordApp;                   //Word应用程序变量 

        public static Microsoft.Office.Interop.Word.Application app = new Microsoft.Office.Interop.Word.Application();
        public static MSWord.Document wordDoc;
        public static object c = "C://Users//Administrator//Desktop//Test.doc";
        public static string da;

    }






    public static class common // static 不是必须
    {
    
    
        public static float[,] farray = new float[2, 3];
        private static string name = "cc";
        public static string Name
        {
    
    
            get {
    
     return name; }
            set {
    
     name = value; }
        }
    }


    public class ipp
    {
    
    

    }
}



猜你喜欢

转载自blog.csdn.net/weixin_40938312/article/details/102628100