2017/10/15编辑器测试

来源:互联网 发布:闹钟备忘录软件 编辑:程序博客网 时间:2024/06/05 07:16
2017/10/15:测试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.Reflection;using System.IO;using Excel = Microsoft.Office.Interop.Excel;namespace Excel2{    public partial class Form1 : Form    {        string cruentPath = "";        public Form1()        {            InitializeComponent();            init();        }    private void button1_Click(object sender, EventArgs e)    {        WriteExcel(cruentPath + "\\results.xlsx");    }    private void init()    {         cruentPath = Directory.GetCurrentDirectory();    }    private void WriteExcel(string filename)    {        Excel.Application excelApp = new Excel.Application();        if (excelApp == null)        {            MessageBox.Show("不存在Excel");            return;        }        Excel.Workbook workbook;        if (File.Exists(filename))        {            workbook = excelApp.Workbooks.Open(filename, 0, false, 5, "", "", true,            Excel.XlPlatform.xlWindows, "\t", false, false, 0, true, 1, 0);        }        else        {            workbook = excelApp.Workbooks.Add(true);        }        Excel.Worksheet worksheet = workbook.ActiveSheet as Excel.Worksheet;        worksheet = (Excel.Worksheet)workbook.Worksheets.get_Item(1);        worksheet.Cells[1,1] = "二维码";        worksheet.Cells[1, 2] = "字符1";        worksheet.Cells[1, 3] = "字符2";        worksheet.Cells[1, 4] = "字符3";        //worksheet.Cells[1, 2] = "二维码";        excelApp.Visible = false;        excelApp.DisplayAlerts = false;        if (File.Exists(filename))        {            workbook.Save();        }        //workbook.SaveAs(filename);        workbook.Close(false,Missing.Value,Missing.Value);        excelApp.Quit();        worksheet = null;        workbook = null;        excelApp = null;        GC.Collect();    }}

}

原创粉丝点击