Here is the solution for my question.
public static void AddNewColumn(string fileName, int sheetNum)
{
Excel.Application xlApp;
Excel.Workbook xlWorkBook;
Excel.Worksheet xlWorkSheet;
Excel.Range rng;
object misValue = System.Reflection.Missing.Value;
try
{
xlApp = new Excel.Application();
xlApp.Visible = true;
xlWorkBook = xlApp.Workbooks.Open(fileName, 0, false, 5, "", "", false,
Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "", true, false, 0, true, 1, 0);
xlWorkSheet = (Excel.Worksheet)xlWorkBook.Sheets.get_Item(sheetNum);
rng = xlWorkSheet.UsedRange;
int colCount = rng.Columns.Count;
int rowCount = rng.Rows.Count;
rng = (Excel.Range)xlWorkSheet.Cells[rowCount, colCount];
Excel.Range newColumn = rng.EntireColumn;
xlWorkSheet.Cells[1, colCount + 1] = "Visit Link";
xlWorkBook.Save();
xlWorkBook.Close(misValue, misValue, misValue);
xlApp.Quit();
System.Runtime.InteropServices.Marshal.ReleaseComObject(rng);
System.Runtime.InteropServices.Marshal.ReleaseComObject(xlWorkSheet);
Marshal.ReleaseComObject(xlWorkBook);
Marshal.ReleaseComObject(xlApp);
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
finally
{
GC.Collect();
GC.WaitForPendingFinalizers();
}
}
private void btnAddNewColumns_Click(object sender, EventArgs e)
{
try
{
string theFile = txtFileName.Text;
int theSheet = cboGetSheet.SelectedIndex +1;
ExcelTools.AddNewColumn(theFile, theSheet);
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}