[ת]C#.net±à³Ì´´½¨ Access ÎļþºÍ Excel Îļþ
һЩϵͳ¿ÉÄÜÐèÇó°ÑÊý¾Ýµ¼³öµ½Access»òÕßExcelÎļþ¸ñʽ£¬ÒÔ·½±ãµÄ´«µÝÊý¾Ý¡¢´òÓ¡µÈ¡£
Excel Îļþ»òÕß AccessÕâÁ½ÖÖÐèÒªµ¼³öµÄÎļþ¿ÉÄܲ¢²»ÊÇÊÂÏȾʹæÔڵģ¬Õâ¾ÍÐèÒªÎÒÃÇ×Ô¼º±à³ÌÉú³ÉËûÃÇ£¬ÏÂÃæÕûÀíÒ»ÏÂÉú³ÉÕâÁ½¸öÎļþµÄһЩ·½·¨£¬Ö»ÂÞÁÐ×î³£Óõġ£²¢²»È«¡£
Ò»¡¢Ê×ÏÈÉú³ÉExcelÎļþ¡£
·½°¸Ò»¡¢Èç¹ûÓÃExcel±£´æµÄÖ»ÊǶþάÊý¾Ý£¬Ò²¾ÍÊÇ°ÑËûµ±Êý¾Ý¿âµÄÀ´Óá£
×î¼òµ¥£¬Äã²»ÓÃÒýÓÃÈκζîÍâ×é¼þ£¬Ö»ÐèÒªÓà OLEDB ¾Í¿ÉÒÔÍê³É´´½¨ExcelÎļþ¡£ ·¶Àý´úÂëÈçÏ¡£
using System.Data.OleDb;
public static void CreateExcelFile2()
{
string OLEDBConnStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\\aa2.xls;";
OLEDBConnStr += " Extended Properties=Excel 8.0;";
string strCreateTableSQL = @" CREATE TABLE ";
strCreateTableSQL += @" ²âÊÔ±í ";
strCreateTableSQL += @" ( ";
strCreateTableSQL += @" ID INTEGER, ";
strCreateTableSQL += @" UserID INTEGER, ";
strCreateTableSQL += @" UserIP VARCHAR , ";
strCreateTableSQL += @" PostTime DATETIME , ";
strCreateTableSQL += @" fromParm VARCHAR ";
strCreateTableSQL += @" ) ";
OleDbConnection oConn = new OleDbConnection();
oConn.ConnectionString = OLEDBConnStr;
OleDbCommand oCreateComm = new OleDbCommand();
oCreateComm.Connection = oConn;
oCreateComm.CommandText = strCreateTableSQL;
oConn.Open();
oCreateComm.ExecuteNonQuery();
oConn.Close();
}
using System.Data.OleDb;
public static void CreateExcelFile2()
{
string OLEDBConnStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\\aa2.xls;";
OLEDBConnStr += " Extended Properties=Excel 8.0;";
string strCreateTableSQL = @" CREATE TABLE ";
strCreateTableSQL += @" ²âÊÔ±í ";
strCreateTableSQL += @" (
Ïà¹ØÎĵµ£º
¼´Ê¹ÎÒ½«Êý¾Ý¿â·ÅÔÚÏîÄ¿ÄÚ½¨µÄÎļþ¼ÐdbÏ£¬¿ÉÊǽøÐд洢²Ù×÷µÄʱºò£¬Êý¾Ý±íûÓÐÈκα仯¡£ºóÀ´·¢ÏÖ´¢´æ¸Ä±ä·¢ÉúÔÚbin\\debug\\dbĿ¼ÏµÄÊý¾Ý¿âÖУ¬Õâ¸öÊý¾Ý¿âÊÇÔÚ³ÌÐòÔËÐÐʱ×Ô¶¯¸´ÖƹýÈ¥µÄ£¬¿ÉÊÇΪʲô´æ´¢±ä»¯Ã»Óз´Ó¦µ½ÍâÃæÏîÄ¿ÄÚµÄÊý¾Ý¿âdbÏÂÄØ£¿ÎÒÏëÁ¬½Ó×Ö·û´®ÖÐdatasourceÖеÄdatadirectory´æÔÚһЩÐþ»ú£¬ÓÚÊÇÎÒÕÒµ½Ò ......
Ê×Ò³£º
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head ......
PBÖÐÁ¬½ÓAccessÊý¾Ý¿âµÄÈýÖÖ·½·¨
·½Ê½Ò»£º
SQLCA.DBMS = "ODBC"
SQLCA.AutoCommit = False
SQLCA.DBParm = "ConnectString='driver=Microsoft Access Driver (*.mdb);DBQ=c:\foodmart.mdb'"
CONNECT;
IF SQLCA.SQLCode <> 0 THEN
MessageBo ......
·¢²¼ÈÕÆÚ : 8/8/2003 | ¸üÐÂÈÕÆÚ : 6/7/2004
Martin Tracy
Visual Studio Team
Microsoft Corporation
ÊÊÓÃÓÚ£º Microsoft® ADO.NET
Microsoft® ASP.NET
Microsoft® Visual C#® .NET
Microsoft® Visual Studio® .NET
ÕªÒª£º±¾ÑÝÁ·ËµÃ÷ÁËÈçºÎʹÓüòµ¥µÄ Visual C#® ÄÚº¬´úÂë Web Ó¦ÓÃ³Ì ......
public void ExportExcel(DataTable dtData, string filename)
{
System.Web.UI.WebControls.DataGrid dgExport = null;
// µ±Ç°¶Ô»°
Sy ......