private GridExcelConverterControl control = new GridExcelConverterControl(); //Importing the excel to grid private void button2_Click(object sender, EventArgs e) { ExcelEngine engine = new ExcelEngine(); IApplication app = engine.Excel.Application; IWorkbook workbook = null; workbook = engine.Excel.Workbooks.Open("..\\..\\Book2.xlsx", ExcelOpenType.Automatic); IWorksheet mySheet = workbook.Worksheets[0]; control.ExcelToGrid(mySheet, this.gridControl1.Model); this.gridControl1.Refresh(); MessageBox.Show("Successfully Imported"); } //Export the grid to excel. private void button1_Click(object sender, EventArgs e) { ExcelEngine engine = new ExcelEngine(); IApplication app = engine.Excel.Application; app.DefaultVersion = ExcelVersion.Excel2010; IWorkbook workBook = app.Workbooks.Create(); workBook = engine.Excel.Workbooks.Open("..\\..\\Book2.xlsx"); IWorksheet sheet = workBook.Worksheets[0]; control.GridToExcel(this.gridControl1, sheet, ConverterOptions.Visible); workBook.Save(); //Process.Start(@"..\..\Book2.xlsx"); MessageBox.Show("Successfully exported"); } |
ExcelEngine engine = new ExcelEngine();
IApplication app = engine.Excel.Application;
app.DefaultVersion = ExcelVersion.Excel2010;
IWorkbook workBook = app.Workbooks.Create();
workBook = engine.Excel.Workbooks.Open(@"../data/bux/sample.xlsx");
IWorksheet sheet = workBook.Worksheets[0];
sheet.InsertRow(1, checkGrid.RowCount, ExcelInsertOptions.FormatAsBefore); // <----- There was not enough line
control.GridToExcel(this.checkGrid, sheet, ConverterOptions.Default);
workBook.Save();