How would you export all the data to the right in the same worksheet? and not in several? From Different DataGridView

  • Thread starter Thread starter OscarMolleapaza
  • Start date Start date
O

OscarMolleapaza

Guest
Microsoft.Office.Interop.Excel.Workbooks workbooks = xlApp.Workbooks;
Microsoft.Office.Interop.Excel.Workbook workbook = workbooks.Add(Microsoft.Office.Interop.Excel.XlWBATemplate.xlWBATWorksheet);
Microsoft.Office.Interop.Excel.Worksheet worksheet = (Microsoft.Office.Interop.Excel.Worksheet)workbook.Worksheets[1];

for (int index = 0; index < dgv.Length; index++)
{
//string[] sheetsCalidad = new string[]{ "TempZonaRec", "TempCalentamiento","TempHomogenizacion","TiemDeshornamiento","TempAustenizacion","TempConformado","TempTemple","FlujoAguaTamb2", "FlujoAguaTamb3","TempAguaTamb1","TempAguaTamb2","VelTamb2","VelTamb3","VelMesEnfr2","TempEcuLadDer","TempSalMesEnfr2" };

for (int i = 0; i < dgv[index].ColumnCount; i++)
{
worksheet.Cells[1, i + 1] = dgv[index].Columns.HeaderText;


}

for (int r = 0; r < dgv[index].Rows.Count; r++)
{
for (int i = 0; i < dgv[index].ColumnCount; i++)
{
worksheet.Cells[r + 2, i + 1] = dgv[index].Rows[r].Cells.Value.ToString();

}
System.Windows.Forms.Application.DoEvents();
}
worksheet.Columns.EntireColumn.AutoFit();
//worksheet.Name = sheetsCalidad[index];
if (index < dgv.Length - 1)
{

//worksheet = (Microsoft.Office.Interop.Excel.Worksheet)workbook.Worksheets.Add();
}
}

Continue reading...
 
Back
Top