Skip to content

Instantly share code, notes, and snippets.

@cofearabi
Created December 15, 2012 00:03
Show Gist options
  • Save cofearabi/4289755 to your computer and use it in GitHub Desktop.
Save cofearabi/4289755 to your computer and use it in GitHub Desktop.
(C#) write excel file
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 Excel = Microsoft.Office.Interop.Excel;
namespace cs_excel_write2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
// string ExcelBookFileName = textBox3.Text;
// string ExcelBookFileName = "c:\\mdb\\temp2.xlsx";
// Microsoft.Office.Interop.Excel.Application ExcelApp
// = new Microsoft.Office.Interop.Excel.Application();
Excel.Application ExcelApp
= new Excel.Application();
ExcelApp.Visible = true;
Excel.Workbook wb = ExcelApp.Workbooks.Add();
Excel.Worksheet ws1 = wb.Sheets[1];
ws1.Select(Type.Missing);
for (int i = 1; i < 20; i++)
{
Excel.Range rgn = ws1.Cells[i, 1];
rgn.Value2 = i;
}
wb.SaveAs("c:\\mdb\\temp3.xlsx");
wb.Close(false);
ExcelApp.Quit();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment