Ver Mensaje Individual
  #1 (permalink)  
Antiguo 29/10/2008, 07:11
vllopico
 
Fecha de Ingreso: septiembre-2006
Mensajes: 94
Antigüedad: 18 años, 7 meses
Puntos: 1
Escribir en Excel con Microsoft.Office.Interop.Excel

Hola compañer@s, estoy utilizando la libreria Microsoft.Office.InterOp.Excel para leer y escribir desde C# a un hoja Excel. Para leer no tengo ningun problema, pero a la hora de escribir no puedo acabar la ejecución del programa. La función es la siguiente:

private void btn_Generar_Click(object sender, System.EventArgs e)
{
string sFile = "C:\\sFile.xls";
string sTemplate = "C:\\Template.xls";
object opc = Missing.Value;

Excel.ApplicationClass excelApp = new Excel.ApplicationClass();
Excel.Workbook excelBook = excelApp.Workbooks.Open (sFile,opc,opc,opc,opc,opc,opc,opc,opc,opc,opc,opc ,opc,opc,opc);
Excel.Worksheet excelSheet = (Excel.Worksheet)excelBook.Sheets.get_Item(1);

excelSheet.Cells[1,1] = "A1";
excelSheet.SaveAs(sFile,opc,opc,opc,opc,opc,opc,op c,opc,opc);

excelApp.Quit();
System.Runtime.InteropServices.Marshal.ReleaseComO bject(excelBook)
System.Runtime.InteropServices.Marshal.ReleaseComO bject(excelSheet);
System.Runtime.InteropServices.Marshal.ReleaseComO bject(excelApp);

excelBook = null;
excelSheet = null;
excelApp = null;
System.GC.Collect();
}

El ejemplo pretende partir de un excel, y escribir en (1,1) A1. Agradecería algun ejemplo válido. Muchas gracias. Salud.