前几天,公司发了一个任务安排,时间不固定,但要求准时到,为了给自己加一个提醒,也为了回顾一下以前的技术,特做了一个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. ubuntu server版连接vpn服务器

    命令行的方法: 1.要下载pptp的客户端    sudo apt-get install pptp-linux 2.创建连接     sudo pptpsetup –create vpn001 –s ...

  2. CCNP第三天 EIGRP综合实验

    实验题如图所示:其中R2连R3 R5为快速以太网线,其他均为串线,帧中继默认是富曼斯(全连网状结构),即所有接入的路由之间的PVC都已经打通,所有  要关闭R5和R8的逆向arp功能,来手工配置R5到 ...

  3. VB6-操作数据库

    平常搞数据库操作多了就想把经常用的内容放在一起,我也懒,在一本书里的工程例子挑了一个bas,修修改改,凑合这用吧. Public strCnn As String '数据库连接字符串 Public A ...

  4. SPI协议及其工作原理详解

    一.概述. SPI, Serial Perripheral Interface, 串行外围设备接口, 是 Motorola 公司推出的一种同步串行接口技术. SPI 总线在物理上是通过接在外围设备微控 ...

  5. what is the virtual machine, when and why we need use it ?

    虚拟机(Virtual Machine)指通过软件模拟的具有完整硬件系统功能的.运行在一个完全隔离环境中的完整计算机系统. 通过虚拟机软件,你可以在一台物理计算机上模拟出二台或多台虚拟的计算机,这些虚 ...

  6. WPF处理Windows消息

    WPF中处理消息首先要获取窗口句柄,创建HwndSource对象 通过HwndSource对象添加消息处理回调函数. HwndSource类: 实现其自己的窗口过程. 创建窗口之后使用 AddHook ...

  7. TabControl控件

    private void Form1_Load(object sender, EventArgs e) { #region 显示样式 tabControl1.ImageList = imageList ...

  8. php源代码安装常见错误与解决办法分享

    错误:configure: error: libevent >= 1.4.11 could not be found 解决:yum -y install libevent libevent-de ...

  9. HTMLParser获取属性名

    HTMLParser获取属性名方式: 原始网页文本: <a title="美军被曝虐尸" href="http://www.sogou.com/web?query= ...

  10. 360随身wifi怎样购买?360随身wifi怎样预约?

    ---恢复内容开始--- 360随身wifi怎样购买 想要购买360随身Wifi,可以登录360随身Wifi的官网wifi.360.cn,或者直接登陆京东商城进行购买,售价为19.9元,分黑.白两色. ...