SoloCodigo

CLR: .Net / Mono / Boo / Otros CLR => C# => Mensaje iniciado por: Lockter en Lunes 5 de Mayo de 2008, 13:09

Título: Error Al Exportar A Excel
Publicado por: Lockter en Lunes 5 de Mayo de 2008, 13:09
Hola.

Me ha salido un problema al exportar unos datos del programa a Excel.

Para llamar al excel uso esto

Excel.Application oWB = new Excel.Application();
string a = System.Globalization.CultureInfo.InstalledUICulture.ToString() ;
System.Globalization.CultureInfo oldCI = System.Threading.Thread.CurrentThread.CurrentCulture;
System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo(a);
oWB.Workbooks.Add(Missing.Value);
System.Threading.Thread.CurrentThread.CurrentCulture = oldCI;
Excel._Worksheet oSheet;

Y falla aquí

oSheet.Cells[2, i+1] = ResultatDataView.Columns.HeaderText;


Antes me funcionaba solo con esto

oWB = (Excel._Workbook)(oXL.Workbooks.Add(Missing.Value));
oSheet = (Excel._Worksheet)oWB.ActiveSheet;

En el ordenador que estaba se reinstalo el Windows y el office, me parece que eso tambien tiene algo que ver.

Muchas gracias.
Título: Re: Error Al Exportar A Excel
Publicado por: Arcangel_Asesino en Lunes 5 de Mayo de 2008, 23:20
Podrías decir cual es el error que marca?

así sera mas fácil ayudarte
Título: Re: Error Al Exportar A Excel
Publicado por: Lockter en Martes 6 de Mayo de 2008, 10:07
El error que marca es el 0x800A03EC y no da ningun dato mas.

Pero por suerte ya lo he solucionado.

Al final resulta que estas dos linies han de ir al reves
Código: Text
  1. System.Globalization.CultureInfo oldCI = System.Threading.Thread.CurrentThread.CurrentCulture;
  2. System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo(a);
  3.  

Y quedar asi

Código: Text
  1. System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo(a);
  2. System.Globalization.CultureInfo oldCI = System.Threading.Thread.CurrentThread.CurrentCulture;
  3.