ApplicationClass Class
Here is VB.NET sample code:
Dim excelApp As ApplicationClass = New ApplicationClass
Dim excelBook As Workbook
excelBook = excelApp.Workbooks.Open("C:\SampleExcel.xls", 0, False, 5, _
System.Reflection.Missing.Value, System.Reflection.Missing.Value, _
False, System.Reflection.Missing.Value, System.Reflection.Missing.Value, _
True, False, System.Reflection.Missing.Value, False)
Dim excelSheets As Sheets = excelBook.Sheets
Dim wSheet As Worksheet = excelSheets(1)
Dim cell1 As Range = wSheet.Range("B4:FZ4", Type.Missing)
Dim cell2 As Range = wSheet.Range("A4:A5", Type.Missing)
cell2.Value2 = "SampleText"
excelBook.Save()
excelApp.Quit()
- 1/9/2007
- Mahesh Chand
Here is an example of how to use ApplicationClass to generate Excel sheet and data in C#.
Excel.Application xl=new Excel.ApplicationClass();
Excel.Workbook wb=xl.Workbooks.Open(Environment.CurrentDirectory+"/SampleExcel.xls",0, false, 5, System.Reflection.Missing.Value, System.Reflection.Missing.Value, false, System.Reflection.Missing.Value, System.Reflection.Missing.Value,true, false, System.Reflection.Missing.Value, false, false, false);//Open the excel sheet
Excel.Sheets xlsheets = wb.Sheets; //Get the sheets from workbook
Excel.Worksheet excelWorksheet = (Excel.Worksheet)xlsheets[1]; //Select the first sheet
Excel.Range excelCell = (Excel.Range)excelWorksheet.get_Range("B4:FZ4", Type.Missing); //Select a range of cells
Excel.Range excelCell2 = (Excel.Range)excelWorksheet.get_Range("A5:A5", Type.Missing); //Select a single cell
excelCell2.Cells.Value2 = "SampleText"; //Assign a value to the cell
wb.Save(); //Save the workbook
xl.Quit();
=========
Read more details here:
- 1/9/2007
- Mahesh Chand