前几天,公司发了一个任务安排,时间不固定,但要求准时到,为了给自己加一个提醒,也为了回顾一下以前的技术,特做了一个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. MySQL的varchar定义长度到底是字节还是字符

    相信这个问题也会困扰不少人,尤其是使用过其它数据库(如Oracle)的人,之前我也没有太在意这个问题,再加上一些书籍和网上的文章讲的不够细致,又没测试过,导致我一直理解错误.下面通过实例来解释,在开始 ...

  2. 使用Java反射(Reflect)、自定义注解(Customer Annotation)生成简单SQL语句

    这次给大家介绍一下在Java开发过程中 使用自定义注解开发:主要知识点:            1.反射            主要用于提取注解信息            2.自定义异常  主要是为了 ...

  3. Python OS模块标准库的系统接口及操作方法

    Python OS模块标准库的系统接口及操作方法 os.name 返回当前操作系统名,定义了'posix','nt','mac','os2','ce','java'(我使用win7/python3.1 ...

  4. Ubuntu 14.04的SWAP 为0

    [@@@@@@]# free total used free shared buffers cached Mem: 1024976 248992 775984 0 16820 73128 -/+ bu ...

  5. Fedora 命令

    1. 更新包 yum clear all yum -y update 2.yum包查找 yum whatprovides xxxx.os.l 3 df 查看磁盘空间 xclip 复制到粘贴板 xcli ...

  6. Java中的异常处理(二)

    1.finally package second; public class C { public static void main(String[] args){ String name = nul ...

  7. SYBASE时间计算

    以摘录了计算月初,月末,上月同日,下月同日,上年同日,下年同日(年有闰月问题),各种函数输出格式. 可以写到存储过程中也可单独使用. Sybase日期函数 文章分类:数据库 关键字: sybase日期 ...

  8. BitSet

    前几天干了一件比较无聊的事儿——抄了一遍C++ STL bitset的源代码,把不懂的宏定义去掉了,发现(暂时)还能用,嘿嘿. #ifndef BITSET_H #define BITSET_H #i ...

  9. java开发命名规范总结

    一 包名的书写规范 (Package)推荐使用公司或机构的顶级域名为包名的前缀,目的是保证各公司/机构内所使用的包名的唯一性.包名全部为小写字母,且具有实际的区分意义. 1.1 一般要求1.选择有意义 ...

  10. JSP内置对象详解

    jsp中内置对象:request.response.session.applecation.out.pagecontesx.config.page.exception.cookie 1.request ...