using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.OleDb;
using Lodge.ToolKit.Common;
public partial class GameInfo_GameXml : System.Web.UI.Page
{
/// <summary>
/// 读取Excel 文件 转换为(DataSet)DataTable,在转化成.xml文件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Page_Load(object sender, EventArgs e)
{
string fileName = "daoju";
DataTable dtResult = new DataTable();
try
{
string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath("~/App_Data/")+fileName + ".xls;Extended Properties='Excel 8.0;HDR=No;IMEX=1'";
using (OleDbConnection connect = new OleDbConnection(strConn))
{
OleDbDataAdapter command = new OleDbDataAdapter("select F1 as imgName,F3 as name,F4 as intro from[Sheet1$]", connect);
DataSet ds = new DataSet();
command.Fill(ds);
if (ds.Tables.Count > 0)
dtResult = ds.Tables[0];
}
}
catch (Exception ex)
{
LogUtility.Add(ex); //web.config 配置异常处理
}
dtResult.TableName = "Item";
dtResult.DataSet.DataSetName = "ItemList";
dtResult.WriteXml(Server.MapPath("~/App_Data/")+fileName+".xml");
}
}