前几天,公司发了一个任务安排,时间不固定,但要求准时到,为了给自己加一个提醒,也为了回顾一下以前的技术,特做了一个Demo。

读取Excel就不多说了,代码很简单,但支持老版本Excel和的版本Excel。

代码如下:

public class ExcelConn
{
private string FilePath;
private string m_filePath = string.Empty;
private OleDbConnection conn; public ExcelConn(string filePath)
{
this.FilePath = filePath;
string fileType = System.IO.Path.GetExtension(filePath);
if (fileType == ".xls")
{
conn = new OleDbConnection("Provider = Microsoft.Jet.OLEDB.4.0 ; Data Source ='" + this.FilePath + "';Extended Properties=Excel 8.0;");
}
else
{
conn = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source ='" + this.FilePath + "';Extended Properties=\"Excel 12.0;HDR=YES;IMEX=1\"");
}
if (conn.State != System.Data.ConnectionState.Open)
{
conn.Open();
}
} private DataTable GetData(OleDbCommand cmd)
{
try
{
if (cmd.Connection != null)
{
using (DataSet ds = new DataSet())
{
using (OleDbDataAdapter da = new OleDbDataAdapter())
{
da.SelectCommand = cmd;
da.Fill(ds);
return ds.Tables[];
}
}
}
else
{
using (OleDbTransaction trans = conn.BeginTransaction(IsolationLevel.ReadUncommitted))
{
try
{
cmd.Transaction = trans;
using (DataSet ds = new DataSet())
{
using (OleDbDataAdapter da = new OleDbDataAdapter())
{
da.SelectCommand = cmd;
da.SelectCommand.Connection = conn;
da.Fill(ds);
return ds.Tables[];
}
}
}
finally
{
trans.Commit();
}
}
}
}
finally
{ }
} public DataSet GetDataSet(string sql)
{
try
{
OleDbTransaction trans = conn.BeginTransaction(IsolationLevel.ReadUncommitted);
try
{
using (OleDbCommand cmd = conn.CreateCommand())
{
cmd.Transaction = trans;
cmd.CommandType = CommandType.Text;
cmd.CommandText = sql;
using (DataSet ds = new DataSet())
{
using (OleDbDataAdapter da = new OleDbDataAdapter())
{
da.SelectCommand = cmd;
da.SelectCommand.Connection = conn;
da.Fill(ds);
return ds;
}
}
}
}
finally
{
trans.Commit();
}
}
finally
{
}
} public void ExecuteNonQuery(string sql)
{
OleDbTransaction trans = conn.BeginTransaction(IsolationLevel.ReadUncommitted);
OleDbCommand cmd = new OleDbCommand(sql);
cmd.Connection = conn;
cmd.Transaction = trans;
cmd.ExecuteNonQuery();
trans.Commit();
} public object ExecuteScalar(OleDbCommand cmd)
{
try
{
using (OleDbTransaction trans = conn.BeginTransaction(IsolationLevel.ReadUncommitted))
{
cmd.Connection = conn;
cmd.Transaction = trans;
object res = cmd.ExecuteScalar();
trans.Commit();
return res;
}
}
finally
{
}
} public void Close()
{
conn.Close();
} public DataSet ExcelToDS()
{
OleDbDataAdapter myCommand;
DataTable schemaTable = conn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, new object[] { });
DataSet ds = new DataSet();
try
{
int i = ;
{
DataRow dr = schemaTable.Rows[i];
string strExcel = "select * from [" + dr["TABLE_NAME"].ToString().Trim() + "]";
myCommand = new OleDbDataAdapter(strExcel, conn);
myCommand.Fill(ds);
}
}
catch
{
}
finally
{
conn.Close();
}
return ds;
}
}

调用示例:DataTable dtExl = new Calendar.ExcelConn(@"d:\桌面\Temp\net开发团队生产突击报名表(1).xlsx").ExcelToDS().Tables[0];

在OutLook上添加日历,其实就是添加一个约会。

新建约会也就是调用OutLook的ApplicationClass。

主要代码如下:

                ApplicationClass oApp = new Microsoft.Office.Interop.Outlook.ApplicationClass();

                //会议是约会的一种
AppointmentItem oItem = (AppointmentItem)oApp.CreateItem(OlItemType.olAppointmentItem);
oItem.MeetingStatus = OlMeetingStatus.olMeeting;
oItem.Subject = "生产突击";
oItem.Body = "内容";
oItem.Location = "地点";
//开始时间 
oItem.Start = DateTime.Now.AddDays();
//结束时间
oItem.End = DateTime.Now.AddDays().AddHours();
//提醒设置
oItem.ReminderSet = true;
oItem.ReminderMinutesBeforeStart = ; //是否全天事件
oItem.AllDayEvent = false; oItem.BusyStatus = OlBusyStatus.olBusy; //索引从1开始,而不是从0
//发件人的帐号信息
var acc = oApp.Session.Accounts;
oItem.SendUsingAccount = oApp.Session.Accounts[]; //添加必选人
Recipient force = oItem.Recipients.Add("wufei@china.com");
force = oItem.Recipients.Add("zaijun@china.com");
force.Type = (int)OlMeetingRecipientType.olRequired;
////添加可选人
//Recipient opt = oItem.Recipients.Add("mailuser3@p.mailserver.com");
//opt.Type = (int)OlMeetingRecipientType.olOptional;
////添加会议发起者
//Recipient meetingSender = oItem.Recipients.Add("mailuser1@mailserver.com");
//meetingSender.Type = (int)OlMeetingRecipientType.olOrganizer; oItem.Recipients.ResolveAll();
oItem.Send();

既读取了Excel,又能发约会,下面就是Excel中数据的筛选和调用了,相信难不倒各位,就不多说了。

至此,这个简单的Demo算是完成了,希望对大家有用。

读取Excel任务列表并显示在Outlook日历上的更多相关文章

  1. asp.net本地读取excel正确。但在iis服务器上就报错 未在本地计算机上注册“Microsoft.ACE.OleDb.12.0”提供程序

    本地vs2010可以上传ecxel文件.并读取数据,但部署到本地IIS.并访问.则提示: 未在本地计算机上注册“Microsoft.ACE.OleDb.12.0”提供程序 首先:确保安装了Micros ...

  2. ASP.NET中读取excel内容并显示

    项目中经常会用到把excel的文件内容导入到数据库中的,刚刚花了点时间,做了个例子,基本上能实现导入Excel后显示的功能吧,导入的excel文件得是xls,即是2003的.     代码思路如下:要 ...

  3. 关于在读取excel的文件时候,放在服务器上就报路径错误

    就是指定这个路径:C:\Program Files (x86)\IIS Express 因为在上传到服务器的时候,服务器读取的是在服务器上的路径,所以正确的思路应该是 把上传的Excel存在服务器上, ...

  4. java 通过流的方式读取本地图片并显示在jsp 页面上(类型以jpg、png等结尾的图片)

    Java代码: File filePic = new File(path+"1-ab1.png"); if(filePic.exists()){ FileInputStream i ...

  5. jspsmart(保存文件)+poi(读取excel文件)操作excel文件

    写在前面: 项目环境:jdk1.4+weblogic 需求:能上传excel2003+2007 由于项目不仅需要上传excel2003,还要上传excel2007,故我们抛弃了jxl(只能上传exce ...

  6. C#读取Excel显示到repeater中

    首先需要一个用来存储我们需要显示的内容,防止页面回发丢失(添加时使用) #region 缓存文件 private DataTable excelData; /// <summary> // ...

  7. 读取Excel数据绑定到Gridview进行显示

    读取Excel数据绑定到Gridview进行显示示例代码. 读取excel代码 /// <summary> /// 读取Excel /// authon:codeo.cn /// < ...

  8. PYTHON读取EXCEL内容再转变成HTML添加到OUTLOOK中

    需求 读取excel里的表格里的内容,然后打开本机的outlook.把excel里的内容添加到正文里,注意.这里是要添加到正文!正文!正文!而不是添加到附件里 设计思路 1.excel处理 打开exc ...

  9. clientdataset 读取excel 如果excel 文件不存在的时候 相应的gird 会不显示数据, 鼠标掠过 gird 格子 才会显示数据。 这是一个bug 哈哈

    clientdataset 读取excel   如果excel 文件不存在的时候   相应的gird 会不显示数据, 鼠标掠过 gird 格子 才会显示数据.   这是一个bug 哈哈

随机推荐

  1. delphi xe memory leak produced in WSDLLookup.pas

    constructor TWSDLLookup.Create; begin FLookup := TDictionary<string, Variant>.Create; end; des ...

  2. Python数据结构——二叉树的实现

    1. 二叉树 二叉树(binary tree)中的每个节点都不能有多于两个的儿子. 1.1 二叉树列表实现 如上图的二叉树可用列表表示: tree=['A', #root ['B', #左子树 ['D ...

  3. C语言的32个关键字

    由ANSI标准定义的C语言关键字共个: auto double int struct break else long switch case enum register typedef char ex ...

  4. 内容自适应UILabel

    xcode 6.1 File-New-Project.. iOs-Application-Simple View Application 代码: - (void)viewDidLoad { [supe ...

  5. C# 的轻量级 RPC 框架

    Redola.Rpc 的一个小目标 Redola.Rpc 的一个小目标 Redola.Rpc 的一个小目标:20000 tps. Concurrency level: 8 threads Comple ...

  6. CSS3圆角气泡框,评论对话框

    <title>CSS3圆角气泡框,评论对话框</title> <style> body { ; ; font:1em/1.4 Cambria, Georgia, s ...

  7. 怎样修改Windows7环境变量

    在使用电脑的时候要运行某些特定的应用程序时需要修改系统的环境变量,例如安装JAVA时我们就需要配置系统的环境变量.那什么是环境变量呢?环境变量一般是指在操作系统中用来指定操作系统运行环境的一些参数,比 ...

  8. 【莫队】bzoj 3781,bzoj 2038,bzoj 3289

    好像又有一个星期没更博客了.. 最近疯狂考试...唯一有点收获的就是学会了莫队这种神奇的算法.. 听起来很难..其实是一个很简单的东西.. 就是在区间处理问题时对于一个待求区间[L',R']通过之前求 ...

  9. Windows 2008 R2系统开机时如何不让Windows进行磁盘检测?

    开始→运行,在运行对话框中键入“chkntfs /t:0”,即可将磁盘扫描等待时间设置为0, 如果要在计算机启动时忽略扫描某个分区,比如C盘,可以输入“chkntfs /x c:”命令:如果要恢复对C ...

  10. Hadoop将过时了?

    http://www.kuqin.com/database/20120715/322528.html Hadoop这个单词如今铺天盖地,几乎成了大数据的代名词.仅仅数年时间,Hadoop从边缘技术迅速 ...