1、我先用程序导出了一个excel模版。导出正常。2、然后对这个模版不做任何操作,再把这个生成的模版导入程序中,只能导入第一列数据(共有2列)3、然后我打开excel模版,让第一列变成编辑状态,再点保存。再次导入,导入成功!初步断定是导出模版时数据格式出错,但不知道怎么解决?求帮助
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);
}
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);
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货