Search
Winners

Win Prizes

Social Presence
Like us on Facebook
Advertisements
Ads

Creating and writing XML file through C#

Mani5155
Posted by Mani5155 under ASP.NET on 4/12/2012 2:24:25 AM | Points: 75 | Views : 4983 | Status : [Member]

using Microsoft.Office.Core;

using Excel = Microsoft.Office.Interop.Excel;


Excel.Application myExcelApp;
Excel.Workbooks myExcelWorkbooks;
Excel.Workbook myExcelWorkbook;


object misValue = System.Reflection.Missing.Value;


myExcelApp = new Excel.ApplicationClass();
myExcelApp.Visible = true;
myExcelWorkbooks = myExcelApp.Workbooks;
String fileName = "C:\\book1.xls"; \\ set this to your file you want
myExcelWorkbook = myExcelWorkbooks.Open(fileName, misValue, misValue, misValue, misValue, misValue, misValue, misValue, misValue, misValue, misValue, misValue, misValue, misValue, misValue);

Excel.Worksheet myExcelWorksheet = (Excel.Worksheet)myExcelWorkbook.ActiveSheet;

String cellFormulaAsString = myExcelWorksheet.get_Range("A2", misValue).Formula.ToString(); \\ this puts the formula in Cell A2 or text depending whats in it in the string.

myExcelWorksheetToChange.get_Range("C22", misValue).Formula = "New Value" \\ this changes the cell value in C2 to "New Value"