【页面效果图】
----------------------------------------------------------------后台代码-----------------------------------------------------------------------------
/// <summary>
/// 导入Execl
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnUpload_Click(object sender, EventArgs e)
{
string returnMsg = string.Empty;
string savePath = Server.MapPath("~/UploadFiles");
if (!System.IO.Directory.Exists(savePath))
{
System.IO.Directory.CreateDirectory(savePath);
}
if (this.FileUpload1.HasFile)
{
string TimeName = DateTime.Now.ToString("yyyyMMddhhmmssff");
string filename = this.FileUpload1.FileName;
string filetype = filename.Substring(filename.LastIndexOf("."));
string ServerFilePath = savePath + "\\" + filetype.Replace(filetype, "") + TimeName + filetype;
FileUpload1.SaveAs(ServerFilePath);
this.FpSpread1.OpenExcel(ServerFilePath, FarPoint.Excel.ExcelOpenFlags.TruncateEmptyRowsAndColumns);
//Response.Redirect("TwoSpread.aspx?ServerFilePath=" + ServerFilePath);
this.FpSpread1.OpenExcel(ServerFilePath, FarPoint.Excel.ExcelOpenFlags.TruncateEmptyRowsAndColumns);
// 取消分页
foreach (SheetView sheet in this.FpSpread1.Sheets)
{
sheet.AllowPage = false;
}
int count = this.FpSpread1.Sheets[0].RowCount;
//// 设置复选框主
this.FpSpread1.Sheets[0].Columns[0].CellType = new FarPoint.Web.Spread.CheckBoxCellType();
//// 设置Spread表格的行数和例数
this.FpSpread1.Sheets[0].ColumnCount = 100;
this.FpSpread1.Sheets[0].RowCount = 100;
this.FpSpread1.Sheets[0].Columns[0].Width = 50;
this.FpSpread1.Sheets[0].Columns[1].Width = 120; //设置项目例的宽度
this.FpSpread1.Sheets[0].Columns[2].Width = 120; //所属部门
this.FpSpread1.Sheets[0].Columns[3].Width = 120; //预算事项编码
this.FpSpread1.Sheets[0].Columns[4].Width = 120; //预算事项名称
this.FpSpread1.Sheets[0].Columns[5].Width = 120; //预算科目代码
this.FpSpread1.Sheets[0].Columns[6].Width = 120; //预算科目名称
this.FpSpread1.Sheets[0].Columns[7].Width = 50; //年度
}
}
--------------------------------------------------------------------------------------------------------------------------------------------- |
|