raushanaj5
Member
- Joined
- Apr 15, 2017
- Messages
- 7
- Programming Experience
- Beginner
I am using C# for my problem.
I have an Excel file which has many worksheets. From "Fisrt Sheet", I am looking for a character "x" which will be present in some cells of a specific column (occurence of "x" will be in one specific column only, in different cells of that column). I am looking for "x" and extracting the corresponding row's details in a generic list (with naming the headers of extracted field). Now, I have to send this generic list in "tabular format" in body of the mail via Outlook.
I am stuck with sending of list in tabular format in the mail body.
I just want to know how to send my generated list in tabular form in mail body.
Please help me with my problem
I have an Excel file which has many worksheets. From "Fisrt Sheet", I am looking for a character "x" which will be present in some cells of a specific column (occurence of "x" will be in one specific column only, in different cells of that column). I am looking for "x" and extracting the corresponding row's details in a generic list (with naming the headers of extracted field). Now, I have to send this generic list in "tabular format" in body of the mail via Outlook.
I am stuck with sending of list in tabular format in the mail body.
I just want to know how to send my generated list in tabular form in mail body.
Please help me with my problem
C#:
[/FONT][/COLOR]using System;using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Data;
using Excel = Microsoft.Office.Interop.Excel;
using Outlook = Microsoft.Office.Interop.Outlook;
namespace xlsm
{
class New
{
static void Main(sting[] args)
{
sting st;
long rCnt, cCnt;
long rows = 0, columns = 0;
Excel.Application xlApp;
Excel.Workbook xlWorkBook;
Excel.Worksheet xlWorkSheet;
Excel.Range rng;
xlApp = new Excel.Application();
xlWorkBook = xlApp.Workbooks.Open(@"F:\Doc_Excel", 0, true, 5, "", "", true, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "\t", false, false, 0, true, 1, 0);
xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets["First Sheet"];
rng = xlWorkSheet.UsedRange;
rows = rng.Rows.Count;
columns = rng.Columns.Count;
List<Memo> lst = new List<Memo>();
for (rCnt = 1; rCnt < rows; rCnt++)
{
for (cCnt = 1; cCnt < columns; cCnt++)
{
if ((rng.Cells[rCnt, cCnt] as Excel.rng).Value2 != null)
{
st = (rng.Cells[rCnt, cCnt] as Excel.rng).Value2.Tosting();
if (st == "x")
{
Memo ms = new Memo();
ms.MemoName = (rng.Cells[rCnt, 1] as Excel.rng).Value2.Tosting();
ms.Type = (rng.Cells[rCnt, 2] as Excel.rng).Value2.Tosting();
ms.Ext = (rng.Cells[rCnt, 3] as Excel.rng).Value2.Tosting();
ms.Seller = (rng.Cells[rCnt, 4] as Excel.rng).Value2.Tosting();
ms.Warehouse = (rng.Cells[rCnt, 5] as Excel.rng).Value2.Tosting();
lst.Add(ms);
}
}
}
}
try
{
Outlook.Application oApp = new Outlook.Application();
Outlook.MailItem oMsg = (Outlook.MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem);
oMsg.HTMLBody = "";
oMsg.Subject = "Memo contents as required.";
Outlook.Recipients oRecims = (Outlook.Recipients)oMsg.Recipients;
Outlook.Recipient oRecip = (Outlook.Recipient)oRecims.Add("abc@xyz.com");
oRecip.Resolve();
oMsg.Send();
oRecip = null;
oRecims = null;
oMsg = null;
oApp = null;
}
catch (Exception ex)
{
}
xlWorkBook.close(true, null, null);
xlApp.Quit();
Marshal.ReleaseComObject(xlWorkSheet);
Marshal.ReleaseComObject(xlWorkBook);
Marshal.ReleaseComObject(xlApp);
}
}
public class Memo
{
public string MemoName { get; set; }
public string Type { get; set; }
public string Ext { get; set; }
public string Seller { get; set; }
public string Warehouse { get; set; }
}
[COLOR=#242729][FONT=Arial]