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.Compare RTF file with Excel file and generate separate RTF file based on group assigned in excel using C# and VB.Net in ASP.Net<p>Hi <a class="username" rel="mod7609"> mod7609</a>,</p> <p>Please paste the RTF and Excel file data here.</p>https://www.aspforums.net:443/Threads/201748/Compare-RTF-file-with-Excel-file-and-generate-separate-RTF-file-based-on-group-assigned-in-excel-using-C-and-VBNet-in-ASPNet/https://www.aspforums.net:443/Threads/201748/Compare-RTF-file-with-Excel-file-and-generate-separate-RTF-file-based-on-group-assigned-in-excel-using-C-and-VBNet-in-ASPNet/Mon, 03 Jul 2017 06:26:03 GMTCompare RTF file with Excel file and generate separate RTF file based on group assigned in excel using C# and VB.Net in ASP.Net<blockquote><cite>dharmendr says:</cite> <p>Hi <a class="username" rel="mod7609"> mod7609</a>,</p> <p>Please paste the RTF and Excel file data here.</p> </blockquote> <p>it was not possible to paste file here but you can find some thing of the data as follow :</p> <p>RTF File :</p> <table> <thead> <tr> <td width="17"> <p><strong>Nr</strong></p> </td> <td width="74"> <p><strong>Case Nr</strong></p> </td> <td width="81"> <p><strong>References </strong></p> </td> <td width="214"> <p><strong>Goods designation</strong></p> </td> <td width="74"> <p><strong>Quantity</strong></p> </td> <td width="89"> <p><strong>Total net weight, kg</strong></p> </td> <td width="89"> <p><strong>Total gross weight, kg</strong></p> </td> <td width="69"> <p><strong>Country of origin</strong></p> </td> </tr> <tr> <td width="17"> <p><strong>&nbsp;</strong></p> </td> <td width="74"> <p><strong>&nbsp;</strong></p> </td> <td width="81"> <p><strong>&nbsp;</strong></p> </td> <td width="214"> <p><strong>&nbsp;</strong></p> </td> <td width="74"> <p><strong>&nbsp;</strong></p> </td> <td width="89"> <p><strong>&nbsp;</strong></p> </td> <td width="89"> <p><strong>&nbsp;</strong></p> </td> <td width="69"> <p><strong>&nbsp;</strong></p> </td> </tr> </thead> <tbody> <tr> <td width="17"> <p><strong>1</strong></p> </td> <td width="74"> <p><strong>126178212</strong></p> </td> <td width="81"> <p>&nbsp;</p> </td> <td width="214"> <p>&nbsp;</p> </td> <td width="74"> <p><strong>64</strong></p> </td> <td width="89"> <p><strong>426,880</strong></p> </td> <td width="89"> <p><strong>451,380</strong></p> </td> <td width="69"> <p>&nbsp;</p> </td> </tr> <tr> <td width="17"> <p>&nbsp;</p> </td> <td width="74"> <p>&nbsp;</p> </td> <td width="81"> <p>8200537190</p> </td> <td width="214"> <p>COMPR</p> <p>&nbsp;</p> </td> <td width="74"> <p>64</p> </td> <td width="89"> <p>426,880</p> </td> <td width="89"> <p>451,380</p> </td> <td width="69"> <p>TH</p> </td> </tr> <tr> <td width="17"> <p><strong>2</strong></p> </td> <td width="74"> <p><strong>126179212</strong></p> </td> <td width="81"> <p>&nbsp;</p> </td> <td width="214"> <p>&nbsp;</p> </td> <td width="74"> <p><strong>64</strong></p> </td> <td width="89"> <p><strong>426,880</strong></p> </td> <td width="89"> <p><strong>451,380</strong></p> </td> <td width="69"> <p>&nbsp;</p> </td> </tr> <tr> <td width="17"> <p>&nbsp;</p> </td> <td width="74"> <p>&nbsp;</p> </td> <td width="81"> <p>8200537190</p> </td> <td width="214"> <p>COMPR</p> <p>&nbsp;</p> </td> <td width="74"> <p>64</p> </td> <td width="89"> <p>426,880</p> </td> <td width="89"> <p>451,380</p> </td> <td width="69"> <p>TH</p> </td> </tr> <tr> <td width="17"> <p><strong>3</strong></p> </td> <td width="74"> <p><strong>130701211</strong></p> </td> <td width="81"> <p>&nbsp;</p> </td> <td width="214"> <p>&nbsp;</p> </td> <td width="74"> <p><strong>480</strong></p> </td> <td width="89"> <p><strong>547,200</strong></p> </td> <td width="89"> <p><strong>571,700</strong></p> </td> <td width="69"> <p>&nbsp;</p> </td> </tr> <tr> <td width="17"> <p>&nbsp;</p> </td> <td width="74"> <p>&nbsp;</p> </td> <td width="81"> <p>765872424R</p> </td> <td width="214"> <p>REINF- SIDE IMPACT RE</p> <p>&nbsp;</p> </td> <td width="74"> <p>480</p> </td> <td width="89"> <p>547,200</p> </td> <td width="89"> <p>571,700</p> </td> <td width="69"> <p>EU</p> </td> </tr> <tr> <td width="17"> <p><strong>4</strong></p> </td> <td width="74"> <p><strong>130718211</strong></p> </td> <td width="81"> <p>&nbsp;</p> </td> <td width="214"> <p>&nbsp;</p> </td> <td width="74"> <p><strong>480</strong></p> </td> <td width="89"> <p><strong>547,200</strong></p> </td> <td width="89"> <p><strong>571,700</strong></p> </td> <td width="69"> <p>&nbsp;</p> </td> </tr> <tr> <td width="17"> <p>&nbsp;</p> </td> <td width="74"> <p>&nbsp;</p> </td> <td width="81"> <p>8200536832</p> </td> <td width="214"> <p>REINF- SIDE IMPACT RE</p> <p>&nbsp;</p> </td> <td width="74"> <p>480</p> </td> <td width="89"> <p>547,200</p> </td> <td width="89"> <p>571,700</p> </td> <td width="69"> <p>EU</p> </td> </tr> <tr> <td width="17"> <p><strong>5</strong></p> </td> <td width="74"> <p><strong>155932212</strong></p> </td> <td width="81"> <p>&nbsp;</p> </td> <td width="214"> <p>&nbsp;</p> </td> <td width="74"> <p><strong>336</strong></p> </td> <td width="89"> <p><strong>493,920</strong></p> </td> <td width="89"> <p><strong>518,420</strong></p> </td> <td width="69"> <p>&nbsp;</p> </td> </tr> <tr> <td width="17"> <p>&nbsp;</p> </td> <td width="74"> <p>&nbsp;</p> </td> <td width="81"> <p>476604621R</p> </td> <td width="214"> <p>UNIT-ABS HYD</p> <p>&nbsp;</p> </td> <td width="74"> <p>336</p> </td> <td width="89"> <p>493,920</p> </td> <td width="89"> <p>518,420</p> </td> <td width="69"> <p>EU</p> </td> </tr> </tbody> </table> <p>&nbsp;</p> <p>Excel file :</p> <table width="303"> <tbody> <tr> <td width="159">Refrences</td> <td width="144">Name of Group</td> </tr> <tr> <td>8200537190</td> <td>Group 1</td> </tr> <tr> <td>8200537190</td> <td>Group 1</td> </tr> <tr> <td>765872424R</td> <td>Group 2</td> </tr> <tr> <td>8200536832</td> <td>Group 1</td> </tr> <tr> <td>476604621R</td> <td>Group 3</td> </tr> </tbody> </table> <p>&nbsp;</p> <p>thanks for your help</p> <p>&nbsp;</p>https://www.aspforums.net:443/Threads/201748/Compare-RTF-file-with-Excel-file-and-generate-separate-RTF-file-based-on-group-assigned-in-excel-using-C-and-VBNet-in-ASPNet/https://www.aspforums.net:443/Threads/201748/Compare-RTF-file-with-Excel-file-and-generate-separate-RTF-file-based-on-group-assigned-in-excel-using-C-and-VBNet-in-ASPNet/Mon, 03 Jul 2017 06:51:00 GMTCompare RTF file with Excel file and generate separate RTF file based on group assigned in excel using C# and VB.Net in ASP.Net<p>Will you please provide the required output?</p>https://www.aspforums.net:443/Threads/201748/Compare-RTF-file-with-Excel-file-and-generate-separate-RTF-file-based-on-group-assigned-in-excel-using-C-and-VBNet-in-ASPNet/https://www.aspforums.net:443/Threads/201748/Compare-RTF-file-with-Excel-file-and-generate-separate-RTF-file-based-on-group-assigned-in-excel-using-C-and-VBNet-in-ASPNet/Mon, 03 Jul 2017 07:22:48 GMTCompare RTF file with Excel file and generate separate RTF file based on group assigned in excel using C# and VB.Net in ASP.Net<blockquote><cite>dharmendr says:</cite> <p>Will you please provide the required output?</p> </blockquote> <p>&nbsp;As you see , all Refrencess are in just one RTF file (5Ref), I want to seperate this refrences with their data based on database and group name, and issue 3 new RTF file <br />for excample one file for Group 1</p> <p>another for Group2</p> <p>and another one for Group 3</p> <p>&nbsp;</p> <p>Thanks</p>https://www.aspforums.net:443/Threads/201748/Compare-RTF-file-with-Excel-file-and-generate-separate-RTF-file-based-on-group-assigned-in-excel-using-C-and-VBNet-in-ASPNet/https://www.aspforums.net:443/Threads/201748/Compare-RTF-file-with-Excel-file-and-generate-separate-RTF-file-based-on-group-assigned-in-excel-using-C-and-VBNet-in-ASPNet/Mon, 03 Jul 2017 07:56:03 GMTCompare RTF file with Excel file and generate separate RTF file based on group assigned in excel using C# and VB.Net in ASP.Net<p>Hi <a class="username" rel="mod7609">mod7609</a>,</p> <p>Your word document contains the record in table format like below or in any other format or in sinple text without table format?</p> <table border="1"> <thead> <tr> <td width="22"> <p><strong>Nr</strong></p> </td> <td width="75"> <p><strong>Case Nr</strong></p> </td> <td width="86"> <p><strong>References </strong></p> </td> <td width="150"> <p><strong>Goods designation</strong></p> </td> <td width="70"> <p><strong>Quantity</strong></p> </td> <td width="73"> <p><strong>Total net weight, kg</strong></p> </td> <td width="73"> <p><strong>Total gross weight, kg</strong></p> </td> <td width="65"> <p><strong>Country of origin</strong></p> </td> </tr> </thead> <tbody> <tr> <td width="22"> <p><strong>1</strong></p> </td> <td width="75"> <p><strong>126178212</strong></p> </td> <td width="86"> <p>&nbsp;</p> </td> <td width="150"> <p>&nbsp;</p> </td> <td width="70"> <p><strong>64</strong></p> </td> <td width="73"> <p><strong>426,880</strong></p> </td> <td width="73"> <p><strong>451,380</strong></p> </td> <td width="65"> <p>&nbsp;</p> </td> </tr> <tr> <td width="22"> <p>&nbsp;</p> </td> <td width="75"> <p>&nbsp;</p> </td> <td width="86"> <p>8200537190</p> </td> <td width="150"> <p>COMPR</p> <p>&nbsp;</p> </td> <td width="70"> <p>64</p> </td> <td width="73"> <p>426,880</p> </td> <td width="73"> <p>451,380</p> </td> <td width="65"> <p>TH</p> </td> </tr> <tr> <td width="22"> <p><strong>2</strong></p> </td> <td width="75"> <p><strong>126179212</strong></p> </td> <td width="86"> <p>&nbsp;</p> </td> <td width="150"> <p>&nbsp;</p> </td> <td width="70"> <p><strong>64</strong></p> </td> <td width="73"> <p><strong>426,880</strong></p> </td> <td width="73"> <p><strong>451,380</strong></p> </td> <td width="65"> <p>&nbsp;</p> </td> </tr> <tr> <td width="22"> <p>&nbsp;</p> </td> <td width="75"> <p>&nbsp;</p> </td> <td width="86"> <p>8200537190</p> </td> <td width="150"> <p>COMPR</p> <p>&nbsp;</p> </td> <td width="70"> <p>64</p> </td> <td width="73"> <p>426,880</p> </td> <td width="73"> <p>451,380</p> </td> <td width="65"> <p>TH</p> </td> </tr> <tr> <td width="22"> <p><strong>3</strong></p> </td> <td width="75"> <p><strong>130701211</strong></p> </td> <td width="86"> <p>&nbsp;</p> </td> <td width="150"> <p>&nbsp;</p> </td> <td width="70"> <p><strong>480</strong></p> </td> <td width="73"> <p><strong>547,200</strong></p> </td> <td width="73"> <p><strong>571,700</strong></p> </td> <td width="65"> <p>&nbsp;</p> </td> </tr> <tr> <td width="22"> <p>&nbsp;</p> </td> <td width="75"> <p>&nbsp;</p> </td> <td width="86"> <p>765872424R</p> </td> <td width="150"> <p>REINF- SIDE IMPACT RE</p> <p>&nbsp;</p> </td> <td width="70"> <p>480</p> </td> <td width="73"> <p>547,200</p> </td> <td width="73"> <p>571,700</p> </td> <td width="65"> <p>EU</p> </td> </tr> <tr> <td width="22"> <p><strong>4</strong></p> </td> <td width="75"> <p><strong>130718211</strong></p> </td> <td width="86"> <p>&nbsp;</p> </td> <td width="150"> <p>&nbsp;</p> </td> <td width="70"> <p><strong>480</strong></p> </td> <td width="73"> <p><strong>547,200</strong></p> </td> <td width="73"> <p><strong>571,700</strong></p> </td> <td width="65"> <p>&nbsp;</p> </td> </tr> <tr> <td width="22"> <p>&nbsp;</p> </td> <td width="75"> <p>&nbsp;</p> </td> <td width="86"> <p>8200536832</p> </td> <td width="150"> <p>REINF- SIDE IMPACT RE</p> <p>&nbsp;</p> </td> <td width="70"> <p>480</p> </td> <td width="73"> <p>547,200</p> </td> <td width="73"> <p>571,700</p> </td> <td width="65"> <p>EU</p> </td> </tr> <tr> <td width="22"> <p><strong>5</strong></p> </td> <td width="75"> <p><strong>155932212</strong></p> </td> <td width="86"> <p>&nbsp;</p> </td> <td width="150"> <p>&nbsp;</p> </td> <td width="70"> <p><strong>336</strong></p> </td> <td width="73"> <p><strong>493,920</strong></p> </td> <td width="73"> <p><strong>518,420</strong></p> </td> <td width="65"> <p>&nbsp;</p> </td> </tr> <tr> <td width="22"> <p>&nbsp;</p> </td> <td width="75"> <p>&nbsp;</p> </td> <td width="86"> <p>476604621R</p> </td> <td width="150"> <p>UNIT-ABS HYD</p> <p>&nbsp;</p> </td> <td width="70"> <p>336</p> </td> <td width="73"> <p>493,920</p> </td> <td width="73"> <p>518,420</p> </td> <td width="65"> <p>EU</p> </td> </tr> </tbody> </table>https://www.aspforums.net:443/Threads/201748/Compare-RTF-file-with-Excel-file-and-generate-separate-RTF-file-based-on-group-assigned-in-excel-using-C-and-VBNet-in-ASPNet/https://www.aspforums.net:443/Threads/201748/Compare-RTF-file-with-Excel-file-and-generate-separate-RTF-file-based-on-group-assigned-in-excel-using-C-and-VBNet-in-ASPNet/Thu, 06 Jul 2017 03:37:25 GMTCompare RTF file with Excel file and generate separate RTF file based on group assigned in excel using C# and VB.Net in ASP.Net<blockquote><cite>dharmendr says:</cite> <p>Hi <a class="username" rel="mod7609">mod7609</a>,</p> <p>Your word document contains the record in table format like below or in any other format or in sinple text without table format?</p> <table border="1"> <thead> <tr> <td width="22"> <p><strong>Nr</strong></p> </td> <td width="75"> <p><strong>Case Nr</strong></p> </td> <td width="86"> <p><strong>References </strong></p> </td> <td width="150"> <p><strong>Goods designation</strong></p> </td> <td width="70"> <p><strong>Quantity</strong></p> </td> <td width="73"> <p><strong>Total net weight, kg</strong></p> </td> <td width="73"> <p><strong>Total gross weight, kg</strong></p> </td> <td width="65"> <p><strong>Country of origin</strong></p> </td> </tr> </thead> <tbody> <tr> <td width="22"> <p><strong>1</strong></p> </td> <td width="75"> <p><strong>126178212</strong></p> </td> <td width="86"> <p>&nbsp;</p> </td> <td width="150"> <p>&nbsp;</p> </td> <td width="70"> <p><strong>64</strong></p> </td> <td width="73"> <p><strong>426,880</strong></p> </td> <td width="73"> <p><strong>451,380</strong></p> </td> <td width="65"> <p>&nbsp;</p> </td> </tr> <tr> <td width="22"> <p>&nbsp;</p> </td> <td width="75"> <p>&nbsp;</p> </td> <td width="86"> <p>8200537190</p> </td> <td width="150"> <p>COMPR</p> <p>&nbsp;</p> </td> <td width="70"> <p>64</p> </td> <td width="73"> <p>426,880</p> </td> <td width="73"> <p>451,380</p> </td> <td width="65"> <p>TH</p> </td> </tr> <tr> <td width="22"> <p><strong>2</strong></p> </td> <td width="75"> <p><strong>126179212</strong></p> </td> <td width="86"> <p>&nbsp;</p> </td> <td width="150"> <p>&nbsp;</p> </td> <td width="70"> <p><strong>64</strong></p> </td> <td width="73"> <p><strong>426,880</strong></p> </td> <td width="73"> <p><strong>451,380</strong></p> </td> <td width="65"> <p>&nbsp;</p> </td> </tr> <tr> <td width="22"> <p>&nbsp;</p> </td> <td width="75"> <p>&nbsp;</p> </td> <td width="86"> <p>8200537190</p> </td> <td width="150"> <p>COMPR</p> <p>&nbsp;</p> </td> <td width="70"> <p>64</p> </td> <td width="73"> <p>426,880</p> </td> <td width="73"> <p>451,380</p> </td> <td width="65"> <p>TH</p> </td> </tr> <tr> <td width="22"> <p><strong>3</strong></p> </td> <td width="75"> <p><strong>130701211</strong></p> </td> <td width="86"> <p>&nbsp;</p> </td> <td width="150"> <p>&nbsp;</p> </td> <td width="70"> <p><strong>480</strong></p> </td> <td width="73"> <p><strong>547,200</strong></p> </td> <td width="73"> <p><strong>571,700</strong></p> </td> <td width="65"> <p>&nbsp;</p> </td> </tr> <tr> <td width="22"> <p>&nbsp;</p> </td> <td width="75"> <p>&nbsp;</p> </td> <td width="86"> <p>765872424R</p> </td> <td width="150"> <p>REINF- SIDE IMPACT RE</p> <p>&nbsp;</p> </td> <td width="70"> <p>480</p> </td> <td width="73"> <p>547,200</p> </td> <td width="73"> <p>571,700</p> </td> <td width="65"> <p>EU</p> </td> </tr> <tr> <td width="22"> <p><strong>4</strong></p> </td> <td width="75"> <p><strong>130718211</strong></p> </td> <td width="86"> <p>&nbsp;</p> </td> <td width="150"> <p>&nbsp;</p> </td> <td width="70"> <p><strong>480</strong></p> </td> <td width="73"> <p><strong>547,200</strong></p> </td> <td width="73"> <p><strong>571,700</strong></p> </td> <td width="65"> <p>&nbsp;</p> </td> </tr> <tr> <td width="22"> <p>&nbsp;</p> </td> <td width="75"> <p>&nbsp;</p> </td> <td width="86"> <p>8200536832</p> </td> <td width="150"> <p>REINF- SIDE IMPACT RE</p> <p>&nbsp;</p> </td> <td width="70"> <p>480</p> </td> <td width="73"> <p>547,200</p> </td> <td width="73"> <p>571,700</p> </td> <td width="65"> <p>EU</p> </td> </tr> <tr> <td width="22"> <p><strong>5</strong></p> </td> <td width="75"> <p><strong>155932212</strong></p> </td> <td width="86"> <p>&nbsp;</p> </td> <td width="150"> <p>&nbsp;</p> </td> <td width="70"> <p><strong>336</strong></p> </td> <td width="73"> <p><strong>493,920</strong></p> </td> <td width="73"> <p><strong>518,420</strong></p> </td> <td width="65"> <p>&nbsp;</p> </td> </tr> <tr> <td width="22"> <p>&nbsp;</p> </td> <td width="75"> <p>&nbsp;</p> </td> <td width="86"> <p>476604621R</p> </td> <td width="150"> <p>UNIT-ABS HYD</p> <p>&nbsp;</p> </td> <td width="70"> <p>336</p> </td> <td width="73"> <p>493,920</p> </td> <td width="73"> <p>518,420</p> </td> <td width="65"> <p>EU</p> </td> </tr> </tbody> </table> </blockquote> <p>&nbsp;yes, like this format</p>https://www.aspforums.net:443/Threads/201748/Compare-RTF-file-with-Excel-file-and-generate-separate-RTF-file-based-on-group-assigned-in-excel-using-C-and-VBNet-in-ASPNet/https://www.aspforums.net:443/Threads/201748/Compare-RTF-file-with-Excel-file-and-generate-separate-RTF-file-based-on-group-assigned-in-excel-using-C-and-VBNet-in-ASPNet/Fri, 07 Jul 2017 04:43:49 GMTCompare RTF file with Excel file and generate separate RTF file based on group assigned in excel using C# and VB.Net in ASP.Net<p>I will get back to you on monday.</p>https://www.aspforums.net:443/Threads/201748/Compare-RTF-file-with-Excel-file-and-generate-separate-RTF-file-based-on-group-assigned-in-excel-using-C-and-VBNet-in-ASPNet/https://www.aspforums.net:443/Threads/201748/Compare-RTF-file-with-Excel-file-and-generate-separate-RTF-file-based-on-group-assigned-in-excel-using-C-and-VBNet-in-ASPNet/Fri, 07 Jul 2017 10:27:20 GMTCompare RTF file with Excel file and generate separate RTF file based on group assigned in excel using C# and VB.Net in ASP.Net<p>Hi <a class="username" rel="mod7609"> mod7609</a>,</p> <p>I have written code to read excel and word file and retrive the data to DataTable. Now you need to check the code and compare the datatable and based on your condition you need to write the code and create separete word file. Try this from your end and let me know. If any issue then revert me back.</p> <p><span style="text-decoration: underline;">C#</span></p> <pre class="brush: csharp">// Read table from word document and return DataTable private DataTable ReadWord() { DataTable dt = new DataTable(&#34;Word&#34;); Word.Application word = new Word.Application(); Word.Document doc = new Word.Document(); object filePath = Server.MapPath(&#34;~/Files/Test.rtf&#34;); object missing = System.Type.Missing; try { doc = word.Documents.Open(ref filePath, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing); // Columns for (int i = 1; i &lt;= word.Application.ActiveDocument.Tables[1].Rows[1].Cells.Count; i++) { dt.Columns.Add(word.Application.ActiveDocument.Tables[1].Rows[1].Cells[i].Range.Text.Replace(&#34;\r\a&#34;, &#34;&#34;).Trim()); } // Rows for (int i = 2; i &lt; word.Application.ActiveDocument.Tables[1].Rows.Count; i++) { Word.Row tableRow = word.Application.ActiveDocument.Tables[1].Rows[i]; dt.Rows.Add(dt.NewRow()); for (int j = 1; j &lt;= tableRow.Cells.Count; j++) { dt.Rows[i - 2][j - 1] = tableRow.Cells[j].Range.Text.Replace(&#34;\r\a&#34;, &#34;&#34;).Trim(); } } } catch (Exception ex) { Response.Write(ex.Message); } finally { ((Word._Application)word).Quit(); } return dt; } // Read excel file and return DataTable. private DataTable ExcelToDataSet() { DataTable dt = new DataTable(&#34;Excel&#34;); string filePath = Server.MapPath(&#34;~/Files/Test.xlsx&#34;); string extension = Path.GetExtension(filePath); using (XLWorkbook workBook = new XLWorkbook(filePath)) { //Read the first Sheet from Excel file. IXLWorksheet workSheet = workBook.Worksheet(1); //Loop through the Worksheet rows. bool firstRow = true; foreach (IXLRow row in workSheet.Rows()) { //Use the first row to add columns to DataTable. if (firstRow) { foreach (IXLCell cell in row.Cells()) { dt.Columns.Add(cell.Value.ToString()); } firstRow = false; } else { //Add rows to DataTable. dt.Rows.Add(); int i = 0; foreach (IXLCell cell in row.Cells()) { dt.Rows[dt.Rows.Count - 1][i] = cell.Value.ToString(); i++; } } } return dt; } }</pre> <p>&nbsp;</p>https://www.aspforums.net:443/Threads/201748/Compare-RTF-file-with-Excel-file-and-generate-separate-RTF-file-based-on-group-assigned-in-excel-using-C-and-VBNet-in-ASPNet/https://www.aspforums.net:443/Threads/201748/Compare-RTF-file-with-Excel-file-and-generate-separate-RTF-file-based-on-group-assigned-in-excel-using-C-and-VBNet-in-ASPNet/Tue, 11 Jul 2017 02:12:28 GMTCompare RTF file with Excel file and generate separate RTF file based on group assigned in excel using C# and VB.Net in ASP.Net<p>Hi <a class="username" rel="mod7609"> mod7609</a>,</p> <p>I have created a sample that full fill your requirement. After a lot of work around i am able to do it. Refer the below sample.</p> <p><strong><span style="text-decoration: underline;">C#</span></strong></p> <pre class="brush: csharp">using System; using System.Collections.Generic; using System.Data; using System.IO; using System.Linq; using ClosedXML.Excel; using DocumentFormat.OpenXml; using DocumentFormat.OpenXml.Packaging; using DocumentFormat.OpenXml.Wordprocessing; using Word = Microsoft.Office.Interop.Word; public partial class CS : System.Web.UI.Page { &nbsp;&nbsp;&nbsp; protected void Page_Load(object sender, EventArgs e) &nbsp;&nbsp;&nbsp; { &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; List&lt;DataTable&gt; result = MergeWordExcelWithGroup().AsEnumerable() &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .GroupBy(row =&gt; row.Field&lt;string&gt;(&#34;Group&#34;)) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .Select(g =&gt; g.CopyToDataTable()).ToList(); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for (int i = 0; i &lt; result.Count; i++) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; { &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; DataTable dt = result[i]; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; string groupName = dt.Rows[0][&#34;Group&#34;].ToString(); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; dt.Columns.Remove(&#34;Group&#34;); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; CreateWordtable(dt, @&#34;C:\Users\dharmendra\Desktop\&#34; + groupName + &#34;.rtf&#34;); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } &nbsp;&nbsp;&nbsp; } &nbsp;&nbsp;&nbsp; public void CreateWordtable(DataTable dt, string filePath) &nbsp;&nbsp;&nbsp; { &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (dt.Rows.Count &gt; 0) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; { &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // Adding header. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; DataRow headerRow = dt.NewRow(); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for (int i = 0; i &lt; dt.Columns.Count; i++) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; { &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; headerRow[i] = dt.Columns[i].ColumnName; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; dt.Rows.InsertAt(headerRow, 0); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // Creating WordDocument. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; WordprocessingDocument document = WordprocessingDocument.Create(filePath, WordprocessingDocumentType.Document); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MainDocumentPart mainDocumentPart = document.AddMainDocumentPart(); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; mainDocumentPart.Document = new Document(); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Body body = new Body(); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; mainDocumentPart.Document.Append(body); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // Creating Table. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Table table = new Table(); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; TableProperties props = new TableProperties(new TableBorders( &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; new TopBorder { Val = new EnumValue&lt;BorderValues&gt;(BorderValues.Single), Size = 1 }, &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; new BottomBorder { Val = new EnumValue&lt;BorderValues&gt;(BorderValues.Single), Size = 1 }, &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; new LeftBorder { Val = new EnumValue&lt;BorderValues&gt;(BorderValues.Single), Size = 1 }, &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; new RightBorder { Val = new EnumValue&lt;BorderValues&gt;(BorderValues.Single), Size = 1 }, &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; new InsideHorizontalBorder { Val = new EnumValue&lt;BorderValues&gt;(BorderValues.Single), Size = 1 }, &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; new InsideVerticalBorder { Val = new EnumValue&lt;BorderValues&gt;(BorderValues.Single), Size = 1 })); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; table.AppendChild&lt;TableProperties&gt;(props); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for (int i = 0; i &lt; dt.Rows.Count; ++i) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; { &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // Creating Rows. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; TableRow row = new TableRow(); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for (int j = 0; j &lt; dt.Columns.Count; j++) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; { &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; TableCell cell = new TableCell(); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cell.Append(new TableCellProperties(new TableCellWidth { Type = TableWidthUnitValues.Dxa, Width = &#34;1200&#34; })); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cell.Append(new Paragraph(new Run(new Text(dt.Rows[i][j].ToString())))); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; row.Append(cell); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; table.Append(row); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; body.Append(table); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // Saving Document. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; document.MainDocumentPart.Document.Save(); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; document.Dispose(); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } &nbsp;&nbsp;&nbsp; } &nbsp;&nbsp;&nbsp; private DataTable MergeWordExcelWithGroup() &nbsp;&nbsp;&nbsp; { &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; DataSet ds = new DataSet(); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ds.Tables.Add(ExcelToDataTable()); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ds.Tables.Add(WordTableToDataTable()); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; DataTable dtWithGroup = ds.Tables[&#34;Word&#34;].Clone(); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; dtWithGroup.Columns.Add(&#34;Group&#34;); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for (int i = 0; i &lt; ds.Tables[&#34;Excel&#34;].Rows.Count; i++) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; { &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; string excelRefrence = ds.Tables[&#34;Excel&#34;].Rows[i][&#34;Refrences&#34;].ToString(); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; string nameOfGroup = ds.Tables[&#34;Excel&#34;].Rows[i][&#34;Name of Group&#34;].ToString(); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for (int j = 0; j &lt; ds.Tables[&#34;Word&#34;].Rows.Count; j++) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; { &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; string nrCurrent = ds.Tables[&#34;Word&#34;].Rows[j][&#34;Nr&#34;].ToString(); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; string caseNrCurrent = ds.Tables[&#34;Word&#34;].Rows[j][&#34;Case Nr&#34;].ToString(); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; string wordRefrenceCurrent = ds.Tables[&#34;Word&#34;].Rows[j][&#34;References&#34;].ToString(); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; string goodsDesignationCurrent = ds.Tables[&#34;Word&#34;].Rows[j][&#34;Goods designation&#34;].ToString(); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; string quantityCurrent = ds.Tables[&#34;Word&#34;].Rows[j][&#34;Quantity&#34;].ToString(); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; string totalNetWeightCurrent = ds.Tables[&#34;Word&#34;].Rows[j][&#34;Total net weight, kg&#34;].ToString(); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; string totalGrossWeightCurrent = ds.Tables[&#34;Word&#34;].Rows[j][&#34;Total gross weight, kg&#34;].ToString(); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; string countryCurrent = ds.Tables[&#34;Word&#34;].Rows[j][&#34;Country of origin&#34;].ToString(); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (!string.IsNullOrEmpty(excelRefrence)) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; { &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (excelRefrence.ToLower() == wordRefrenceCurrent.ToLower()) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; { &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; string nrPrevious = ds.Tables[&#34;Word&#34;].Rows[j - 1][&#34;Nr&#34;].ToString(); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; string caseNrPrevious = ds.Tables[&#34;Word&#34;].Rows[j - 1][&#34;Case Nr&#34;].ToString(); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; string wordRefrencePrevious = ds.Tables[&#34;Word&#34;].Rows[j - 1][&#34;References&#34;].ToString(); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; string goodsDesignationPrevious = ds.Tables[&#34;Word&#34;].Rows[j - 1][&#34;Goods designation&#34;].ToString(); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; string quantityPrevious = ds.Tables[&#34;Word&#34;].Rows[j - 1][&#34;Quantity&#34;].ToString(); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; string totalNetWeightPrevious = ds.Tables[&#34;Word&#34;].Rows[j - 1][&#34;Total net weight, kg&#34;].ToString(); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; string totalGrossWeightPrevious = ds.Tables[&#34;Word&#34;].Rows[j - 1][&#34;Total gross weight, kg&#34;].ToString(); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; string countryPrevious = ds.Tables[&#34;Word&#34;].Rows[j - 1][&#34;Country of origin&#34;].ToString(); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; dtWithGroup.Rows.Add(nrPrevious, caseNrPrevious, wordRefrencePrevious, goodsDesignationPrevious, quantityPrevious, totalNetWeightPrevious, totalGrossWeightPrevious, countryPrevious, nameOfGroup); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; dtWithGroup.Rows.Add(nrCurrent, caseNrCurrent, wordRefrenceCurrent, goodsDesignationCurrent, quantityCurrent, totalNetWeightCurrent, totalGrossWeightCurrent, countryCurrent, nameOfGroup); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return dtWithGroup; &nbsp;&nbsp;&nbsp; } &nbsp;&nbsp;&nbsp; private DataTable WordTableToDataTable() &nbsp;&nbsp;&nbsp; { &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; DataTable dt = new DataTable(&#34;Word&#34;); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Word.Application word = new Word.Application(); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Word.Document doc = new Word.Document(); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; object filePath = Server.MapPath(&#34;~/Files/Test.rtf&#34;); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; object missing = System.Type.Missing; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; try &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; { &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; doc = word.Documents.Open(ref filePath, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // Columns&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for (int i = 1; i &lt;= word.Application.ActiveDocument.Tables[1].Rows[1].Cells.Count; i++) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; { &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; dt.Columns.Add(word.Application.ActiveDocument.Tables[1].Rows[1].Cells[i].Range.Text.Replace(&#34;\r\a&#34;, &#34;&#34;).Trim()); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // Rows &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for (int i = 2; i &lt;= word.Application.ActiveDocument.Tables[1].Rows.Count; i++) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; { &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Word.Row tableRow = word.Application.ActiveDocument.Tables[1].Rows[i]; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; dt.Rows.Add(dt.NewRow()); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for (int j = 1; j &lt;= tableRow.Cells.Count; j++) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; { &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; dt.Rows[i - 2][j - 1] = tableRow.Cells[j].Range.Text.Replace(&#34;\r\a&#34;, &#34;&#34;).Trim(); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; catch (Exception ex) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; { &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Response.Write(ex.Message); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; finally &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; { &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ((Word._Application)word).Quit(); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return dt; &nbsp;&nbsp;&nbsp; } &nbsp;&nbsp;&nbsp; private DataTable ExcelToDataTable() &nbsp;&nbsp;&nbsp; { &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; DataTable dt = new DataTable(&#34;Excel&#34;); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; string filePath = Server.MapPath(&#34;~/Files/Test.xlsx&#34;); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; string extension = Path.GetExtension(filePath); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; using (XLWorkbook workBook = new XLWorkbook(filePath)) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; { &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //Read the first Sheet from Excel file. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; IXLWorksheet workSheet = workBook.Worksheet(1); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //Loop through the Worksheet rows. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; bool firstRow = true; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; foreach (IXLRow row in workSheet.Rows()) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; { &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //Use the first row to add columns to DataTable. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (firstRow) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; { &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; foreach (IXLCell cell in row.Cells()) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; { &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; dt.Columns.Add(cell.Value.ToString()); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; firstRow = false; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; { &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //Add rows to DataTable. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; dt.Rows.Add(); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; int i = 0; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; foreach (IXLCell cell in row.Cells()) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; { &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; dt.Rows[dt.Rows.Count - 1][i] = cell.Value.ToString(); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; i++; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return dt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } &nbsp;&nbsp;&nbsp; } }</pre> <p><strong><span style="text-decoration: underline;">VB.Net</span></strong></p> <pre class="brush: vb">Imports DocumentFormat.OpenXml.Packaging Imports DocumentFormat.OpenXml Imports DocumentFormat.OpenXml.Wordprocessing Imports Microsoft.Office.Interop Imports System.IO Imports ClosedXML.Excel Partial Class VB Inherits System.Web.UI.Page Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load Dim result As List(Of DataTable) = MergeWordExcelWithGroup().AsEnumerable() _ .GroupBy(Function(row) row.Field(Of String)(&#34;Group&#34;)) _ .[Select](Function(g) g.CopyToDataTable()) _ .ToList() For i As Integer = 0 To result.Count - 1 Dim dt As DataTable = result(i) Dim groupName As String = dt.Rows(0)(&#34;Group&#34;).ToString() dt.Columns.Remove(&#34;Group&#34;) CreateWordtable(dt, (Convert.ToString(&#34;C:\Users\dharmendra\Desktop\&#34;) &amp; groupName) + &#34;.rtf&#34;) Next End Sub Public Sub CreateWordtable(dt As DataTable, filePath As String) If dt.Rows.Count &gt; 0 Then &#39; Adding header. Dim headerRow As DataRow = dt.NewRow() For i As Integer = 0 To dt.Columns.Count - 1 headerRow(i) = dt.Columns(i).ColumnName Next dt.Rows.InsertAt(headerRow, 0) &#39; Creating WordDocument. Dim document As WordprocessingDocument = WordprocessingDocument.Create(filePath, WordprocessingDocumentType.Document) Dim mainDocumentPart As MainDocumentPart = document.AddMainDocumentPart() mainDocumentPart.Document = New Wordprocessing.Document() Dim body As New Wordprocessing.Body() mainDocumentPart.Document.Append(body) &#39; Creating Table. Dim table As New Table() Dim props As New TableProperties(New TableBorders( New TopBorder() With {.Val = New EnumValue(Of BorderValues)(BorderValues.[Single]), .Size = 1}, New BottomBorder() With {.Val = New EnumValue(Of BorderValues)(BorderValues.[Single]), .Size = 1}, New LeftBorder() With {.Val = New EnumValue(Of BorderValues)(BorderValues.[Single]), .Size = 1}, New RightBorder() With {.Val = New EnumValue(Of BorderValues)(BorderValues.[Single]), .Size = 1}, New InsideHorizontalBorder() With {.Val = New EnumValue(Of BorderValues)(BorderValues.[Single]), .Size = 1}, New InsideVerticalBorder() With {.Val = New EnumValue(Of BorderValues)(BorderValues.[Single]), .Size = 1})) table.AppendChild(Of TableProperties)(props) For i As Integer = 0 To dt.Rows.Count - 1 &#39; Creating Rows. Dim row As New TableRow() For j As Integer = 0 To dt.Columns.Count - 1 Dim cell As New TableCell() cell.Append(New TableCellProperties(New TableCellWidth() With {.Type = TableWidthUnitValues.Dxa, .Width = &#34;1200&#34;})) cell.Append(New Paragraph(New Run(New Text(dt.Rows(i)(j).ToString())))) row.Append(cell) Next table.Append(row) Next body.Append(table) &#39; Saving Document. document.MainDocumentPart.Document.Save() document.Dispose() End If End Sub Private Function MergeWordExcelWithGroup() As DataTable Dim ds As New DataSet() ds.Tables.Add(ExcelToDataTable()) ds.Tables.Add(WordTableToDataTable()) Dim dtWithGroup As DataTable = ds.Tables(&#34;Word&#34;).Clone() dtWithGroup.Columns.Add(&#34;Group&#34;) For i As Integer = 0 To ds.Tables(&#34;Excel&#34;).Rows.Count - 1 Dim excelRefrence As String = ds.Tables(&#34;Excel&#34;).Rows(i)(&#34;Refrences&#34;).ToString() Dim nameOfGroup As String = ds.Tables(&#34;Excel&#34;).Rows(i)(&#34;Name of Group&#34;).ToString() For j As Integer = 0 To ds.Tables(&#34;Word&#34;).Rows.Count - 1 Dim nrCurrent As String = ds.Tables(&#34;Word&#34;).Rows(j)(&#34;Nr&#34;).ToString() Dim caseNrCurrent As String = ds.Tables(&#34;Word&#34;).Rows(j)(&#34;Case Nr&#34;).ToString() Dim wordRefrenceCurrent As String = ds.Tables(&#34;Word&#34;).Rows(j)(&#34;References&#34;).ToString() Dim goodsDesignationCurrent As String = ds.Tables(&#34;Word&#34;).Rows(j)(&#34;Goods designation&#34;).ToString() Dim quantityCurrent As String = ds.Tables(&#34;Word&#34;).Rows(j)(&#34;Quantity&#34;).ToString() Dim totalNetWeightCurrent As String = ds.Tables(&#34;Word&#34;).Rows(j)(&#34;Total net weight, kg&#34;).ToString() Dim totalGrossWeightCurrent As String = ds.Tables(&#34;Word&#34;).Rows(j)(&#34;Total gross weight, kg&#34;).ToString() Dim countryCurrent As String = ds.Tables(&#34;Word&#34;).Rows(j)(&#34;Country of origin&#34;).ToString() If Not String.IsNullOrEmpty(excelRefrence) Then If excelRefrence.ToLower() = wordRefrenceCurrent.ToLower() Then Dim nrPrevious As String = ds.Tables(&#34;Word&#34;).Rows(j - 1)(&#34;Nr&#34;).ToString() Dim caseNrPrevious As String = ds.Tables(&#34;Word&#34;).Rows(j - 1)(&#34;Case Nr&#34;).ToString() Dim wordRefrencePrevious As String = ds.Tables(&#34;Word&#34;).Rows(j - 1)(&#34;References&#34;).ToString() Dim goodsDesignationPrevious As String = ds.Tables(&#34;Word&#34;).Rows(j - 1)(&#34;Goods designation&#34;).ToString() Dim quantityPrevious As String = ds.Tables(&#34;Word&#34;).Rows(j - 1)(&#34;Quantity&#34;).ToString() Dim totalNetWeightPrevious As String = ds.Tables(&#34;Word&#34;).Rows(j - 1)(&#34;Total net weight, kg&#34;).ToString() Dim totalGrossWeightPrevious As String = ds.Tables(&#34;Word&#34;).Rows(j - 1)(&#34;Total gross weight, kg&#34;).ToString() Dim countryPrevious As String = ds.Tables(&#34;Word&#34;).Rows(j - 1)(&#34;Country of origin&#34;).ToString() dtWithGroup.Rows.Add(nrPrevious, caseNrPrevious, wordRefrencePrevious, goodsDesignationPrevious, quantityPrevious, totalNetWeightPrevious, _ totalGrossWeightPrevious, countryPrevious, nameOfGroup) dtWithGroup.Rows.Add(nrCurrent, caseNrCurrent, wordRefrenceCurrent, goodsDesignationCurrent, quantityCurrent, totalNetWeightCurrent, _ totalGrossWeightCurrent, countryCurrent, nameOfGroup) End If End If Next Next Return dtWithGroup End Function Private Function WordTableToDataTable() As DataTable Dim dt As New DataTable(&#34;Word&#34;) Dim word As New Word.Application() Dim doc As New Word.Document() Dim filePath As Object = Server.MapPath(&#34;~/Files/Test.rtf&#34;) Dim missing As Object = System.Type.Missing Try doc = word.Documents.Open(filePath, missing, missing, missing, missing, missing, _ missing, missing, missing, missing, missing, missing, missing, missing, missing, missing) &#39; Columns For i As Integer = 1 To word.Application.ActiveDocument.Tables(1).Rows(1).Cells.Count dt.Columns.Add(word.Application.ActiveDocument.Tables(1).Rows(1).Cells(i).Range.Text.Replace(vbCr &amp; ChrW(7), &#34;&#34;).Trim()) Next &#39; Rows For i As Integer = 2 To word.Application.ActiveDocument.Tables(1).Rows.Count Dim tableRow As Word.Row = word.Application.ActiveDocument.Tables(1).Rows(i) dt.Rows.Add(dt.NewRow()) For j As Integer = 1 To tableRow.Cells.Count dt.Rows(i - 2)(j - 1) = tableRow.Cells(j).Range.Text.Replace(vbCr &amp; ChrW(7), &#34;&#34;).Trim() Next Next Catch ex As Exception Response.Write(ex.Message) Finally DirectCast(word, Word._Application).Quit() End Try Return dt End Function Private Function ExcelToDataTable() As DataTable Dim dt As New DataTable(&#34;Excel&#34;) Dim filePath As String = Server.MapPath(&#34;~/Files/Test.xlsx&#34;) Dim extension As String = Path.GetExtension(filePath) Using workBook As New XLWorkbook(filePath) &#39;Read the first Sheet from Excel file. Dim workSheet As IXLWorksheet = workBook.Worksheet(1) &#39;Loop through the Worksheet rows. Dim firstRow As Boolean = True For Each row As IXLRow In workSheet.Rows() &#39;Use the first row to add columns to DataTable. If firstRow Then For Each cell As IXLCell In row.Cells() dt.Columns.Add(cell.Value.ToString()) Next firstRow = False Else &#39;Add rows to DataTable. dt.Rows.Add() Dim i As Integer = 0 For Each cell As IXLCell In row.Cells() dt.Rows(dt.Rows.Count - 1)(i) = cell.Value.ToString() i += 1 Next End If Next Return dt End Using End Function End Class</pre> <p><strong><span style="text-decoration: underline;">Input file</span></strong></p> <p><span style="text-decoration: underline;">Test.rtf</span></p> <table border="1"> <thead> <tr> <td width="22"> <p><strong>Nr</strong></p> </td> <td width="75"> <p><strong>Case Nr</strong></p> </td> <td width="86"> <p><strong>References </strong></p> </td> <td width="150"> <p><strong>Goods designation</strong></p> </td> <td width="70"> <p><strong>Quantity</strong></p> </td> <td width="73"> <p><strong>Total net weight, kg</strong></p> </td> <td width="73"> <p><strong>Total gross weight, kg</strong></p> </td> <td width="65"> <p><strong>Country of origin</strong></p> </td> </tr> </thead> <tbody> <tr> <td width="22"> <p><strong>1</strong></p> </td> <td width="75"> <p><strong>126178212</strong></p> </td> <td width="86"> <p>&nbsp;</p> </td> <td width="150"> <p>&nbsp;</p> </td> <td width="70"> <p><strong>64</strong></p> </td> <td width="73"> <p><strong>426,880</strong></p> </td> <td width="73"> <p><strong>451,380</strong></p> </td> <td width="65"> <p>&nbsp;</p> </td> </tr> <tr> <td width="22"> <p>&nbsp;</p> </td> <td width="75"> <p>&nbsp;</p> </td> <td width="86"> <p>8200537190</p> </td> <td width="150"> <p>COMPR</p> <p>&nbsp;</p> </td> <td width="70"> <p>64</p> </td> <td width="73"> <p>426,880</p> </td> <td width="73"> <p>451,380</p> </td> <td width="65"> <p>TH</p> </td> </tr> <tr> <td width="22"> <p><strong>2</strong></p> </td> <td width="75"> <p><strong>126179212</strong></p> </td> <td width="86"> <p>&nbsp;</p> </td> <td width="150"> <p>&nbsp;</p> </td> <td width="70"> <p><strong>64</strong></p> </td> <td width="73"> <p><strong>426,880</strong></p> </td> <td width="73"> <p><strong>451,380</strong></p> </td> <td width="65"> <p>&nbsp;</p> </td> </tr> <tr> <td width="22"> <p>&nbsp;</p> </td> <td width="75"> <p>&nbsp;</p> </td> <td width="86"> <p>8200537190</p> </td> <td width="150"> <p>COMPR</p> <p>&nbsp;</p> </td> <td width="70"> <p>64</p> </td> <td width="73"> <p>426,880</p> </td> <td width="73"> <p>451,380</p> </td> <td width="65"> <p>TH</p> </td> </tr> <tr> <td width="22"> <p><strong>3</strong></p> </td> <td width="75"> <p><strong>130701211</strong></p> </td> <td width="86"> <p>&nbsp;</p> </td> <td width="150"> <p>&nbsp;</p> </td> <td width="70"> <p><strong>480</strong></p> </td> <td width="73"> <p><strong>547,200</strong></p> </td> <td width="73"> <p><strong>571,700</strong></p> </td> <td width="65"> <p>&nbsp;</p> </td> </tr> <tr> <td width="22"> <p>&nbsp;</p> </td> <td width="75"> <p>&nbsp;</p> </td> <td width="86"> <p>765872424R</p> </td> <td width="150"> <p>REINF- SIDE IMPACT RE</p> <p>&nbsp;</p> </td> <td width="70"> <p>480</p> </td> <td width="73"> <p>547,200</p> </td> <td width="73"> <p>571,700</p> </td> <td width="65"> <p>EU</p> </td> </tr> <tr> <td width="22"> <p><strong>4</strong></p> </td> <td width="75"> <p><strong>130718211</strong></p> </td> <td width="86"> <p>&nbsp;</p> </td> <td width="150"> <p>&nbsp;</p> </td> <td width="70"> <p><strong>480</strong></p> </td> <td width="73"> <p><strong>547,200</strong></p> </td> <td width="73"> <p><strong>571,700</strong></p> </td> <td width="65"> <p>&nbsp;</p> </td> </tr> <tr> <td width="22"> <p>&nbsp;</p> </td> <td width="75"> <p>&nbsp;</p> </td> <td width="86"> <p>8200536832</p> </td> <td width="150"> <p>REINF- SIDE IMPACT RE</p> <p>&nbsp;</p> </td> <td width="70"> <p>480</p> </td> <td width="73"> <p>547,200</p> </td> <td width="73"> <p>571,700</p> </td> <td width="65"> <p>EU</p> </td> </tr> <tr> <td width="22"> <p><strong>5</strong></p> </td> <td width="75"> <p><strong>155932212</strong></p> </td> <td width="86"> <p>&nbsp;</p> </td> <td width="150"> <p>&nbsp;</p> </td> <td width="70"> <p><strong>336</strong></p> </td> <td width="73"> <p><strong>493,920</strong></p> </td> <td width="73"> <p><strong>518,420</strong></p> </td> <td width="65"> <p>&nbsp;</p> </td> </tr> <tr> <td width="22"> <p>&nbsp;</p> </td> <td width="75"> <p>&nbsp;</p> </td> <td width="86"> <p>476604621R</p> </td> <td width="150"> <p>UNIT-ABS HYD</p> <p>&nbsp;</p> </td> <td width="70"> <p>336</p> </td> <td width="73"> <p>493,920</p> </td> <td width="73"> <p>518,420</p> </td> <td width="65"> <p>EU</p> </td> </tr> </tbody> </table> <p><span style="text-decoration: underline;">Test.xlsx</span></p> <table border="1"> <tbody> <tr> <td>Refrences</td> <td>Name of Group</td> </tr> <tr> <td>8200537190</td> <td>Group 1</td> </tr> <tr> <td>765872424R</td> <td>Group 2</td> </tr> <tr> <td>8200536832</td> <td>Group 1</td> </tr> <tr> <td>476604621R</td> <td>Group 3</td> </tr> </tbody> </table> <p><strong><span style="text-decoration: underline;">Output</span></strong></p> <p><span style="text-decoration: underline;">Group 1.rtf</span> </p> <table border="1"> <tbody> <tr> <td width="80"> <p>Nr</p> </td> <td width="80"> <p>Case Nr</p> </td> <td width="80"> <p>References</p> </td> <td width="80"> <p>Goods designation</p> </td> <td width="80"> <p>Quantity</p> </td> <td width="80"> <p>Total net weight, kg</p> </td> <td width="80"> <p>Total gross weight, kg</p> </td> <td width="80"> <p>Country of origin</p> </td> </tr> <tr> <td width="80"> <p>1</p> </td> <td width="80"> <p>126178212</p> </td> <td width="80"> <p>&nbsp;</p> </td> <td width="80"> <p>&nbsp;</p> </td> <td width="80"> <p>64</p> </td> <td width="80"> <p>426,880</p> </td> <td width="80"> <p>451,380</p> </td> <td width="80"> <p>&nbsp;</p> </td> </tr> <tr> <td width="80"> <p>&nbsp;</p> </td> <td width="80"> <p>&nbsp;</p> </td> <td width="80"> <p>8200537190</p> </td> <td width="80"> <p>COMPR</p> </td> <td width="80"> <p>64</p> </td> <td width="80"> <p>426,880</p> </td> <td width="80"> <p>451,380</p> </td> <td width="80"> <p>TH</p> </td> </tr> <tr> <td width="80"> <p>2</p> </td> <td width="80"> <p>126179212</p> </td> <td width="80"> <p>&nbsp;</p> </td> <td width="80"> <p>&nbsp;</p> </td> <td width="80"> <p>64</p> </td> <td width="80"> <p>426,880</p> </td> <td width="80"> <p>451,380</p> </td> <td width="80"> <p>&nbsp;</p> </td> </tr> <tr> <td width="80"> <p>&nbsp;</p> </td> <td width="80"> <p>&nbsp;</p> </td> <td width="80"> <p>8200537190</p> </td> <td width="80"> <p>COMPR</p> </td> <td width="80"> <p>64</p> </td> <td width="80"> <p>426,880</p> </td> <td width="80"> <p>451,380</p> </td> <td width="80"> <p>TH</p> </td> </tr> <tr> <td width="80"> <p>4</p> </td> <td width="80"> <p>130718211</p> </td> <td width="80"> <p>&nbsp;</p> </td> <td width="80"> <p>&nbsp;</p> </td> <td width="80"> <p>480</p> </td> <td width="80"> <p>547,200</p> </td> <td width="80"> <p>571,700</p> </td> <td width="80"> <p>&nbsp;</p> </td> </tr> <tr> <td width="80"> <p>&nbsp;</p> </td> <td width="80"> <p>&nbsp;</p> </td> <td width="80"> <p>8200536832</p> </td> <td width="80"> <p>REINF- SIDE IMPACT RE</p> </td> <td width="80"> <p>480</p> </td> <td width="80"> <p>547,200</p> </td> <td width="80"> <p>571,700</p> </td> <td width="80"> <p>EU</p> </td> </tr> </tbody> </table> <p><span style="text-decoration: underline;">Group 2.rtf</span> </p> <table border="1"> <tbody> <tr> <td width="80"> <p>Nr</p> </td> <td width="80"> <p>Case Nr</p> </td> <td width="80"> <p>References</p> </td> <td width="80"> <p>Goods designation</p> </td> <td width="80"> <p>Quantity</p> </td> <td width="80"> <p>Total net weight, kg</p> </td> <td width="80"> <p>Total gross weight, kg</p> </td> <td width="80"> <p>Country of origin</p> </td> </tr> <tr> <td width="80"> <p>3</p> </td> <td width="80"> <p>130701211</p> </td> <td width="80"> <p>&nbsp;</p> </td> <td width="80"> <p>&nbsp;</p> </td> <td width="80"> <p>480</p> </td> <td width="80"> <p>547,200</p> </td> <td width="80"> <p>571,700</p> </td> <td width="80"> <p>&nbsp;</p> </td> </tr> <tr> <td width="80"> <p>&nbsp;</p> </td> <td width="80"> <p>&nbsp;</p> </td> <td width="80"> <p>765872424R</p> </td> <td width="80"> <p>REINF- SIDE IMPACT RE</p> </td> <td width="80"> <p>480</p> </td> <td width="80"> <p>547,200</p> </td> <td width="80"> <p>571,700</p> </td> <td width="80"> <p>EU</p> </td> </tr> </tbody> </table> <p><span style="text-decoration: underline;">Group 3.rtf</span> </p> <table border="1"> <tbody> <tr> <td width="80"> <p>Nr</p> </td> <td width="80"> <p>Case Nr</p> </td> <td width="80"> <p>References</p> </td> <td width="80"> <p>Goods designation</p> </td> <td width="80"> <p>Quantity</p> </td> <td width="80"> <p>Total net weight, kg</p> </td> <td width="80"> <p>Total gross weight, kg</p> </td> <td width="80"> <p>Country of origin</p> </td> </tr> <tr> <td width="80"> <p>5</p> </td> <td width="80"> <p>155932212</p> </td> <td width="80"> <p>&nbsp;</p> </td> <td width="80"> <p>&nbsp;</p> </td> <td width="80"> <p>336</p> </td> <td width="80"> <p>493,920</p> </td> <td width="80"> <p>518,420</p> </td> <td width="80"> <p>&nbsp;</p> </td> </tr> <tr> <td width="80"> <p>&nbsp;</p> </td> <td width="80"> <p>&nbsp;</p> </td> <td width="80"> <p>476604621R</p> </td> <td width="80"> <p>UNIT-ABS HYD</p> </td> <td width="80"> <p>336</p> </td> <td width="80"> <p>493,920</p> </td> <td width="80"> <p>518,420</p> </td> <td width="80"> <p>EU</p> </td> </tr> </tbody> </table>https://www.aspforums.net:443/Threads/201748/Compare-RTF-file-with-Excel-file-and-generate-separate-RTF-file-based-on-group-assigned-in-excel-using-C-and-VBNet-in-ASPNet/https://www.aspforums.net:443/Threads/201748/Compare-RTF-file-with-Excel-file-and-generate-separate-RTF-file-based-on-group-assigned-in-excel-using-C-and-VBNet-in-ASPNet/Thu, 13 Jul 2017 06:18:43 GMT