For this solution, I'll assume you'll run it on a PC with Excel installed.
First, add reference to library Microsoft.Office.Interop.Excel
. Then, use its namespace:
using Excel = Microsoft.Office.Interop.Excel;
Be warned that because it's COM Interop, you need to retain each and every reference to objects from this library to properly release them from memory with Marshal. This is golden rule to use COM Interop objects from .NET projects. For more info, read it here: How do I properly clean up Excel interop objects?
So, this is another important import:
using System.Runtime.InteropServices;
I don't know how you're filling this form, but I'll suppose there is one field for each data between brackets: {CITY}, {NUM_I1}, and so on.
So, in your form submission, you could create a dictionary out of your inputs:
Dictionary<string, string> replacing = new Dictionary<string, string>();
replacing.Add("{CITY}",txtCity.Text);
...
And then, for filling the Workbook:
//Opening Excel Application with desirable template Workbook
//and instantiating the desirable Worksheet and Range
Excel.Application xlApplication = new Excel.Application();
Excel.Workbooks xlWorkbooks = xlApplication.Workbooks;
Excel.Workbook xlWorkbook = xlWorkbooks.Open(templateFilename, ReadOnly: true);
Excel.Sheets xlSheets = xlWorkbook.Sheets;
Excel.Worksheet xlWorksheet = (Excel.Worksheet)xlSheets[sheetNameOrIndex];
Excel.xlFirstCell = xlWorksheet.Cells[firstRow, firstCol];
Excel.xlLastCell = xlWorksheet.Cells[lastRow, lastCol];
Excel.Range xlRange = xlWorksheet.Cells[xlFirstCell, xlLastCell];
//all of the replacing
foreach (string key in replacing.Keys)
xlRange.Replace(key, replacing[key]);
//saving
xlWorkbook.SaveAs(newFilename);
//important part: releasing references
Marshal.ReleaseComObject(xlRange);
Marshal.ReleaseComObject(xlFirstCell);
Marshal.ReleaseComObject(xlLastCell);
Marshal.ReleaseComObject(xlWorksheet);
Marshal.ReleaseComObject(xlSheets);
xlWorkbook.Close(SaveChanges: false);
Marshal.ReleaseComObject(xlWorkbook);
Marshal.ReleaseComObject(xlWorkbooks);
xlApplication.Exit();
Marshal.ReleaseComObject(xlApplication);
I've made it using c# 4.0. If you need it to develop it under Visual Studio 2008 or older, which don't support optional parameters, you just need to pass Type.Missing
to parameters you don't want to use under Excel library methods (Workbooks.Open and Range.Replace).