1. added the Microsoft. Office. Interop. Excel application.
2 reference namespace using Excel = Microsoft. Office. Interop. Excel;
/// <Summary>
/// If the supplied excel File does not exist then Create it
/// </Summary>
/// <Param name = "FileName"> </param>
Private void CreateExcelFile (string FileName)
{
// Create
Object Nothing = System. Reflection. Missing. Value;
Var app = new Excel. Application ();
App. Visible = false;
Excel. Workbook workBook = app. Workbooks. Add (Nothing );
Excel. Worksheet worksheet = (Excel. Worksheet) workBook. Sheets [1];
Worksheet. Name = "Work ";
// Headline
Worksheet. Cells [1, 1] = "FileName ";
Worksheet. Cells [1, 2] = "FindString ";
Worksheet. Cells [1, 3] = "ReplaceString ";
Worksheet. saveAs (FileName, Type. missing, Type. missing, Type. missing, Type. missing, Type. missing, Excel. xlSaveAsAccessMode. xlNoChange, Type. missing, Type. missing, Type. missing );
WorkBook. Close (false, Type. Missing, Type. Missing );
App. Quit ();
}
/// <Summary>
/// Open an excel file, then write the content to file
/// </Summary>
/// <Param name = "FileName"> file name </param>
/// <Param name = "findString"> first cloumn </param>
/// <Param name = "replaceString"> second cloumn </param>
Private void WriteToExcel (string excelName, string filename, string findString, string replaceString)
{
// Open
Object Nothing = System. Reflection. Missing. Value;
Var app = new Excel. Application ();
App. Visible = false;
Excel. workbook mybook = app. workbooks. open (excelName, Nothing, Nothing );
Excel. Worksheet mysheet = (Excel. Worksheet) mybook. Worksheets [1];
Mysheet. Activate ();
// Get activate sheet max row count
Int maxrow = mysheet. UsedRange. Rows. Count + 1;
Mysheet. Cells [maxrow, 1] = filename;
Mysheet. Cells [maxrow, 2] = findString;
Mysheet. Cells [maxrow, 3] = replaceString;
Mybook. Save ();
Mybook. Close (false, Type. Missing, Type. Missing );
Mybook = null;
// Quit excel app
App. Quit ();
}
1. added the Microsoft. Office. Interop. Excel application.
2 reference namespace using Excel = Microsoft. Office. Interop. Excel;
/// <Summary>
/// If the supplied excel File does not exist then Create it
/// </Summary>
/// <Param name = "FileName"> </param>
Private void CreateExcelFile (string FileName)
{
// Create
Object Nothing = System. Reflection. Missing. Value;
Var app = new Excel. Application ();
App. Visible = false;
Excel. Workbook workBook = app. Workbooks. Add (Nothing );
Excel. Worksheet worksheet = (Excel. Worksheet) workBook. Sheets [1];
Worksheet. Name = "Work ";
// Headline
Worksheet. Cells [1, 1] = "FileName ";
Worksheet. Cells [1, 2] = "FindString ";
Worksheet. Cells [1, 3] = "ReplaceString ";
Worksheet. saveAs (FileName, Type. missing, Type. missing, Type. missing, Type. missing, Type. missing, Excel. xlSaveAsAccessMode. xlNoChange, Type. missing, Type. missing, Type. missing );
WorkBook. Close (false, Type. Missing, Type. Missing );
App. Quit ();
}
/// <Summary>
/// Open an excel file, then write the content to file
/// </Summary>
/// <Param name = "FileName"> file name </param>
/// <Param name = "findString"> first cloumn </param>
/// <Param name = "replaceString"> second cloumn </param>
Private void WriteToExcel (string excelName, string filename, string findString, string replaceString)
{
// Open
Object Nothing = System. Reflection. Missing. Value;
Var app = new Excel. Application ();
App. Visible = false;
Excel. workbook mybook = app. workbooks. open (excelName, Nothing, Nothing );
Excel. Worksheet mysheet = (Excel. Worksheet) mybook. Worksheets [1];
Mysheet. Activate ();
// Get activate sheet max row count
Int maxrow = mysheet. UsedRange. Rows. Count + 1;
Mysheet. Cells [maxrow, 1] = filename;
Mysheet. Cells [maxrow, 2] = findString;
Mysheet. Cells [maxrow, 3] = replaceString;
Mybook. Save ();
Mybook. Close (false, Type. Missing, Type. Missing );
Mybook = null;
// Quit excel app
App. Quit ();
}