Export UltraWinGrid to Excel (WinGird에서 엑셀로 내려받기)
Posted by 씨디맨 Posted in " 소프트웨어/3rd Part "
2009. 1. 30. 22:45
|
Downloading an UltraGrid to an Excel File, by letting the user choose the download location
UltraGrid is a component from Infragistics, which provide a rich set of features for the Grid Control. And moreover, it can download the entire Grid (along with its content) to an Excel file. It retains the entire formatting, entire Column Positions and much more.
UltraGrid is a component from Infragistics, which provide a rich set of features for the Grid Control. And moreover, it can download the entire Grid (along with its content) to an Excel file. It retains the entire formatting, entire Column Positions and much more.
UltraWinGrid에서 Excel로 내려 받는 방법입니다.
UltraGridExcelExporter1 컨트롤을 이용하면 간단히 처리할 수 있습니다.
소스코드는 외국블로그를 참고하였습니다.
간단히 동작하는 로직을 보면 내려받기 버튼을 클릭합니다.
이벤트가 발생하면 저장위치를 지정하는 파일다이얼로그를 호출합니다.
저장할 위치를 지정하고 파일명을 쓰고 엑셀파일을 IO로 씁니다.
그런후 UltraGridExcelExporter 를 이용해서 그리드를 엑셀로 기록합니다.
Excel로 내려받기 버튼을 클릭합니다. 저장이름을 입력합니다.
엑셀에서 정상적으로 잘 보여집니다.
하지만 포멧도 적용 되지만 mask형식은 적용 안되는 거 같습니다.
현재 정렬을 정상적으로 적용되어 나타난 상태입니다.
외국 포럼에서 설명해둔 코드
Please note:
btnDownload is the button on whose click Event the code to CreateExcel file is written.
참조를 하니깐 아래와 같이 선언을 해 주어야 합니다.
using Infragistics.Win.UltraWinGrid.ExcelExport;
using System.IO;
/// <summary>
/// The Button Event
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
// 버튼 클릭시
private void btnDownload_Click(object sender, System.EventArgs e)
{
try
{
//Saving to Excel file. This launches the Save dialog for the user to select the Save Path
CreateExcel(FindSavePath());
}
catch(Exception ex)
{
//Handle Exception
MessageBox.Show(ex.Message);
}
finally
{
//Any cleanup code
this.Cursor = Cursors.Default;
}
}
/// <summary>
/// Creates an Excel from the UltraGrid and saves it to the user mentioned Save Path
/// </summary>
/// <param name="myFilepath"></param>
private void CreateExcel(String myFilepath )
{
try
{
if (myFilepath!= null)
{
//You need to Create the ExcelExporter component in the design view
this.ultraGridExcelExporter1.Export(this.ultragrid1, myFilepath);
//위와 같이 컨트롤을 넣어도 됩니다. 저는 컨트롤을 붙이기 보다는 아래와 같이 선언을 해서 썼습니다. (동일)
//using Infragistics.Win.UltraWinGrid.ExcelExport;
//UltraGridExcelExporter UltraGridExcelExporter1 = new UltraGridExcelExporter();
//UltraGridExcelExporter1.Export(this.ultraGrid1, myFilepath);
MessageBox.Show("Grid data successfully downloaded to "+ myFilepath);
}
}
catch(Exception ex)
{
throw ex;
}
}
/// <summary>
/// Finding path for saving excel sheet.
/// </summary>
/// <returns>full path</returns>
private String FindSavePath()
{
Stream myStream;
string myFilepath=null;
try
{
SaveFileDialog saveFileDialog1 = new SaveFileDialog();
saveFileDialog1.Filter = "excel files (*.xls)|*.xls";
saveFileDialog1.FilterIndex = 2 ;
saveFileDialog1.RestoreDirectory = true ;
if(saveFileDialog1.ShowDialog() == DialogResult.OK)
{
if((myStream = saveFileDialog1.OpenFile()) != null)
{
myFilepath=saveFileDialog1.FileName;
myStream.Close();
}
}
}
catch(Exception ex)
{
throw ex;
}
return myFilepath;
}
btnDownload is the button on whose click Event the code to CreateExcel file is written.
참조를 하니깐 아래와 같이 선언을 해 주어야 합니다.
using Infragistics.Win.UltraWinGrid.ExcelExport;
using System.IO;
/// <summary>
/// The Button Event
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
// 버튼 클릭시
private void btnDownload_Click(object sender, System.EventArgs e)
{
try
{
//Saving to Excel file. This launches the Save dialog for the user to select the Save Path
CreateExcel(FindSavePath());
}
catch(Exception ex)
{
//Handle Exception
MessageBox.Show(ex.Message);
}
finally
{
//Any cleanup code
this.Cursor = Cursors.Default;
}
}
/// <summary>
/// Creates an Excel from the UltraGrid and saves it to the user mentioned Save Path
/// </summary>
/// <param name="myFilepath"></param>
private void CreateExcel(String myFilepath )
{
try
{
if (myFilepath!= null)
{
//You need to Create the ExcelExporter component in the design view
this.ultraGridExcelExporter1.Export(this.ultragrid1, myFilepath);
//위와 같이 컨트롤을 넣어도 됩니다. 저는 컨트롤을 붙이기 보다는 아래와 같이 선언을 해서 썼습니다. (동일)
//using Infragistics.Win.UltraWinGrid.ExcelExport;
//UltraGridExcelExporter UltraGridExcelExporter1 = new UltraGridExcelExporter();
//UltraGridExcelExporter1.Export(this.ultraGrid1, myFilepath);
MessageBox.Show("Grid data successfully downloaded to "+ myFilepath);
}
}
catch(Exception ex)
{
throw ex;
}
}
/// <summary>
/// Finding path for saving excel sheet.
/// </summary>
/// <returns>full path</returns>
private String FindSavePath()
{
Stream myStream;
string myFilepath=null;
try
{
SaveFileDialog saveFileDialog1 = new SaveFileDialog();
saveFileDialog1.Filter = "excel files (*.xls)|*.xls";
saveFileDialog1.FilterIndex = 2 ;
saveFileDialog1.RestoreDirectory = true ;
if(saveFileDialog1.ShowDialog() == DialogResult.OK)
{
if((myStream = saveFileDialog1.OpenFile()) != null)
{
myFilepath=saveFileDialog1.FileName;
myStream.Close();
}
}
}
catch(Exception ex)
{
throw ex;
}
return myFilepath;
}
|
'소프트웨어 > 3rd Part' 카테고리의 다른 글
UltraWinGrid Infragistics Netadvantage - FrameWork (25) | 2009.07.16 |
---|---|
UltraWinTree 클릭후 포커스 Enter/Out 시 색상지정 (5) | 2009.03.02 |
스마트클라이언트 이해와 배포시나리오 (27) | 2009.02.25 |
Export UltraWinGrid to Excel (WinGird에서 엑셀로 내려받기) (5) | 2009.01.30 |
Windows Form UltraWinGrid Infragistics Netadvantage 2008.3 CLR2.0 버전 ver 0.1 (5) | 2009.01.20 |
UltraWinGrid 의 Grid의 GroupBoxBy 예제입니다. (4) | 2009.01.17 |
앗 첫댓글....^^
역시 저에겐 좀 어려운 포스팅...ㅎㅎㅎㅎ
주말 잘 보내세요~~~
동생이 적은글입니다 ㅋ 동생이랑 팀블로그를 했거든요 동생이 설명은 재대로 안해놓고 스샷만 ㅡㅡ
행복하고 즐거운 주말 보내세요 ^^
히히히-.
우선 설명이라고 간략하게 달았지만 많이 부족하네요.
포럼에 영어로 친절히 설명이 되어 있구요~
UltraGridExcelExporter 컨포넌트를 이용해서 쉽게 Excel로 다운로드 받을 수 있다는 내용이죠 ^^
솔루션 프로그램중에서 엑셀로 다운로드 받는 기능이 있는 데 고객들이 원하죠.
돈관리나 숫자관리는 엑셀로 하는 버릇때문에 구현해 달라고 하기때문에 이건 필요한거죠 ^^ㅋㅋ
어째 전 봐도 모르겠어요...
알면 알수록 더 어려워집니다.
그래도 cdmanii님네서 많은 정보 얻고 갑니다...
안녕하세요 ^^
Infragistics NetAdvantage for Windows Forms 2008.Vol.3.CLR.2.0에 보면 UltraGridExcelExporter 컨포넌트가 있죠. 이걸 이용해서 그리드를 엑셀로 내려받는 방법이죠.
3rd part쪽은 프로그래밍이 보다는 어떻게 잘쓰냐가 관건인거 같아요. 외국컴퍼넌트라서 영어로 된 메뉴얼이 많고 포럼이기때문에 관련자료는 한글로 된것이 별로 없어서 이렇게 하나씩 설명해보려고 작성중이에요 ^^