■ GridControl 클래스 : ExportToXlsx 메소드를 사용해 엑셀 파일 생성하기

------------------------------------------------------------------------------------------------------------------------


TestProject.zip


MainForm.cs

 

 

using System;

using System.Data.OleDb;

using System.Diagnostics;

 

using DevExpress.Utils;

using DevExpress.XtraEditors;

using DevExpress.XtraGrid.Views.Grid;

using DevExpress.XtraPrinting;

 

namespace TestProject

{

    /// <summary>

    /// 메인 폼

    /// </summary>

    public partial class MainForm : XtraForm

    {

        //////////////////////////////////////////////////////////////////////////////////////////////////// Field

        ////////////////////////////////////////////////////////////////////////////////////////// Private

 

        #region Field

 

        /// <summary>

        /// 연결

        /// </summary>

        private OleDbConnection connection;

 

        #endregion

 

        //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor

        ////////////////////////////////////////////////////////////////////////////////////////// Public

 

        #region 생성자 - MainForm()

 

        /// <summary>

        /// 생성자

        /// </summary>

        public MainForm()

        {

            InitializeComponent();

 

            this.connection = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=nwind.mdb");

 

            this.gridView.InitializeView

            (

                true,                           // Multi Select

                GridMultiSelectMode.CellSelect, // Grid Multi Select Mode

                DrawFocusRectStyle.CellFocus,   // Draw Focus Rect Style

                true,                           // Show Indicator

                true,                           // Show Column Headers

                true,                           // Allow Column Moving

                true,                           // Allow Column Resizing

                true,                           // Allow Filter

                true,                           // Allow Sort

                false,                          // Allow Cell Merge

                EditorShowMode.Default,         // Editor Show Mode

                false                           // Editable

            );

 

            this.gridView.OptionsBehavior.AutoPopulateColumns = true;

 

            this.gridControl.DataSource = Customer.GetCustomerList(this.connection);

 

            this.gridView.BestFitColumns();

 

            this.executeButton.Click += executeButton_Click;

        }

 

        #endregion

 

        //////////////////////////////////////////////////////////////////////////////////////////////////// Method

        ////////////////////////////////////////////////////////////////////////////////////////// Private

 

        #region 실행 버튼 클릭시 처리하기 - executeButton_Click(sender, e)

 

        /// <summary>

        /// 실행 버튼 클릭시 처리하기

        /// </summary>

        /// <param name="sender">이벤트 발생자</param>

        /// <param name="e">이벤트 인자</param>

        private void executeButton_Click(object sender, EventArgs e)

        {

            string filePath = "d:\\output.xlsx";

 

            this.gridView.OptionsPrint.PrintHeader = false;

 

            XlsxExportOptionsEx option = new XlsxExportOptionsEx();

 

            option.AllowGrouping      = DefaultBoolean.False;

            option.ShowTotalSummaries = DefaultBoolean.False;

            option.SheetName          = "데이터";

 

            this.gridControl.ExportToXlsx(filePath, option);

 

            Process.Start(filePath);

        }

 

        #endregion

    }

}

 

------------------------------------------------------------------------------------------------------------------------

Posted by 사용자 icodebroker
TAG

댓글을 달아 주세요