62,268
社区成员
发帖
与我相关
我的任务
分享
public string MenberExcelCreate(ClassInfo classInfo, SchoolInfo schoolInfo, HttpContext context)
{
string export_data_file_path = "";
XlsDocument xls = new XlsDocument();
string dir_path = "/Analyse/ExcelDoc/MemberExcel/" + schoolInfo.SchoolName + "/";
if (!Directory.Exists(HttpContext.Current.Server.MapPath(dir_path)))
{
Directory.CreateDirectory(HttpContext.Current.Server.MapPath(dir_path));
}
xls.FileName = HttpContext.Current.Server.MapPath(dir_path) + schoolInfo.SchoolName + classInfo.ClassName + ".xls";
if (File.Exists(xls.FileName))
{
File.Delete(xls.FileName);
}
export_data_file_path = dir_path + schoolInfo.SchoolName + classInfo.ClassName + ".xls";
Worksheet sheet = xls.Workbook.Worksheets.Add("基础属性");
ColumnInfo col0 = new ColumnInfo(xls, sheet);
col0.ColumnIndexStart = 0;
col0.ColumnIndexEnd = 0;
col0.Width = 20 * 256;
sheet.AddColumnInfo(col0);
Cells cells = sheet.Cells;
Cell cell = cells.Add(1, 1, "学校ID");
cell.Font.Bold = true;
cell = cells.Add(2, 1, schoolInfo.SchoolID);
cell.Font.Bold = true;
ColumnInfo col1 = new ColumnInfo(xls, sheet);
col1.ColumnIndexStart = 1;
col1.ColumnIndexEnd = 1;
col1.Width = 20 * 256;
sheet.AddColumnInfo(col1);
cells = sheet.Cells;
cell = cells.Add(1, 2, "班级ID");
cell.Font.Bold = true;
cell = cells.Add(2, 2, classInfo.ClassID);
cell.Font.Bold = true;
xls.Save();
return export_data_file_path;
}
protected void LinkButton_MenberExcelCreate_Click(object sender, EventArgs e)
{
//classInfo,schoolInfo,this.Context 都是有值的,这里省略
string url=MenberExcelCreate(classInfo, schoolInfo,this.Context);
Response.Redirect(url);
}