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;                            //设置文档为可见
                //————————————————
                //版权声明:本文为优快云博主「亨利先生」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
                //原文链接:https://blog.youkuaiyun.com/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.W
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值