I am trying to open an Excel file and populate its cells with data? I have done the following coding so far.
Currently I am at this stage with the following code but
I think, that you have to declare the associated sheet!
Try something like this
objsheet(1).Cells[i,j].Value;
Simple.
To open a workbook. Use xlapp.workbooks.Open()
where you have previously declared and instanitated xlapp as so.. Excel.Application xlapp = new Excel.Applicaton();
parameters are correct.
Next make sure you use the property Value2 when assigning a value to the cell using either the cells property or the range object.
How I work to automate Office / Excel:
You can use the below code; it's working fine for me:
newWorkbook = appExcel.Workbooks.Add();
Try:
Excel.Application oXL;
Excel._Workbook oWB;
Excel._Worksheet oSheet;
Excel.Range oRng;
oXL = new Excel.Application();
oXL.Visible = true;
oWB = (Excel._Workbook)(oXL.Workbooks.Add(Missing.Value));
oSheet = (Excel._Worksheet)oWB.Worksheets;
oSheet.Activate();
oSheet.Cells[3, 9] = "Some Text"
This works fine for me
Excel.Application oXL = null;
Excel._Workbook oWB = null;
Excel._Worksheet oSheet = null;
try
{
oXL = new Excel.Application();
string path = @"C:\Templates\NCRepTemplate.xlt";
oWB = oXL.Workbooks.Open(path, 0, false, 5, "", "",
false, Excel.XlPlatform.xlWindows, "", true, false,
0, true, false, false);
oSheet = (Excel._Worksheet)oWB.ActiveSheet;
oSheet.Cells[2, 2] = "Text";