
29/12/2009, 05:28
|
| | Fecha de Ingreso: diciembre-2007
Mensajes: 10
Antigüedad: 17 años, 2 meses Puntos: 0 | |
Respuesta: Importar Excel a DataGrid Bueno, al final lo he hecho de una forma un poca mas "rustica",
Código:
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
Microsoft.Office.Interop.Excel.Application xlApp;
Microsoft.Office.Interop.Excel.Workbook xlWorkBook;
Microsoft.Office.Interop.Excel.Worksheet xlWorkSheet;
object misValue = System.Reflection.Missing.Value;
xlApp = new Microsoft.Office.Interop.Excel.ApplicationClass();
xlWorkBook = xlApp.Workbooks.Open(openFileDialog1.FileName, 0, true, 5, "", "", true, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "\t", false, false, 0, true, 1, 0);
xlWorkSheet = (Microsoft.Office.Interop.Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);
//damos valores a los datagridview
//matriz de terminosFuente
for (int j = 0; j < numericUpDownTerminosFuente.Value; j++)
{
for (int i = 0; i < numericUpDownEspecies.Value; i++)
{
Excel.Range rg = (Excel.Range)xlWorkSheet.Cells[j + 2,i + 2 ];
dataGridView1[i, j].Value = rg.Value;
}
}
}
|