TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Raushan Raj
NA
23
12.3k
How can I send generic list<T> in the body of outlook mail
Apr 15 2017 1:15 AM
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<t> in "tabular format" in body of the mail via Outlook.
I am stuck with sending of list in tabular format in the mail body.
Please help me with my problem
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(
"
[email protected]
"
);
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
; }
}
Reply
Answers (
7
)
Which approach is better according to OOP principals?
HOw can acces nested datalist item in datalist