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 = (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 = (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 ();
}
C # create an Excel file and write the content