ado.net excel 模版
ado.net excel 模版
private static void Excute()
{
while (true)
{
string templatePath = System.Environment.CurrentDirectory + "\\template.xls";
string newPath = System.Environment.CurrentDirectory + "\\temp.xls";
if (!File.Exists(templatePath))
return;
if (!File.Exists(newPath))
File.Copy(templatePath, newPath,true);
FileInfo fileInfo = new FileInfo(newPath);
string s = fileInfo.Attributes.ToString();
if (fileInfo.Attributes.ToString().ToLower().IndexOf("readonly") != -1)
{
fileInfo.Attributes = FileAttributes.Normal;
}
string connStr = "Provider=Microsoft.ACE.OLEDB.12.0;;Persist Security Info=False;" +
"Extended Properties=\"Excel 12.0;HDR=YES;IMEX=0\";" +
// 指定扩展属性为 Microsoft Excel 8.0 (97) 9.0 (2000) 10.0 (2002),并且第一行作为数据返回,且以文本方式读取
"data source=" + newPath;
OleDbConnection conn = new OleDbConnection(connStr);
OleDbCommand cmd = new OleDbCommand("", conn);
try
{
conn.Open();
string sql = "insert into [Sheet2$] (姓名,性别,联系电话) values (41,51,61)";
cmd.CommandText = sql;
cmd.ExecuteNonQuery();
conn.Close();
//FileStream reader = File.OpenRead(newPath);
//int length = (int)reader.Length;
//byte[] buffer = new byte[length];
//int byteToRead;
//while (length > 0)
//{
// //客户端还开着
// byteToRead = reader.Read(buffer, 0, length);
// length -= byteToRead;
// //客户端断开时
// //length = -1;
//}
//以下为一个事务
File.Copy(newPath, "2011.xls", true);
if (File.Exists(newPath))
File.Delete(newPath);
}
catch (Exception e)
{
System.Diagnostics.Debug.WriteLine(e.Message);
}
finally
{
conn.Dispose();
}
Thread.Sleep(1000);
}
private static void Excute()
{
while (true)
{
string templatePath = System.Environment.CurrentDirectory + "\\template.xls";
string newPath = System.Environment.CurrentDirectory + "\\temp.xls";
if (!File.Exists(templatePath))
return;
if (!File.Exists(newPath))
File.Copy(templatePath, newPath,true);
FileInfo fileInfo = new FileInfo(newPath);
string s = fileInfo.Attributes.ToString();
if (fileInfo.Attributes.ToString().ToLower().IndexOf("readonly") != -1)
{
fileInfo.Attributes = FileAttributes.Normal;
}
string connStr = "Provider=Microsoft.Jet.OLEDB.4.0;" +
"Extended Properties=\"Excel 8.0;HDR=YES;IMEX=2\";" +
// 指定扩展属性为 Microsoft Excel 8.0 (97) 9.0 (2000) 10.0 (2002),并且第一行作为数据返回,且以文本方式读取
"data source=" + newPath;
OleDbConnection conn = new OleDbConnection(connStr);
OleDbCommand cmd = new OleDbCommand("", conn);
try
{
conn.Open();
string sql = "insert into [Sheet2$] (姓名,性别,联系电话) values (41,51,61)";
cmd.CommandText = sql;
cmd.ExecuteNonQuery();
conn.Close();
//FileStream reader = File.OpenRead(newPath);
//int length = (int)reader.Length;
//byte[] buffer = new byte[length];
//int byteToRead;
//while (length > 0)
//{
// //客户端还开着
// byteToRead = reader.Read(buffer, 0, length);
// length -= byteToRead;
// //客户端断开时
// //length = -1;
//}
//以下为一个事务
File.Copy(newPath, "2011.xls", true);
if (File.Exists(newPath))
File.Delete(newPath);
}
catch (Exception e)
{
}
finally
{
conn.Dispose();
}
Thread.Sleep(1000);
}
}
ado.net excel 模版的更多相关文章
- C#巧用Excel模版变成把Table打印出来
将一个做好的Excel模版,通过程序填上数据然后打印出来这个需求有两种方法一种是通过代码打开Excel模版然后填入数据然后再打印. 第二种方法就是我将要介绍的 1.将Excel设置好格式另存为HTML ...
- JAVA实现Excel导出数据(以写好的Excel模版导出)
工作中经常会有将后台数据以Excel导出的功能. 简单的方法有将response的contentType设置为application/vnd.ms-excel: 或在JSP页面直接设置成: <% ...
- POI3.10 根据Excel模版导出数据测试
1:所需jar包 2:Mysql数据库表内容如下: 3:代码结构如下: (1)User.java public class User { private int id; private String ...
- ADO读取EXCEL
窗体上拖放ADOQuery1,DataSetProvider1,DataSource1,ClientDataSet1,OpenDialog1, ExcelApplication1,ExcelWorkb ...
- ADO对Excel对象进行连接时的 两种方法区别
在通过ADO对Excel对象进行连接时(此时Excel则认为是一个数据源),需要配置对Excel数据源对应的连接串,这个连接串中包括了Provider信息(其实类似对数据库进行连接操作时,都需要指定连 ...
- Kettle 事务、转换内顺序、excel模版、使用踩坑
kettle中转换和作业的执行顺序: 1.一个作业内的转换,是顺序执行的. 2.一个转换内的步骤是并行执行的. 3.作业内不支持事务,转换内支持事务. 根据业务需要,通常需要在 ...
- [poi使用]使用excel模版导出excel
Apache POI是基于Office Open XML标准(OOXML)和Microsoft的OLE 2复合文档格式(OLE2)处理各种文件格式的开源项目.简而言之,您可以使用Java读写MS ...
- 同时使用ADO与Excel类库冲突的问题
客户需要一个Demo程序实现Access数据库表导出到Excel表格,并将表中存储的照片(OLE对象)以其中一个字段(编号)命名存储到本地.程序中引入了ADO操作Access数据库("C:\ ...
- 使用NPOI插件读取excel模版修改数据后保存到新目录新文件中
添加引用: using System.IO; using NPOI.XSSF.UserModel; using NPOI.SS.UserModel; using NPOI.HSSF.UserModel ...
随机推荐
- 【巩固】Bootstrap笔记三
这段笔记介绍了bootstrp中以下几点应用点: 警告框的使用 面板功能 运用chart.js制作图表 进度条的制作 媒体对象的制作 有一个元素如果有属性alert-dismissible" ...
- 动态linq to list排序
public class QeurySort { public static IList<T> Sort<T>(IList<T> list,string sidx, ...
- 作业总结(一):IE6下面的那些坑
考完试就来实习的公司实习了,大概最近有两周时间就一直在做公司给新人布置的大作业.虽然只是很简单的一个小的项目,但却从其中总结到了不少有用的东西.计划将其发出来一系列文章,算是对这两周时间的总结.也算是 ...
- R&S学习笔记(三)
1.GRE OVER IPv4 GRE协议栈:IPSEC只支持TCP/IP协议的网络,GRE则支持多协议,不同的网络类型.(如IPX,APPLETALK):通常IPSEC over gre结合使用, ...
- linux基础2——gdb调试器
gdb调试器使用的一般步骤(不断更新完善): 1.编译过程中要用-g参数来添加调试符号——gcc test.c -g: 2.gdb启动可执行文件——gdb a.out: 3.出现gdb符号表示启动成功 ...
- dsquery、netdom工具示例
C:\>netdom query fsmo架构主机 DC1.lypower.com.cn域命名主机 DC1.lypower.com.cnPDC ...
- Android自动化学习笔记:编写MonkeyRunner脚本的几种方式
---------------------------------------------------------------------------------------------------- ...
- where 子句中使用通配符
模糊匹配 ------------------------模糊匹配----------------- '[1-9]'.'[a-z]'.'[^4]' select * from student wher ...
- THINKPHP中关于接口问题(客户端)
一 apk版本号 客户端发送get请求访问服务器端的控制器方法,通过用户传过来的用户名和密码. 二 服务器端通过客户端传入的user and password 去数据库进行查询,Success就生成 ...
- 17.linux下root用户与普通用户
默认安装完成之后并不知道root用户的密码,那么如何应用root权限呢? (1)sudo 命令 这样输入当前管理员用户密码就可以得到超级用户的权限.但默认的情况下5分钟root权限就失效了. (2 ...