raushanaj5
会员
- 已加入
- 2017年4月15日
- 留言内容
- 7
- 编程经验
- Beginner
我正在使用C#解决我的问题。
我有一个包含许多工作表的Excel文件。从"Fisrt Sheet",我正在寻找一个角色"x"它将出现在特定列的某些单元格中("x"将仅在一个特定的列中,在该列的不同单元格中)。我在寻找"x"并在通用列表中提取相应行的详细信息(并命名提取字段的标题)。现在,我必须在"tabular format"通过Outlook在邮件正文中显示。
I am stuck with sending of list in 福彩12选5走势图格式 in the mail body.
我只想知道如何在邮件正文中以福彩12选5走势图形式发送生成的列表。
请帮我解决我的问题
我有一个包含许多工作表的Excel文件。从"Fisrt Sheet",我正在寻找一个角色"x"它将出现在特定列的某些单元格中("x"将仅在一个特定的列中,在该列的不同单元格中)。我在寻找"x"并在通用列表中提取相应行的详细信息(并命名提取字段的标题)。现在,我必须在"tabular format"通过Outlook在邮件正文中显示。
I am stuck with sending of list in 福彩12选5走势图格式 in the mail body.
我只想知道如何在邮件正文中以福彩12选5走势图形式发送生成的列表。
请帮我解决我的问题
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("[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; }
}
[COLOR=#242729][FONT=Arial]