722 lines
26 KiB
C#
722 lines
26 KiB
C#
|
|
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.IO;
|
|||
|
|
using NPOI.HSSF.UserModel;
|
|||
|
|
using NPOI.SS.UserModel;
|
|||
|
|
using NPOI.XSSF.UserModel;
|
|||
|
|
using System.Xml;
|
|||
|
|
using System.Collections.Generic;
|
|||
|
|
using System.Data.OleDb;
|
|||
|
|
using WeiSha.Common;
|
|||
|
|
|
|||
|
|
|
|||
|
|
namespace Song.Site.Manage.Utility
|
|||
|
|
{
|
|||
|
|
public partial class ExcelInput : System.Web.UI.UserControl
|
|||
|
|
{
|
|||
|
|
#region <EFBFBD><EFBFBD><EFBFBD>ԣ<EFBFBD><EFBFBD>¼<EFBFBD>
|
|||
|
|
public event EventHandler Input;
|
|||
|
|
//<2F>ĵ<EFBFBD><C4B5>ϴ<EFBFBD><CFB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD>·<EFBFBD><C2B7>
|
|||
|
|
private string _tempPathConfig = "Temp";
|
|||
|
|
//Excel<65><6C><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD>
|
|||
|
|
string connStr = "Provider=Microsoft.Ace.OleDb.12.0;data source={0};Extended Properties='Excel 12.0; HDR=NO; IMEX=1'";
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20><><EFBFBD><EFBFBD>ģ<EFBFBD><C4A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
/// </summary>
|
|||
|
|
public string TemplateName
|
|||
|
|
{
|
|||
|
|
get
|
|||
|
|
{
|
|||
|
|
object obj = ViewState["TemplateName"];
|
|||
|
|
return (obj == null) ? "" : obj.ToString();
|
|||
|
|
}
|
|||
|
|
set
|
|||
|
|
{
|
|||
|
|
ViewState["TemplateName"] = value;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20><><EFBFBD><EFBFBD>ģ<EFBFBD><C4A3><EFBFBD><EFBFBD>·<EFBFBD><C2B7>
|
|||
|
|
/// </summary>
|
|||
|
|
public string TemplatePath
|
|||
|
|
{
|
|||
|
|
get
|
|||
|
|
{
|
|||
|
|
object obj = ViewState["TemplatePath"];
|
|||
|
|
return (obj == null) ? "" : obj.ToString();
|
|||
|
|
}
|
|||
|
|
set
|
|||
|
|
{
|
|||
|
|
ViewState["TemplatePath"] = value;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20><>¼Excel<65><6C><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD><DDBF>ֶζ<D6B6>Ӧ<EFBFBD><D3A6>ϵ<EFBFBD><CFB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>
|
|||
|
|
/// </summary>
|
|||
|
|
public string Config
|
|||
|
|
{
|
|||
|
|
get
|
|||
|
|
{
|
|||
|
|
object obj = ViewState["Config"];
|
|||
|
|
return (obj == null) ? "" : obj.ToString();
|
|||
|
|
}
|
|||
|
|
set
|
|||
|
|
{
|
|||
|
|
ViewState["Config"] = value;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
public List<string> Keys
|
|||
|
|
{
|
|||
|
|
get
|
|||
|
|
{
|
|||
|
|
return GetKeys();
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
private DataTable _sheetData;
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20><>ǰ<EFBFBD><C7B0>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD>Ĺ<EFBFBD><C4B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݼ<EFBFBD>
|
|||
|
|
/// </summary>
|
|||
|
|
public DataTable SheetDataTable
|
|||
|
|
{
|
|||
|
|
get { return _sheetData; }
|
|||
|
|
set { _sheetData = value; }
|
|||
|
|
}
|
|||
|
|
private List<DataRow> _errorDataRow = new List<DataRow>();
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20><><EFBFBD><EFBFBD>ʧ<EFBFBD>ܵ<EFBFBD><DCB5><EFBFBD><EFBFBD>ݼ<EFBFBD>
|
|||
|
|
/// </summary>
|
|||
|
|
public List<DataRow> ErrorDataRows
|
|||
|
|
{
|
|||
|
|
get { return _errorDataRow; }
|
|||
|
|
}
|
|||
|
|
private Dictionary<String, String> _dataRelation;
|
|||
|
|
/// <summary>
|
|||
|
|
/// Excel<65><6C><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD><DDBF>ֶζ<D6B6>Ӧ<EFBFBD><D3A6>ϵ<EFBFBD><CFB5>ǰ<EFBFBD><C7B0>ΪExcel<65><6C><EFBFBD><EFBFBD>(keyֵ<79><D6B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD>ݿ<EFBFBD><DDBF>ֶ<EFBFBD><D6B6><EFBFBD><EFBFBD><EFBFBD>valueֵ<65><D6B5>
|
|||
|
|
/// </summary>
|
|||
|
|
public Dictionary<String, String> DataRelation
|
|||
|
|
{
|
|||
|
|
get { return _dataRelation; }
|
|||
|
|
set { _dataRelation = value; }
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
#endregion
|
|||
|
|
protected void Page_Load(object sender, EventArgs e)
|
|||
|
|
{
|
|||
|
|
if (!this.IsPostBack)
|
|||
|
|
{
|
|||
|
|
//<2F><><EFBFBD><EFBFBD>ģ<EFBFBD><C4A3>
|
|||
|
|
linkDataTmp.NavigateUrl = this.ResolveUrl(this.TemplatePath);
|
|||
|
|
linkDataTmp.Text = linkDataTmp.Text.Replace("{0}", this.TemplateName);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20><><EFBFBD>ӵ<EFBFBD><D3B5><EFBFBD>ʧ<EFBFBD>ܵ<EFBFBD><DCB5><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="dr"></param>
|
|||
|
|
public void AddError(DataRow dr)
|
|||
|
|
{
|
|||
|
|
_errorDataRow.Add(dr);
|
|||
|
|
}
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20><>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD>ϴ<EFBFBD><CFB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="sender"></param>
|
|||
|
|
/// <param name="e"></param>
|
|||
|
|
protected void btnUp_Click(object sender, EventArgs e)
|
|||
|
|
{
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
if (fuLoad.PostedFile.FileName != "")
|
|||
|
|
{
|
|||
|
|
fuLoad.UpPath = _tempPathConfig;
|
|||
|
|
fuLoad.IsMakeSmall = false;
|
|||
|
|
fuLoad.IsConvertJpg = false;
|
|||
|
|
fuLoad.SaveAs();
|
|||
|
|
ViewState["dataFilePath"] = fuLoad.File.Server.FileFullName;
|
|||
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
DataTable table = this.GetSheets(fuLoad.File.Server.FileFullName);
|
|||
|
|
dlWorkBook.DataSource = table;
|
|||
|
|
dlWorkBook.DataBind();
|
|||
|
|
//״̬
|
|||
|
|
ltSheetCount.Text = table.Rows.Count.ToString();
|
|||
|
|
//
|
|||
|
|
lbState.Text = "<22><><EFBFBD>ڲ<EFBFBD><DAB2><EFBFBD><EFBFBD>ĵ<EFBFBD> <20><>" + fuLoad.File.Client.FileName + "<22><>";
|
|||
|
|
btnNext1.Visible = true;
|
|||
|
|
lbFile2.Text = fuLoad.File.Client.FileName;
|
|||
|
|
//
|
|||
|
|
fdPanel1.Visible = false;
|
|||
|
|
fdPanel2.Visible = true;
|
|||
|
|
lbError2.Text = "";
|
|||
|
|
//<2F><><EFBFBD><EFBFBD>ֻ<EFBFBD><D6BB>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֱ<EFBFBD><D6B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>
|
|||
|
|
if (table.Rows.Count == 1)
|
|||
|
|
{
|
|||
|
|
foreach (DataListItem dli in dlWorkBook.Items)
|
|||
|
|
{
|
|||
|
|
Button lb = (Button)dli.FindControl("btnWorkBook");
|
|||
|
|
btnSheet_Click(lb, null);
|
|||
|
|
break;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
catch (Exception ex)
|
|||
|
|
{
|
|||
|
|
lbError1.Text = ex.Message;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20>ڶ<EFBFBD><DAB6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѡ<EFBFBD><D1A1><EFBFBD>İ<EFBFBD>ť<EFBFBD>¼<EFBFBD>
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="sender"></param>
|
|||
|
|
/// <param name="e"></param>
|
|||
|
|
protected void btnSheet_Click(object sender, EventArgs e)
|
|||
|
|
{
|
|||
|
|
lbFile3.Text = lbFile2.Text;
|
|||
|
|
//<2F><>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD><EFBFBD>Ĺ<EFBFBD><C4B9><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
string sheetText = ((Button)sender).Text;
|
|||
|
|
lbSheet3.Text = "<22><>" + sheetText.Substring(0, sheetText.IndexOf("<22><>")) + "<22><><EFBFBD><EFBFBD>" + sheetText.Substring(sheetText.IndexOf("<22><>") + 1);
|
|||
|
|
//Ҫ<><D2AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Excel<65>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD>빤<EFBFBD><EBB9A4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
string xlsFile = ViewState["dataFilePath"].ToString();
|
|||
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
int sheetIndex = Convert.ToInt32(((Button)sender).CommandArgument);
|
|||
|
|
ViewState["sheetIndex"] = sheetIndex;
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
//DataTable dtRows = SheetToDatatable(xlsFile, sheetIndex);
|
|||
|
|
//if (dtRows.Rows.Count < 1) throw new Exception("<22><>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
|
|||
|
|
//<2F><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
DataTable dtColumn = this.GetSheetColumn(xlsFile, sheetIndex);
|
|||
|
|
dlColumn.DataSource = dtColumn;
|
|||
|
|
dlColumn.DataBind();
|
|||
|
|
//Ԥ<>õ<EFBFBD><C3B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֶεĶ<CEB5>Ӧ<EFBFBD><D3A6>ϵ
|
|||
|
|
DataTable dtConfig = getConfig();
|
|||
|
|
//<2F>Զ<EFBFBD>ʶ<EFBFBD><CAB6>excel<65><6C><EFBFBD>ֶ<EFBFBD><D6B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD><DDBF><EFBFBD><EFBFBD>ַ<EFBFBD>ƥ<EFBFBD><C6A5>
|
|||
|
|
for (int i = 0; i < dlColumn.Items.Count; i++)
|
|||
|
|
{
|
|||
|
|
DataListItem dli = dlColumn.Items[i];
|
|||
|
|
//<2F><><EFBFBD><EFBFBD>
|
|||
|
|
Label lb = (Label)dli.FindControl("lbColumn");
|
|||
|
|
//<2F><EFBFBD>Ӧ<EFBFBD><D3A6>ϵ<EFBFBD><CFB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
DropDownList ddl = (DropDownList)dli.FindControl("ddlColumnForField");
|
|||
|
|
ddl.DataSource = dtConfig;
|
|||
|
|
ddl.DataTextField = "Column";
|
|||
|
|
ddl.DataValueField = "Field";
|
|||
|
|
ddl.DataBind();
|
|||
|
|
ddl.Items.Insert(0, new ListItem("", ""));
|
|||
|
|
//<2F>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD>ö<EFBFBD>Ӧ<EFBFBD><D3A6>ϵ
|
|||
|
|
setDataList(lb.Text, ddl);
|
|||
|
|
if (i > 30) break;
|
|||
|
|
}
|
|||
|
|
fdPanel2.Visible = false;
|
|||
|
|
fdPanel3.Visible = true;
|
|||
|
|
lbError3.Text = "";
|
|||
|
|
}
|
|||
|
|
catch (Exception ex)
|
|||
|
|
{
|
|||
|
|
lbError2.Text = ex.Message;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݵİ<DDB5>ť<EFBFBD>¼<EFBFBD>
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="sender"></param>
|
|||
|
|
/// <param name="e"></param>
|
|||
|
|
protected void btnInput_Click(object sender, EventArgs e)
|
|||
|
|
{
|
|||
|
|
fdPanel5.Visible = false;
|
|||
|
|
btnOutpt.Visible = false;
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
//ʵ<>ʵ<EFBFBD><CAB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֶεĹ<CEB5>ϵ
|
|||
|
|
this._dataRelation = getColumnForField();
|
|||
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
string file = ViewState["dataFilePath"].ToString();
|
|||
|
|
int sheetIndex = Convert.ToInt32(ViewState["sheetIndex"].ToString());
|
|||
|
|
this._sheetData = this.SheetToDatatable(file, sheetIndex);
|
|||
|
|
//*****************
|
|||
|
|
//ִ<>е<EFBFBD><D0B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݵ<EFBFBD><DDB5>¼<EFBFBD>
|
|||
|
|
if (Input != null)
|
|||
|
|
this.Input(sender, e);
|
|||
|
|
//
|
|||
|
|
lbFile4.Text = lbFile3.Text;
|
|||
|
|
lbSheet4.Text = lbSheet3.Text;
|
|||
|
|
fdPanel3.Visible = false;
|
|||
|
|
fdPanel4.Visible = true;
|
|||
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ĵ<EFBFBD><C4B4><EFBFBD>
|
|||
|
|
lbErrorCount.Text = ErrorDataRows.Count.ToString();
|
|||
|
|
lbSuccCount.Text = (SheetDataTable.Rows.Count - ErrorDataRows.Count).ToString();
|
|||
|
|
if (ErrorDataRows.Count > 0)
|
|||
|
|
{
|
|||
|
|
fdPanel5.Visible = true;
|
|||
|
|
btnOutpt.Visible = true;
|
|||
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
DataTable dtErr = SheetDataTable.Clone();
|
|||
|
|
foreach (DataRow dr in ErrorDataRows)
|
|||
|
|
{
|
|||
|
|
dtErr.ImportRow(dr);
|
|||
|
|
}
|
|||
|
|
gvError.DataSource = dtErr;
|
|||
|
|
gvError.DataBind();
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
catch (Exception ex)
|
|||
|
|
{
|
|||
|
|
lbError3.Text = ex.Message;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
#region <EFBFBD><EFBFBD><EFBFBD><EFBFBD>Excel<EFBFBD>ķ<EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
/// <summary>
|
|||
|
|
/// ͨ<><CDA8>Excel<65>ĵ<EFBFBD><C4B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD>Ĵ<EFBFBD><C4B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="xlsFile"></param>
|
|||
|
|
/// <returns></returns>
|
|||
|
|
private IWorkbook createWorkbook(string xlsFile)
|
|||
|
|
{
|
|||
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
IWorkbook workbook = null;
|
|||
|
|
using (FileStream file = new FileStream(xlsFile, FileMode.Open, FileAccess.Read))
|
|||
|
|
{
|
|||
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>չ<EFBFBD><D5B9><EFBFBD>ж<EFBFBD>excel<65>汾
|
|||
|
|
string ext = xlsFile.Substring(xlsFile.LastIndexOf(".") + 1);
|
|||
|
|
//WorkbookFactory.Create(file);
|
|||
|
|
if (ext.ToLower() == "xls") workbook = new HSSFWorkbook(file);
|
|||
|
|
if (ext.ToLower() == "xlsx") workbook = new XSSFWorkbook(file);
|
|||
|
|
}
|
|||
|
|
return workbook;
|
|||
|
|
}
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20><>Excel<65>ж<EFBFBD>ȡһ<C8A1><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Datatable<6C><65><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="xlsFile"></param>
|
|||
|
|
/// <param name="sheetIndex"></param>
|
|||
|
|
/// <returns></returns>
|
|||
|
|
private DataTable SheetToDatatable(string xlsFile, int sheetIndex)
|
|||
|
|
{
|
|||
|
|
DataTable dt = new DataTable();
|
|||
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
IWorkbook workbook = createWorkbook(xlsFile);
|
|||
|
|
ISheet sheet = workbook.GetSheetAt(sheetIndex);
|
|||
|
|
System.Collections.IEnumerator rows = sheet.GetRowEnumerator();
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
rows.MoveNext();
|
|||
|
|
//<2F><><EFBFBD><EFBFBD>Datatable<6C>ṹ
|
|||
|
|
HSSFRow firsRow = (HSSFRow)rows.Current;
|
|||
|
|
for (int i = 0; i < firsRow.LastCellNum; i++)
|
|||
|
|
{
|
|||
|
|
ICell cell = firsRow.GetCell(i);
|
|||
|
|
if (cell == null || string.IsNullOrWhiteSpace(cell.ToString())) continue;
|
|||
|
|
dt.Columns.Add(new DataColumn(cell.ToString(), getColumnType(cell.ToString())));
|
|||
|
|
}
|
|||
|
|
//<2F><><EFBFBD>빤<EFBFBD><EBB9A4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
while (rows.MoveNext())
|
|||
|
|
{
|
|||
|
|
HSSFRow row = (HSSFRow)rows.Current;
|
|||
|
|
DataRow dr = dt.NewRow();
|
|||
|
|
for (int i = 0; i < dt.Columns.Count; i++)
|
|||
|
|
{
|
|||
|
|
ICell cell = row.GetCell(i);
|
|||
|
|
if (cell == null) continue;
|
|||
|
|
string value = cell.ToString();
|
|||
|
|
//<2F><>ȡExcel<65><6C>ʽ<EFBFBD><CABD><EFBFBD><EFBFBD><EFBFBD>ݸ<EFBFBD>ʽ<EFBFBD><CABD>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
switch (dt.Columns[i].DataType.FullName)
|
|||
|
|
{
|
|||
|
|
case "System.DateTime": //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
if (DateUtil.IsValidExcelDate(cell.NumericCellValue))
|
|||
|
|
{
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
value = cell.DateCellValue.ToString();
|
|||
|
|
}
|
|||
|
|
catch
|
|||
|
|
{
|
|||
|
|
value = cell.ToString();
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
value = cell.NumericCellValue.ToString();
|
|||
|
|
}
|
|||
|
|
break;
|
|||
|
|
|
|||
|
|
default:
|
|||
|
|
value = cell.ToString();
|
|||
|
|
break;
|
|||
|
|
}
|
|||
|
|
dr[i] = WeiSha.Common.Param.Method.ConvertToAnyValue.Get(value).ChangeType(dt.Columns[i].DataType);
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
dt.Rows.Add(dr);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
catch
|
|||
|
|
{
|
|||
|
|
return dt;
|
|||
|
|
}
|
|||
|
|
return dt;
|
|||
|
|
}
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20><>ȡ<EFBFBD>е<EFBFBD><D0B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="colname"></param>
|
|||
|
|
/// <returns></returns>
|
|||
|
|
private System.Type getColumnType(string colname)
|
|||
|
|
{
|
|||
|
|
DataTable dtConfing = getConfig();
|
|||
|
|
System.Type type=null;
|
|||
|
|
foreach (DataRow dr in dtConfing.Rows)
|
|||
|
|
{
|
|||
|
|
if (colname.ToLower().Trim() == dr["Column"].ToString().ToLower().Trim())
|
|||
|
|
{
|
|||
|
|
if (dr["DataType"].ToString().ToLower().Trim() == "date") type = Type.GetType("System.DateTime");
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
if (type == null) type = Type.GetType("System.String");
|
|||
|
|
return type;
|
|||
|
|
}
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20><>ȡ<EFBFBD>ĵ<EFBFBD><C4B5>е<EFBFBD><D0B5><EFBFBD><EFBFBD>й<EFBFBD><D0B9><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="xlsFile"></param>
|
|||
|
|
/// <returns></returns>
|
|||
|
|
private DataTable GetSheets(string xlsFile)
|
|||
|
|
{
|
|||
|
|
DataTable dt = new DataTable();
|
|||
|
|
dt.Columns.Add(new DataColumn("Name"));
|
|||
|
|
dt.Columns.Add(new DataColumn("Count"));
|
|||
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
IWorkbook workbook = createWorkbook(xlsFile);
|
|||
|
|
int sheetNum = workbook.NumberOfSheets;
|
|||
|
|
for (int i = 0; i < sheetNum; i++)
|
|||
|
|
{
|
|||
|
|
DataRow dr = dt.NewRow();
|
|||
|
|
dr["Name"] = workbook.GetSheetAt(i).SheetName;
|
|||
|
|
dr["Count"] = workbook.GetSheetAt(i).LastRowNum;
|
|||
|
|
dt.Rows.Add(dr);
|
|||
|
|
}
|
|||
|
|
return dt;
|
|||
|
|
}
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>б<EFBFBD><D0B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD>еı<D0B5><C4B1><EFBFBD>
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="xlsFile"></param>
|
|||
|
|
/// <param name="sheetIndex"></param>
|
|||
|
|
/// <returns></returns>
|
|||
|
|
private DataTable GetSheetColumn(string xlsFile, int sheetIndex)
|
|||
|
|
{
|
|||
|
|
DataTable dtSch = new DataTable("SheetStructure");
|
|||
|
|
dtSch.Columns.Add(new DataColumn("Name", Type.GetType("System.String")));
|
|||
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
IWorkbook workbook = createWorkbook(xlsFile);
|
|||
|
|
ISheet sheet = workbook.GetSheetAt(sheetIndex);
|
|||
|
|
System.Collections.IEnumerator rows = sheet.GetRowEnumerator();
|
|||
|
|
rows.MoveNext();
|
|||
|
|
//<2F><><EFBFBD><EFBFBD>Datatable<6C>ṹ
|
|||
|
|
IRow firsRow = (IRow)rows.Current;
|
|||
|
|
for (int i = 0; i < firsRow.LastCellNum; i++)
|
|||
|
|
{
|
|||
|
|
DataRow dr = dtSch.NewRow();
|
|||
|
|
ICell cell = firsRow.GetCell(i);
|
|||
|
|
dr["Name"] = cell == null ? "(null)" + i : cell.ToString();
|
|||
|
|
dtSch.Rows.Add(dr);
|
|||
|
|
}
|
|||
|
|
return dtSch;
|
|||
|
|
}
|
|||
|
|
#endregion
|
|||
|
|
|
|||
|
|
#region <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֶζԱȵķ<EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
/// <summary>
|
|||
|
|
/// ͨ<><CDA8><EFBFBD>ֶΣ<D6B6><CEA3><EFBFBD>ȡ<EFBFBD><C8A1>Ӧ<EFBFBD><D3A6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="field"></param>
|
|||
|
|
/// <returns></returns>
|
|||
|
|
public string GetColumnForField(string field)
|
|||
|
|
{
|
|||
|
|
Dictionary<String, String> dic = this._dataRelation;
|
|||
|
|
if (dic.Count < 1) return "";
|
|||
|
|
foreach (KeyValuePair<String, String> kvp in dic)
|
|||
|
|
{
|
|||
|
|
if (kvp.Value == field) return kvp.Key;
|
|||
|
|
}
|
|||
|
|
return "";
|
|||
|
|
}
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>
|
|||
|
|
/// </summary>
|
|||
|
|
/// <returns></returns>
|
|||
|
|
public List<string> GetKeys()
|
|||
|
|
{
|
|||
|
|
List<string> keys = new List<string>();
|
|||
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>·<EFBFBD><C2B7>
|
|||
|
|
string path = App.Get["ExcelInputConfig"].VirtualPath;
|
|||
|
|
string config = this.Server.MapPath(path + this.Config);
|
|||
|
|
if (!System.IO.File.Exists(config)) return keys;
|
|||
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
XmlDocument resXml = new XmlDocument();
|
|||
|
|
resXml.Load(config);
|
|||
|
|
//<2F><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>
|
|||
|
|
XmlNode ele = resXml.LastChild;
|
|||
|
|
if (ele.Attributes["Keys"] == null) return keys;
|
|||
|
|
string[] keyscol = ele.Attributes["Keys"].Value.Split(',');
|
|||
|
|
//ƥ<><C6A5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
XmlNodeList nodes = resXml.GetElementsByTagName("item");
|
|||
|
|
//
|
|||
|
|
foreach (string k in keyscol)
|
|||
|
|
{
|
|||
|
|
foreach (XmlNode n in nodes)
|
|||
|
|
{
|
|||
|
|
string column = ((XmlElement)n).Attributes["Column"].Value;
|
|||
|
|
string field = ((XmlElement)n).Attributes["Field"].Value;
|
|||
|
|
if (k.Trim().ToLower() == column.Trim().ToLower())
|
|||
|
|
{
|
|||
|
|
keys.Add(field.Trim());
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
return keys;
|
|||
|
|
}
|
|||
|
|
/// <summary>
|
|||
|
|
/// ͨ<><CDA8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡ<EFBFBD><C8A1>Ӧ<EFBFBD><D3A6><EFBFBD>ֶ<EFBFBD>
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="column"></param>
|
|||
|
|
/// <returns></returns>
|
|||
|
|
public string GetFieldForColumn(string column)
|
|||
|
|
{
|
|||
|
|
Dictionary<String, String> dic = this._dataRelation;
|
|||
|
|
if (dic.Count < 1) return "";
|
|||
|
|
foreach (KeyValuePair<String, String> kvp in dic)
|
|||
|
|
{
|
|||
|
|
if (kvp.Key == column) return kvp.Value;
|
|||
|
|
}
|
|||
|
|
return "";
|
|||
|
|
}
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֶ<EFBFBD><D6B6><EFBFBD><EFBFBD>Ķ<EFBFBD>Ӧ<EFBFBD><D3A6>ϵ<EFBFBD><CFB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
/// </summary>
|
|||
|
|
private DataTable getConfig()
|
|||
|
|
{
|
|||
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
DataTable dt = new DataTable();
|
|||
|
|
dt.Columns.Add(new DataColumn("Column", Type.GetType("System.String")));
|
|||
|
|
dt.Columns.Add(new DataColumn("Field", Type.GetType("System.String")));
|
|||
|
|
dt.Columns.Add(new DataColumn("DataType", Type.GetType("System.String")));
|
|||
|
|
dt.Columns.Add(new DataColumn("Format", Type.GetType("System.String")));
|
|||
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>·<EFBFBD><C2B7>
|
|||
|
|
string path = App.Get["ExcelInputConfig"].VirtualPath;
|
|||
|
|
string config = this.Server.MapPath(path + this.Config);
|
|||
|
|
if (!System.IO.File.Exists(config)) return dt;
|
|||
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
XmlDocument resXml = new XmlDocument();
|
|||
|
|
resXml.Load(config);
|
|||
|
|
XmlNodeList nodes = resXml.GetElementsByTagName("item");
|
|||
|
|
foreach (XmlNode n in nodes)
|
|||
|
|
{
|
|||
|
|
XmlElement el = (XmlElement)n;
|
|||
|
|
DataRow dr = dt.NewRow();
|
|||
|
|
dr["Column"] = el.Attributes["Column"].Value;
|
|||
|
|
dr["Field"] = el.Attributes["Field"].Value;
|
|||
|
|
dr["DataType"] = el.Attributes["DataType"] != null ? el.Attributes["DataType"].Value : null;
|
|||
|
|
dr["Format"] = el.Attributes["Format"] != null ? el.Attributes["Format"].Value : null;
|
|||
|
|
dt.Rows.Add(dr);
|
|||
|
|
}
|
|||
|
|
return dt;
|
|||
|
|
}
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20><>ȡʵ<C8A1>ʵ<EFBFBD><CAB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֶεĹ<CEB5>ϵ,Dictionary<String, String> ǰ<><C7B0>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD>ֶ<EFBFBD><D6B6><EFBFBD>
|
|||
|
|
/// </summary>
|
|||
|
|
/// <returns></returns>
|
|||
|
|
private Dictionary<String, String> getColumnForField()
|
|||
|
|
{
|
|||
|
|
Dictionary<String, String> dic = new Dictionary<string, string>();
|
|||
|
|
for (int i = 0; i < dlColumn.Items.Count; i++)
|
|||
|
|
{
|
|||
|
|
DataListItem dli = dlColumn.Items[i];
|
|||
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD><D3A6><EFBFBD>ֶ<EFBFBD>
|
|||
|
|
Label lb = (Label)dli.FindControl("lbColumn");
|
|||
|
|
DropDownList ddl = (DropDownList)dli.FindControl("ddlColumnForField");
|
|||
|
|
if (!dic.ContainsKey(lb.Text))
|
|||
|
|
dic.Add(lb.Text, ddl.SelectedValue);
|
|||
|
|
}
|
|||
|
|
return dic;
|
|||
|
|
}
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѡ<EFBFBD><D1A1><EFBFBD>е<EFBFBD><D0B5>ĸ<EFBFBD><C4B8>Ϊѡ<CEAA><D1A1>״̬
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="label"><3E>ֶ<EFBFBD><D6B6><EFBFBD><EFBFBD>ƣ<EFBFBD><C6A3><EFBFBD>Ӧ<EFBFBD><D3A6><EFBFBD>ݿ<EFBFBD>˵<EFBFBD><CBB5><EFBFBD><EFBFBD></param>
|
|||
|
|
/// <param name="ddl"></param>
|
|||
|
|
private void setDataList(string label, DropDownList ddl)
|
|||
|
|
{
|
|||
|
|
for (int i = 0; i < ddl.Items.Count; i++)
|
|||
|
|
{
|
|||
|
|
if (label == ddl.Items[i].Text)
|
|||
|
|
{
|
|||
|
|
ddl.Items[i].Selected = true;
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
for (int i = 0; i < ddl.Items.Count; i++)
|
|||
|
|
{
|
|||
|
|
if (isExts(label, ddl.Items[i].Text))
|
|||
|
|
{
|
|||
|
|
ddl.Items[i].Selected = true;
|
|||
|
|
break;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20>ж<EFBFBD>ǰ<EFBFBD><C7B0><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ں<EFBFBD><DABA><EFBFBD>
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="ea"></param>
|
|||
|
|
/// <param name="str"></param>
|
|||
|
|
/// <returns></returns>
|
|||
|
|
private bool isExts(string ea, string str)
|
|||
|
|
{
|
|||
|
|
bool isExt = false;
|
|||
|
|
if (ea.Trim() == str.Trim()) return true;
|
|||
|
|
if (str.IndexOf(ea) > -1) isExt = true;
|
|||
|
|
if (ea.Length > 2)
|
|||
|
|
{
|
|||
|
|
for (int i = 0; i <= (ea.Length - 2); i++)
|
|||
|
|
{
|
|||
|
|
string t = ea.Substring(i, 2);
|
|||
|
|
if (str.IndexOf(t) > -1)
|
|||
|
|
{
|
|||
|
|
isExt = true;
|
|||
|
|
break;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
return isExt;
|
|||
|
|
}
|
|||
|
|
#endregion
|
|||
|
|
|
|||
|
|
#region <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ť
|
|||
|
|
protected void btnBack2_Click(object sender, EventArgs e)
|
|||
|
|
{
|
|||
|
|
fdPanel1.Visible = true;
|
|||
|
|
fdPanel2.Visible = false;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
protected void btnBack_Click(object sender, EventArgs e)
|
|||
|
|
{
|
|||
|
|
fdPanel2.Visible = true;
|
|||
|
|
fdPanel3.Visible = false;
|
|||
|
|
}
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ĺ<EFBFBD><C4B9><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="sender"></param>
|
|||
|
|
/// <param name="e"></param>
|
|||
|
|
protected void btnBack4_Click(object sender, EventArgs e)
|
|||
|
|
{
|
|||
|
|
fdPanel2.Visible = true;
|
|||
|
|
fdPanel4.Visible = false;
|
|||
|
|
lbError2.Text = "";
|
|||
|
|
fdPanel5.Visible = false;
|
|||
|
|
}
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Excel<65>ĵ<EFBFBD>
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="sender"></param>
|
|||
|
|
/// <param name="e"></param>
|
|||
|
|
protected void btnBack5_Click(object sender, EventArgs e)
|
|||
|
|
{
|
|||
|
|
fdPanel1.Visible = true;
|
|||
|
|
fdPanel4.Visible = false;
|
|||
|
|
lbState.Text = "<22>ȴ<EFBFBD><C8B4>ϴ<EFBFBD><CFB4><EFBFBD><EFBFBD><EFBFBD>";
|
|||
|
|
btnNext1.Visible = false;
|
|||
|
|
lbError1.Text = "";
|
|||
|
|
fdPanel5.Visible = false;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
protected void btnNext1_Click(object sender, EventArgs e)
|
|||
|
|
{
|
|||
|
|
fdPanel1.Visible = false;
|
|||
|
|
fdPanel2.Visible = true;
|
|||
|
|
}
|
|||
|
|
#endregion
|
|||
|
|
|
|||
|
|
#region <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="sender"></param>
|
|||
|
|
/// <param name="e"></param>
|
|||
|
|
protected void btnOutpt_Click(object sender, EventArgs e)
|
|||
|
|
{
|
|||
|
|
//<2F><><EFBFBD><EFBFBD>Excel<65><6C><EFBFBD><EFBFBD>
|
|||
|
|
HSSFWorkbook hssfworkbook = new HSSFWorkbook();
|
|||
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
ISheet sheet = hssfworkbook.CreateSheet(this.TemplateName);
|
|||
|
|
//sheet.DefaultColumnWidth = 30;
|
|||
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD><D0B6><EFBFBD>
|
|||
|
|
IRow rowHead = sheet.CreateRow(0);
|
|||
|
|
//<2F><><EFBFBD>ɱ<EFBFBD>ͷ
|
|||
|
|
for (int i = 0; i < gvError.HeaderRow.Cells.Count; i++)
|
|||
|
|
{
|
|||
|
|
string txt = gvError.HeaderRow.Cells[i].Text;
|
|||
|
|
txt = txt.Replace(" ", "");
|
|||
|
|
rowHead.CreateCell(i).SetCellValue(txt);
|
|||
|
|
}
|
|||
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
ICellStyle style_size = hssfworkbook.CreateCellStyle();
|
|||
|
|
style_size.WrapText = true;
|
|||
|
|
for (int i = 0; i < gvError.Rows.Count; i++)
|
|||
|
|
{
|
|||
|
|
IRow row = sheet.CreateRow(i + 1);
|
|||
|
|
GridViewRow gvr = gvError.Rows[i];
|
|||
|
|
for (int j = 0; j < gvr.Cells.Count; j++)
|
|||
|
|
{
|
|||
|
|
string txt = gvr.Cells[j].Text;
|
|||
|
|
if (string.IsNullOrEmpty(txt)) continue;
|
|||
|
|
txt = txt.Replace(" ", "");
|
|||
|
|
txt = txt.Replace("\n", "");
|
|||
|
|
txt = txt.Replace("\r", "");
|
|||
|
|
ICell cell = row.CreateCell(j);
|
|||
|
|
cell.SetCellValue(txt.Trim());
|
|||
|
|
cell.CellStyle = style_size;
|
|||
|
|
if (txt.Length > 20)
|
|||
|
|
{
|
|||
|
|
cell.Sheet.SetColumnWidth(j, 100 * 256);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>
|
|||
|
|
string filePath = Upload.Get["Temp"].Physics + WeiSha.Common.Server.LegalName(this.TemplateName + "-<2D><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>-" + DateTime.Now.ToLongDateString()) + ".xls";
|
|||
|
|
FileStream file = new FileStream(filePath, FileMode.Create);
|
|||
|
|
hssfworkbook.Write(file);
|
|||
|
|
file.Close();
|
|||
|
|
if (System.IO.File.Exists(filePath))
|
|||
|
|
{
|
|||
|
|
FileInfo fileInfo = new FileInfo(filePath);
|
|||
|
|
Response.Clear();
|
|||
|
|
Response.ClearContent();
|
|||
|
|
Response.ClearHeaders();
|
|||
|
|
Response.AddHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(fileInfo.Name));
|
|||
|
|
Response.AddHeader("Content-Length", fileInfo.Length.ToString());
|
|||
|
|
Response.AddHeader("Content-Transfer-Encoding", "binary");
|
|||
|
|
Response.ContentType = "application/-excel";
|
|||
|
|
Response.ContentEncoding = System.Text.Encoding.Default;
|
|||
|
|
Response.WriteFile(fileInfo.FullName);
|
|||
|
|
Response.Flush();
|
|||
|
|
Response.End();
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
#endregion
|
|||
|
|
}
|
|||
|
|
}
|