2017년 3월 21일 화요일

[C#] 스프레드 Sheet Copy

참고 : http://blog.daum.net/lsj8601/44
 
ex ) ---> 스프레드 Sheet 1, 2,3  데이타 각각 가져와서 Excel에 뿌려주기 

            FarPoint.Win.Spread.SheetView sv = new FarPoint.Win.Spread.SheetView();
            FarPoint.Win.Spread.SheetView sv01 = new FarPoint.Win.Spread.SheetView();
            FarPoint.Win.Spread.SheetView sv02 = new FarPoint.Win.Spread.SheetView();
          --> 스프레드 데이타 복사 
            sv   = CopySheet(this.spdNICUFollowDetailList.ActiveSheet);
            sv01 = CopySheet(this.spdNICUDetail01.ActiveSheet);
            sv02 = CopySheet(this.spdNICUDetail02.ActiveSheet);

            SaveFileDialog saveExcelFileDialog = new SaveFileDialog();
            saveExcelFileDialog.InitialDirectory = "C:\\";
            saveExcelFileDialog.Filter = "Excel files (*.xls)|*.xls";
            saveExcelFileDialog.FilterIndex = 0;
            saveExcelFileDialog.FileName = "NICU_" + this.txtUnitNo.Text; //+ "_" + this.txtPatNm.Text;

            if (saveExcelFileDialog.ShowDialog() == DialogResult.OK)
            {

                this.fpspreadExc.Sheets[0].Protect = false;
                this.fpspreadExc.Sheets[1].Protect = false;
                this.fpspreadExc.Sheets[2].Protect = false;
                
                // 하나의 스프레드를 만들어서 Sheet 별로 담기 
                fpspreadExc.Sheets[0] = sv;
                fpspreadExc.Sheets[1] = sv01;
                fpspreadExc.Sheets[2] = sv02;
                this.fpspreadExc.Visible = true;
                
                // 담은 값을 엑셀에 뿌려주기 
                this.fpspreadExc.SaveExcel(saveExcelFileDialog.FileName,     FarPoint.Win.Spread.Model.IncludeHeaders.ColumnHeadersCustomOnly);

                this.fpspreadExc.Visible = false;
                this.fpspreadExc.Sheets[0].Protect = true;
                this.fpspreadExc.Sheets[1].Protect = true;
                this.fpspreadExc.Sheets[2].Protect = true;
            
                MessageBoxViewer.ShowAlert("HIS.SP", "SET_SAVE_SUCCEEDED");
                
               
                
            }
--> 스프레드 Copy 사용자메서드 
public FarPoint.Win.Spread.SheetView CopySheet(FarPoint.Win.Spread.SheetView sheet)
        {
            FarPoint.Win.Spread.SheetView newSheet = null;
            if (sheet != null)
            {
                newSheet = (FarPoint.Win.Spread.SheetView)FarPoint.Win.Serializer.LoadObjectXml(sheet.GetType(),                     FarPoint.Win.Serializer.GetObjectXml(sheet, "CopySheet"), "CopySheet");
            }
            return newSheet;
        } 

댓글 없음:

댓글 쓰기

엑셀 파일 데이타 강제로 담기

http://leemcse.tistory.com/entry/C-%ED%94%84%EB%A1%9C%EA%B7%B8%EB%9E%A8%EC%9C%BC%EB%A1%9C-Excel-File%EC%9D%84-%EB%B6%88%EB%9F%AC%EC%98%A4%EA...