Working with Excel from C# (archive)
This is the simplest and most primitive example, may be useful, but better to use OpenXML.
In this publication, an example of creating and displaying an Excel document from a program written in C# is presented.
The most primitive example is presented for educational purposes.
Creating an Excel document.
Microsoft.Office.Interop.Excel.Application ObjExcel = new Microsoft.Office.Interop.Excel.Application();
Microsoft.Office.Interop.Excel.Workbook ObjWorkBook;
Microsoft.Office.Interop.Excel.Worksheet ObjWorkSheet;
//Книга.
ObjWorkBook = ObjExcel.Workbooks.Add(System.Reflection.Missing.Value);
//Таблица.
ObjWorkSheet = (Microsoft.Office.Interop.Excel.Worksheet)ObjWorkBook.Sheets[1];
Filling in values.
//Значения [y - строка,x - столбец]
ObjWorkSheet.Cells[3, 1] = textBox1.Text;
ObjWorkSheet.Cells[3, 2] = textBox2.Text;
ObjWorkSheet.Cells[3, 3] = textBox3.Text;
Finally, making the created Excel document visible and accessible!
ObjExcel.Visible = true;
ObjExcel.UserControl = true;
Comments (0)
No comments yet.