I'm quite new in handling huge data sets and I'm using C# for this. Now, the data that I'm handling (which is a CSV) has a column of 19 and row of 9,831. When it comes to writing the data into an existing excel file the program take 6 minutes to accomplish its task. I'm looking for suggestions or tips that can reduce the time rendering into seconds. So here's my class or code for writing it to an excel file:
using System;
using System.Data;
using Excel = Microsoft.Office.Interop.Excel;
namespace Project
{
class WriteCsv
{
public WriteCsv(DataTable dt)
{
//sets the existing excel file to be written
Microsoft.Office.Interop.Excel.Application excel = new Microsoft.Office.Interop.Excel.Application();
Microsoft.Office.Interop.Excel.Workbook sheet = excel.Workbooks.Open(@"path to excel file");
Microsoft.Office.Interop.Excel.Worksheet x = excel.ActiveSheet as Microsoft.Office.Interop.Excel.Worksheet;
//selects a specific worksheet to written on
x = (Excel.Worksheet)sheet.Sheets[2];
int rowCount = 1;
int dataColumns = dt.Columns.Count;
//this is where the writing starts
foreach (DataRow dr in dt.Rows)
{
int columnCount = 0;
while (columnCount < dataColumns)
{
x.Cells[rowCount, columnCount + 1] = dr[columnCount];
columnCount++;
}
Console.WriteLine("=====================ROW COMPLETED " + rowCount + "========================");
rowCount++;
}
sheet.Close(true, Type.Missing, Type.Missing);
excel.Quit();
}
}
}