【求助】关于导入,导出Excel问题

Ganker 2012-05-15 11:10:01
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);




...全文
108 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复

62,268

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧