ASPForums.Net RSS Feedhttp://www.aspforums.net/Handlers/RSS.ashxLatest additions to the content that appears on ASPForums.Net(c) 2019 www.aspforums.com. All rights reserved.Add CSV file data as WorkSheet to an Excel file using C# in ASP.Net<p>Hi <a class="username" rel="vygi0913"> vygi0913</a>,</p> <p>I have created sample that full-fill your requirement.</p> <p><span style="text-decoration: underline;">Code</span></p> <pre class="brush: csharp">protected void Page_Load(object sender, EventArgs e) { int i = 0; DataTable dt = new DataTable(); dt.Columns.Add(&#34;SourceFile&#34;); dt.Columns.Add(&#34;DestinationFile&#34;); dt.Columns.Add(&#34;Result&#34;); string result = &#34;Passed&#34;; foreach (var line in File.ReadAllLines(Server.MapPath(&#34;CSVs/Compare.csv&#34;))) { string sourceFilePath = line.Split(&#39;;&#39;)[0].Split(&#39;,&#39;)[0]; string destinationFilePath = line.Split(&#39;;&#39;)[0].Split(&#39;,&#39;)[1]; var sourceFile = File.ReadAllLines(sourceFilePath); var destinationFile = File.ReadAllLines(destinationFilePath); var compareFile = from ln in sourceFile from ln1 in destinationFile where ln != ln1 select ln; if (compareFile.ToList().Count &gt; 0) { result = &#34;Failed&#34;; } dt.Rows.Add(sourceFilePath, destinationFilePath, result); i++; } Microsoft.Office.Interop.Excel.Application excel = default(Microsoft.Office.Interop.Excel.Application); Microsoft.Office.Interop.Excel.Workbook workBook = default(Microsoft.Office.Interop.Excel.Workbook); excel = new Microsoft.Office.Interop.Excel.Application(); excel.Visible = true; workBook = excel.Workbooks.Open(Server.MapPath(&#34;~/CSVs/Book1.xls&#34;)); var excelSheets = workBook.Sheets as Microsoft.Office.Interop.Excel.Sheets; var excelNewSheet = (Microsoft.Office.Interop.Excel.Worksheet)excelSheets.Add(excelSheets[excelSheets.Count], Type.Missing, Type.Missing, Type.Missing); excelNewSheet.Name = string.Format(&#34;{0}_{1}&#34;, DateTime.Now.ToShortDateString(), DateTime.Now.ToLongTimeString()).Replace(&#34;/&#34;, &#34;_&#34;).Replace(&#34;:&#34;, &#34;_&#34;); int irow = 1; int col = 1; foreach (DataColumn column in dt.Columns) { excelNewSheet.Cells[irow, col] = column.ColumnName; col++; } foreach (DataRow dr in dt.Rows) { irow += 1; col = 0; foreach (string c in dr.ItemArray) { col += 1; excelNewSheet.Cells[irow, col] = c; } } workBook.Save(); workBook.Close(); excel.Visible = true; excel.UserControl = true; excelNewSheet = null; workBook = null; excel = null; }</pre> <p><span style="text-decoration: underline;">Sceernshot</span></p> <p><img src="https://i.imgur.com/NPGI3li.jpg" alt="" width="472" height="118" /></p>https://www.aspforums.net:443/Threads/182865/Add-CSV-file-data-as-WorkSheet-to-an-Excel-file-using-C-in-ASPNet/https://www.aspforums.net:443/Threads/182865/Add-CSV-file-data-as-WorkSheet-to-an-Excel-file-using-C-in-ASPNet/Tue, 15 Dec 2015 09:25:36 GMT