前几天,公司发了一个任务安排,时间不固定,但要求准时到,为了给自己加一个提醒,也为了回顾一下以前的技术,特做了一个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. 【WPF】Application应用程序启动

    wpf应用程序在启动的时候会自动创建Main函数并调用Application实例的run(),从而启动Application进程.Main函数在一个App.g.cs文件中,App.g.cs文件的位置在 ...

  2. Foreign Exchange

     10763 Foreign ExchangeYour non-profit organization (iCORE - international Confederation of Revolver ...

  3. RAC环境下SCAN IP可以PING通,1521端口也可以TELNET,但是无法建立数据库连接

    昨天用户请求帮助处理一个问题:有个厂家需要连某个业务系统的数据库,网络上已经开通了权限,SCAN IP可以PING通,测试TELNET 1521端口也是正常.但是想通过SQLPLUS连接,总是会提示连 ...

  4. ASP.NET MVC的约定

    ASP.NET MVC 应用程序遵循以下3条约定: 所有的控制器的名称都以Controller结尾,如HomeController, AccountController 这些类默认在Controlle ...

  5. Js 处理将时间转换 “年-月-日”

    将时间  \/Date(1432828800000+0800)\/"  转换成:“年-月-日” //时间转换function ChangeDateFormat(val) {    if (v ...

  6. ARC工程中添加非ARC文件

    转载自:http://blog.csdn.net/zhenweicao/article/details/16988543 分类: IOS2013-11-27 17:02 626人阅读 评论(0) 收藏 ...

  7. python学习笔记19(序列的方法)

    序列包含有宝值 表(tuple)和表(list).此外,字符串(string)是一种特殊的定值表,表的元素可以更改,定值表一旦建立,其元素不可更改. 任何的序列都可以引用其中的元素(item). 下面 ...

  8. Linux学习笔记(4)-文本编辑器vi的使用

    vi的三种编辑模式 命令模式(Command mode) 在此模式下可以控制光标的移动,可以删除字符,删除行,还可以对某个段落进行复制和移动 输入模式(Insert mode) 只有在此模式下,可以输 ...

  9. springMVC+MyBatis+Spring 整合(2)

    mybatis 与Spring 的整合. 1.导入Spring 和Springmvc的包 pom <project xmlns="http://maven.apache.org/POM ...

  10. pl/sql developer连接远程数据库

    本地不安装oracle client程序,直接使用pl/sql developer连接远程数据库 考虑到机子本身资源有限,一个client会占用很多资源,尝试使用不安装客户端的方式进行远程连接. 需要 ...