- UID
- 961
- 帖子
- 4088
- 积分
- 13454
- 阅读权限
- 70
- 注册时间
- 2005-7-11
- 最后登录
- 2015-6-19
- 在线时间
- 5897 小时
|
class CAOZUOEXCEL
{
public DataSet duquexcel(string wenjianm)//导出EXCEL数据到数据集
{
string strCon = "Provider= Microsoft.Jet.OLEDB.4.0;Data Source=" + wenjianm + ";Extended Properties=Excel 8.0";
OleDbConnection conn = new OleDbConnection(strCon);
string sql = "select * from [DRB$]";
conn.Open();
OleDbDataAdapter myCommand = new OleDbDataAdapter(sql, strCon);
DataSet ds = new DataSet();
myCommand.Fill(ds, "[DRB$]");
conn.Close();
return ds;
}
public bool genxinexcel(DataSet ds,int rowindex,int coll, string fileName)//更新ACCESS 查询到EXCEL ROWINDEX 为列 COLL为行
{
if (ds.Tables.Count == 0 || fileName == string.Empty) //判断文件名或数据集是否为空
{
return false;
}
object a =System.Reflection.Missing.Value;
Excel.Application excel = new Excel.ApplicationClass();
excel.Workbooks.Open(fileName,a, false , a,a, a,a,a,a,a,a,a,a);
int colindex;
System.Data.DataTable table = ds.Tables[0];
foreach (DataRow row in table.Rows)
{
rowindex++;
colindex = coll;
foreach (DataColumn col in table.Columns)
{
colindex++;
excel.Cells[rowindex, colindex] = row[col.ColumnName].ToString();
}
}
table.Dispose();
MessageBox.Show("导出EXCEL 结束");
excel.Visible = true;
// excel.Quit();
// excel = null;
// GC.Collect();
return true;
}
}
我不是码农只是工作需要 业余编写一下程序 |
|