读取Excel任务列表并显示在Outlook日历上
前几天,公司发了一个任务安排,时间不固定,但要求准时到,为了给自己加一个提醒,也为了回顾一下以前的技术,特做了一个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日历上的更多相关文章
- asp.net本地读取excel正确。但在iis服务器上就报错 未在本地计算机上注册“Microsoft.ACE.OleDb.12.0”提供程序
本地vs2010可以上传ecxel文件.并读取数据,但部署到本地IIS.并访问.则提示: 未在本地计算机上注册“Microsoft.ACE.OleDb.12.0”提供程序 首先:确保安装了Micros ...
- ASP.NET中读取excel内容并显示
项目中经常会用到把excel的文件内容导入到数据库中的,刚刚花了点时间,做了个例子,基本上能实现导入Excel后显示的功能吧,导入的excel文件得是xls,即是2003的. 代码思路如下:要 ...
- 关于在读取excel的文件时候,放在服务器上就报路径错误
就是指定这个路径:C:\Program Files (x86)\IIS Express 因为在上传到服务器的时候,服务器读取的是在服务器上的路径,所以正确的思路应该是 把上传的Excel存在服务器上, ...
- java 通过流的方式读取本地图片并显示在jsp 页面上(类型以jpg、png等结尾的图片)
Java代码: File filePic = new File(path+"1-ab1.png"); if(filePic.exists()){ FileInputStream i ...
- jspsmart(保存文件)+poi(读取excel文件)操作excel文件
写在前面: 项目环境:jdk1.4+weblogic 需求:能上传excel2003+2007 由于项目不仅需要上传excel2003,还要上传excel2007,故我们抛弃了jxl(只能上传exce ...
- C#读取Excel显示到repeater中
首先需要一个用来存储我们需要显示的内容,防止页面回发丢失(添加时使用) #region 缓存文件 private DataTable excelData; /// <summary> // ...
- 读取Excel数据绑定到Gridview进行显示
读取Excel数据绑定到Gridview进行显示示例代码. 读取excel代码 /// <summary> /// 读取Excel /// authon:codeo.cn /// < ...
- PYTHON读取EXCEL内容再转变成HTML添加到OUTLOOK中
需求 读取excel里的表格里的内容,然后打开本机的outlook.把excel里的内容添加到正文里,注意.这里是要添加到正文!正文!正文!而不是添加到附件里 设计思路 1.excel处理 打开exc ...
- clientdataset 读取excel 如果excel 文件不存在的时候 相应的gird 会不显示数据, 鼠标掠过 gird 格子 才会显示数据。 这是一个bug 哈哈
clientdataset 读取excel 如果excel 文件不存在的时候 相应的gird 会不显示数据, 鼠标掠过 gird 格子 才会显示数据. 这是一个bug 哈哈
随机推荐
- php入门之表单创建和基本处理
为了方便后面学习数组,这里引入了过渡章节就是表单,至于为什么,等真的学习到数组的时候你就会发现它的妙处拉. ============================================== ...
- 这个SpringMVC的一直刷屏的问题你见过吗?无解
严重: Servlet.service() for servlet DispatcherServlet threw exceptionjava.lang.StackOverflowError at o ...
- 【转】#ifdef __cplusplus深度剖析
原文:http://bbs.ednchina.com/BLOG_ARTICLE_251752.HTM 时常在cpp的代码之中看到这样的代码: #ifdef __cplusplus extern ...
- (转)《深入理解java虚拟机》学习笔记5——Java Class类文件结构
Java语言从诞生之时就宣称一次编写,到处运行的跨平台特性,其实现原理是源码文件并没有直接编译成机器指令,而是编译成Java虚拟机可以识别和运行的字节码文件(Class类文件,*.class),字节码 ...
- SQL Server数据库备份(本机)
基础的SQL Server数据库备份存储过程 /**************************************************************************** ...
- Head First设计模式悟道
暂时包括 策略模式,观察者,装饰模式,工厂模式,抽象工厂模式,后续会继续补充中,纯属个人总结用,不喜勿喷, 源代码见: 传送门 public class NYPizzaIngredientFactor ...
- POJ 2151 概率DP
主要的子问题是每一个队伍有一个做出题目的概率,求做出k个题目的概率.简单的简单的组合数DP.想清楚即可. 1: #include <iostream> 2: #include <cs ...
- 自定义UICollectionViewLayout并添加UIDynamic - scorpiozj(转)
转载自:http://www.tuicool.com/articles/jM77Vf 自定义UICollectionViewLayout并添加UIDynamic UICollectionVie ...
- MySQL查询本周、上周、本月、上个月份数据的sql代码(转)
感谢:http://www.jb51.net/article/32277.htm ----------------------------------------------------------- ...
- MSMQ(消息队列)
前段时间研究WCF接触到了MSMQ,所以认真的学习了一下,下面是我的笔记. 我理解的MSMQ MSMQ可以被看成一个数据储存装置,就如同数据库,只不过数据存储的是一条一条的记录,而MSMQ存储的是一个 ...