前提:保证自己已经加载了数据,通过GetAttribute获取Layer的属性表DataTable,Excel分类专栏中有如何将DataTable导出为Excel
//获取Layer的属性表public DataTable GetAttribute(Layer oLayer){FeatureDefn oDefn = oLayer.GetLayerDefn();//获取字段个数int iFieldCount = oDefn.GetFieldCount();DataTable att = new DataTable();//遍历所有的字段for (int iAttr = 0; iAttr < iFieldCount; iAttr++){FieldDefn oField = oDefn.GetFieldDefn(iAttr);att.Columns.Add(oField.GetName());}Feature oFeature = null;// 下面开始遍历图层中的要素while ((oFeature = oLayer.GetNextFeature()) != null){DataRow dr=att.NewRow();// 获取要素中的属性表内容for (int iField = 0; iField < iFieldCount; iField++){FieldDefn oFieldDefn = oDefn.GetFieldDefn(iField);FieldType type = oFieldDefn.GetFieldType();dr[oFieldDefn.GetName()] = oFeature.GetFieldAsString(iField);}//添加属性行att.Rows.Add(dr);}return att;}