/// <summary> /// 获取导入数据的模板(支持2007以上) /// </summary> public void ExcelTemplate() { string path = HttpContext.Current.Server.MapPath("~/Resource/Excel/" + ObjName + ".xls"); if (!File.Exists(path)) { path = path + "x"; if (!File.Exists(path)) { path = HttpContext.Current.Server.MapPath("~/Resource/Excel/" + TableName + ".xls"); if (!File.Exists(path)) { path = path + "x"; } } } MemoryStream ms = null; if (File.Exists(path)) { byte[] data = File.ReadAllBytes(path); ms = new MemoryStream(data, 0, data.Length, false, true); } string fix = "_模板"; if (ms == null) { fix = "-模板"; string objName = ObjName; MDataTable dt = GridConfig.GetList(objName, GridConfig.SelectType.All);//获取所有列的字段名。 if (dt.Rows.Count > 0) { ms = ExcelHelper.CreateExcelHeader(dt, KeyValueConfig.GetValidationData(dt)); } } WebHelper.SendFile(KeyValueConfig.GetTableDescription(ObjName, TableName) + fix + Path.GetExtension(path), ms); }
/// <summary> /// 获取导入数据的模板(支持2007以上) /// </summary> public void ExcelTemplate() { string path = HttpContext.Current.Server.MapPath("~/Resource/Excel/" + ObjName + ".xls"); if (!File.Exists(path)) { path = path + "x"; if (!File.Exists(path) && ObjName != TableName) { path = HttpContext.Current.Server.MapPath("~/Resource/Excel/" + TableName + ".xls"); if (!File.Exists(path)) { path = path + "x"; } } } MemoryStream ms = null; string fix = ExcelHelper.BookType == ExcelHelper.WorkBookType.High ? ".xlsx" : ".xls"; if (File.Exists(path)) { byte[] data = File.ReadAllBytes(path); ms = new MemoryStream(data, 0, data.Length, false, true); fix = Path.GetExtension(path); } if (ms == null) { string objName = ObjName; MDataTable header = GridConfig.GetList(objName, GridConfig.SelectType.Import);//获取所有列的字段名。 if (header.Rows.Count > 0) { ms = ExcelHelper.CreateExcelHeader(header, KeyValueConfig.GetValidationData(header)); } } WebHelper.SendFile(KeyValueConfig.GetTableDescription(ObjName, TableName) + fix, ms); }