try
{ if (sprGrid.Sheets[0].Rows.Count == 0) { return; }
SaveFileDialog mDlg = new SaveFileDialog();
mDlg.InitialDirectory = Application.StartupPath;
mDlg.Filter = "Excel files (*.xlsx)|*.xlsx|Excel files (*.xls)|*.xls|All files (*.*)|*.*";
mDlg.FilterIndex = 1;
if (mDlg.ShowDialog() == DialogResult.OK) { // 1. Footer 값 넣기 위해 1줄 추가 sprGrid.ActiveSheet.RowCount++;
// 2. int row = sprGrid.ActiveSheet.GetLastNonEmptyRow(FarPoint.Win.Spread.NonEmptyItemFlag.Data) + 1; int col = sprGrid.ActiveSheet.GetLastNonEmptyColumn(FarPoint.Win.Spread.NonEmptyItemFlag.Data) + 1;
// 3. ColumnFooter의 데이터를 데이터 영역에 붙여 넣기 for (int i = 0; i < sprGrid.ActiveSheet.ColumnFooter.RowCount; i++) { sprGrid.ActiveSheet.Rows[row + i].Height = 30;
for (int j = 0; j < col; j++) { sprGrid.ActiveSheet.Cells[row + i, j].Value = sprGrid.ActiveSheet.ColumnFooter.Cells[i, j].Value; } }
// 헤더를 포함하여 엑셀 변환... sprGrid.SaveExcel(mDlg.FileName, FarPoint.Excel.ExcelSaveFlags.UseOOXMLFormat | FarPoint.Excel.ExcelSaveFlags.SaveCustomColumnHeaders);
// 4. 위 3 에서 붙여 넣은 데이터 지우기 sprGrid.ActiveSheet.ClearRange(row, 0, sprGrid.ActiveSheet.ColumnFooter.RowCount, col, true); sprGrid.ActiveSheet.RowCount--;
// 엑셀파일 열기... ProcessStartInfo info = new ProcessStartInfo("excel.exe", mDlg.FileName); Process.Start(info); } } catch (Exception ex) { MessageBox.Show(ex.Message, "오류", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } finally {
} |