using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.OleDb;

namespace ExcelExport
{
    class ExcelExport
    {

        /// <summary>
        /// DataTable 엑셀로 내보내기
        /// </summary>
        /// <param name="ds"></param>
        public void TOExcel()
        {
            DateTime dt = DateTime.Now;  // 현제 날짜를 파일명으로 받아오기 위함.
            try
            {
                string xls = "c:\\" + dt.ToString("MMdd");
                if (System.IO.File.Exists(xls))
                {
                    System.IO.File.Delete(xls);
                }


                string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=C:\\" + dt.ToString("MMdd") + @";Extended Properties=Excel 8.0";
                OleDbConnection connection = new OleDbConnection(strConn);
                connection.Open();
                string sql = "CREATE TABLE test(숫자 int)";

                OleDbCommand command = new OleDbCommand(sql, connection);
                command.ExecuteNonQuery();

 

                for (int i = 0; i <= 1000; i++)
                {
                    string sql1 = "INSERT INTO test VALUES('" + i.ToString() + "')";
                    OleDbCommand command1 = new OleDbCommand(sql1, connection);
                    command1.ExecuteNonQuery();
                }

                connection.Close();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }

        }
    }
}

'닷넷 프레임워크' 카테고리의 다른 글

1. 프로세스의 형태  (0) 2009.04.27
Managed Code 개요  (0) 2009.04.27
IFormatProvider 인터페이스  (0) 2009.04.27
Generic  (0) 2009.04.27
error MSB3323: 대처법  (0) 2009.04.27

+ Recent posts