archivo de Excel para guardar valor en el rango de celdas

 protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                Microsoft.Office.Interop.Excel.Application app = new Microsoft.Office.Interop.Excel.Application();

                Microsoft.Office.Interop.Excel.Workbook wb = app.Workbooks.Open(@"D:\Tesco\NGC\Output\temp_02Feb2012.xls", Type.Missing, Type.Missing, Type.Missing, Type.Missing,
                Type.Missing, Type.Missing, Type.Missing, Type.Missing,
                Type.Missing, Type.Missing, Type.Missing, Type.Missing,
                Type.Missing, Type.Missing);

                Worksheet sheet = (Worksheet)wb.Sheets["ExpiredAccount"];
                Range excelRange = sheet.UsedRange;
                Range rng1 = sheet.get_Range("A2", "A2");
                rng1.Value2 = "India";
                Range rng2 = sheet.get_Range("A3", "A3");
                rng2.Value2 = "Good work"; 

               // string A4D4 = GetRange("A" + 2 + ":A" + 2 + "", sheet);

            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

i am trying to open an excel file and an particular sheet called[ExpiredAccount].where i need to set an value in that particular range

here is my code but its not saving the value only, its not throwing any error.

please let me know where i am going wrong it would great if you can help me on this

Gracias príncipe

preguntado el 02 de febrero de 12 a las 10:02

1 Respuestas

you have to save the workbook. and release the runtime callable wrapper.

simply add this code:

wb.Close(true, Type.Missing, Type.Missing); //closes and saves the workbook
app.Quit();
Marshal.FinalReleaseComObject(app); //release the wrapper

p.s. if you weren't releasing the object, I suggest to run the Task manager, check the processes tab, and end all Excel.exe processes... there ought to be a lot of them :)

Respondido 02 Feb 12, 15:02

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.