public void CreateExcel(string FileName)
{
typeModel.cType_Code = dropType.SelectedValue;
wareModel.cWare_Code = dropWare.SelectedValue;
if (txtEmpName.Text == "" || txtEmpName.Text == null)
{
assetModel.emp_Id = dropEmp.SelectedValue.Trim();
}
else
{
employeeModel.Emp_Name = txtEmpName.Text;
}
if (dropDepartment.SelectedValue != "")
{
Desktop.BLL.Department newdepartment = new Desktop.BLL.Department();
departmentModel.cChild = newdepartment.GetcChild(dropDepartment.SelectedValue);
}
employeeModel.beWorking = dropUserStatus.SelectedValue;
assetModel.cAsset_Name = txtName.Text;
assetModel.cAsset_Set = txtSet.Text;
assetModel.cAsset_From = dropFrom.SelectedItem.Text;
assetModel.cAsset_Status = dropStatus.SelectedItem.Text;
if (dtpBeginTime.HasValue == true)
{
assetModel.dBuy_Date = dtpBeginTime.Value;
}
if (dtpEndTime.HasValue == true)
{
assetModel.dReg_Date = dtpEndTime.Value;
}
if (txtPriceMin.Text != "")
{
assetModel.iPrice = decimal.Parse(txtPriceMin.Text);
}
if (txtPriceMax.Text != "")
{
assetModel.iCurPrice = decimal.Parse(txtPriceMax.Text);
}
assetModel.cCheck = dropCheckStatus.SelectedValue;
assetModel.cBudNo = txtBudNo.Text;
assetModel.cAccNo = txtAccNo.Text;
assetModel.cAssetNo = txtAssetNo.Text;
assetModel.cCheckNo = txtCheckNo.Text;
assetModel.cAccCorp = txtAccCorp.Text;
assetModel.cAccCurCorp = txtAccCurCorp.Text;
assetModel.cSelYes = DropYes.SelectedValue;
DataSet ds = asset.GetAssetMain(assetModel, typeModel, wareModel, employeeModel, departmentModel, "");//产生dataset
//主要方法体:
HttpResponse resp;
resp = Page.Response;
resp.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
resp.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(FileName, System.Text.Encoding.UTF8) + ".xls");
string colHeaders = "", ls_item = "";
//定义表对象与行对象,同时用DataSet对其值进行初始化
System.Data.DataTable dt = ds.Tables[0];
DataRow[] myRow = dt.Select();//可以类似dt.Select("id>10")之形式达到数据筛选目的
int i = 0;
int cl = dt.Columns.Count;
//取得数据表各列标题,各标题之间以t分割,最后一个列标题后加回车符
for (i = 0; i < cl; i++)
{
if (i == (cl - 1))//最后一列,加n
{
colHeaders += dt.Columns[i].Caption.ToString() + "\n";
}
else
{
colHeaders += dt.Columns[i].Caption.ToString() + "\t";
}
}
resp.Write(colHeaders);
//向HTTP输出流中写入取得的数据信息
//逐行处理数据
foreach (DataRow row in myRow)
{
//当前行数据写入HTTP输出流,并且置空ls_item以便下行数据
for (i = 0; i < cl; i++)
{
if (i == (cl - 1))//最后一列,加n
{
ls_item += row[i].ToString() + "\n";
}
else
{
ls_item += row[i].ToString() + "\t";
}
}
resp.Write(ls_item);
ls_item = "";
}
resp.End();
}