小弟用C#写了一个winform 程序界面(图1),主要实现从电脑上的网络盘每天定时获取备份文件的大小,然后自动写入指定位置的excel文件(图2)中自动保存。现在能够实现手动选择文件获取到大小,但是不知道如何实现写到指定位置的Excel中,请各路前辈指点一下代码。最好能够解决实现程序一直运行,每天早上9点自动获取备份大写,然后自动写入网络盘上的excel中,谢谢!

解决方案 »

  1.   

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows.Forms;
    using System.Runtime.InteropServices;
    using System.IO;namespace 读取备份信息
    {
        public partial class Frm_Main : Form
        {
            public Frm_Main()
            {
                InitializeComponent();
            }        OpenFileDialog open = new OpenFileDialog();        private void button1_Click(object sender, EventArgs e)
            {
                if (open.ShowDialog() == DialogResult.OK)
                {
                    textBox1.Text = open.FileName;
                }
                FileInfo MyFileInfo = new FileInfo(open.FileName);
                float MyFileSize = (float)MyFileInfo.Length / (1024 * 1024);
                textBox5.Text = MyFileSize.ToString() + "MB";
                return;
            }        private void timer1_Tick(object sender, EventArgs e)
            {
                DateTime current = DateTime.Now;
                textBox8.Text = current.Year.ToString()+ "/" + current.Month.ToString() + "/" + current.Day.ToString(); 
            }        private void button5_Click(object sender, EventArgs e)
            {
              
                if (open.ShowDialog() == DialogResult.OK)
                {
                    textBox3.Text = open.FileName;
                }
                FileInfo MyFileInfo = new FileInfo(open.FileName);
                float MyFileSize = (float)MyFileInfo.Length / (1024 * 1024);
                textBox6.Text = MyFileSize.ToString() + "MB";
                return;        }        private void button6_Click(object sender, EventArgs e)
            {
            
                if (open.ShowDialog() == DialogResult.OK)
                {
                    textBox4.Text = open.FileName;
                }
                FileInfo MyFileInfo = new FileInfo(open.FileName);
                float MyFileSize = (float)MyFileInfo.Length / (1024 * 1024);
                textBox7.Text = MyFileSize.ToString() + "MB";
                return;
            }        private void button2_Click(object sender, EventArgs e)
            {
               
                if (open.ShowDialog() == DialogResult.OK)
                {
                    textBox2.Text =  open.FileName;
                }
            }        private void button3_Click(object sender, EventArgs e)
            {
                Workbook workbook = new Workbook();
                   
             
            }
        }
    }
    目前的代码写到这里了,就是下面的写不下去了,求指导(如何将备份大小信息写到指定位置的excel中)
      

  2.   

    搜索 C# NPOI
      

  3.   

    自动定时备份,写入EXCEL需要使用定时服务
    1.写一个C#的服务,定时执行备份和写EXCEL任务.
    2.C#操作EXCEL,工具类很多,NPOI,或者逗号分隔的文本也行