//转成txt

public static void ConvertTable2Txt(ITable pTable, string pFilePath)
        {

int pIndex = 0;

string pStrLast = "";

string pTxtFile = System.IO.Path.Combine(pFilePath, (pTable as IDataset).Name + ".txt");

System.IO.FileStream pTxt1 = new System.IO.FileStream(pTxtFile, FileMode.Create);

StreamWriter pStrW = new StreamWriter(pTxt1);

int pFieldCount = pTable.Fields.FieldCount;

ICursor pCursor = pTable.Search(null, false);

IRow pRow = pCursor.NextRow();

//写入字段

for (int i = 0; i < pFieldCount; i++)
            {
                if (pTable.Fields.get_Field(i).Type != esriFieldType.esriFieldTypeGeometry)
                {
                    pStrLast = pStrLast + "," + pTable.Fields.get_Field(i).Name;
                }

}

pStrLast = pStrLast.Substring(1, pStrLast.Length - 1);

pStrW.WriteLine(pStrLast);

//写入值

while (pRow != null)
            {
                pStrLast = "";
                pIndex++;
                for (int i = 0; i < pFieldCount; i++)
                {
                    if (pTable.Fields.get_Field(i).Type != esriFieldType.esriFieldTypeGeometry)
                    {
                        pStrLast = pStrLast+ "," + pRow.get_Value(i).ToString();
                    }

}
                pStrLast =pStrLast.Substring(1, pStrLast.Length - 1);

pStrW.WriteLine(pStrLast);

if(pIndex==50)
                {
                
                    pStrW.Flush();
                    pIndex=0;
                }
               
                pRow = pCursor.NextRow();

}
         
            pStrW.Close();

}

//转成Excel
        public static void ConvertTable2Excel(ITable pTable, string pFilePath)
        {

int pIndex = 1;

string pTxtFile = System.IO.Path.Combine(pFilePath, (pTable as IDataset).Name + ".xlsx");

int pFieldCount = pTable.Fields.FieldCount;

ICursor pCursor = pTable.Search(null, false);

IRow pRow = pCursor.NextRow();

//写入字段

Microsoft.Office.Interop.Excel.Application  pExcel = new Microsoft.Office.Interop.Excel.Application();

pExcel.Workbooks.Add(true);

pExcel.Visible = false;

Workbook pWorKbook = pExcel.Workbooks[1];

Worksheet xSheet = (Microsoft.Office.Interop.Excel.Worksheet)pWorKbook.Worksheets[1];

xSheet.Name = (pTable as IDataset).Name;

xSheet.SaveAs(pTxtFile, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);

//字段
            for (int i = 0; i < pFieldCount; i++)
            {

xSheet.Cells[1, i + 1] = pTable.Fields.get_Field(i).Name;
                   
            }

//写入值

while (pRow != null)
            {
               
                pIndex++;
                for (int i = 0; i < pFieldCount; i++)
                {

xSheet.Cells[pIndex, i + 1] = pRow.get_Value(i).ToString();

}

pRow = pCursor.NextRow();

}

pWorKbook.Save();
            pExcel.Quit();

}

来自:http://www.gisall.com/html/63/151663-6857.html

两个常用的功能,将shp数据属性转成TXT和Excel(转)的更多相关文章

  1. Windows校验文件哈希hash的两种常用方式

    大家经常都到哪儿去下载软件和应用程序呢?有没想过下载回来的软件.应用程序或资源是否安全呢?在 Windows 10 和 Office 2016 发布当初,很多没权限的朋友都使用第三方网站去下载安装映像 ...

  2. RealView编译器常用特有功能(转)

    源:RealView编译器常用特有功能 一. 关键字和运算符 1. __align(n):指示编译器在n 字节边界上对齐变量. 对于局部变量,n 值可为 1.2.4 或 8. 对于全局变量,n 可以具 ...

  3. Impala系列: Impala常用的功能函数

    --=======================查看内置的函数--=======================hive 不需要进入什么内置数据库, 即可使用 show functions 命令列出 ...

  4. Pandas常用基本功能

    Series 和 DataFrame还未构建完成的朋友可以参考我的上一篇博文:https://www.cnblogs.com/zry-yt/p/11794941.html 当我们构建好了 Series ...

  5. 常用js功能函数汇总(持续更新ing)

    ////////////////////获取元素属性/////////////////// function getStyle(obj,name) { if(obj.currentStyle) { r ...

  6. Spring Cloud Config采用Git存储时两种常用的配置策略

    由于Spring Cloud Config默认采用了Git存储,相信很多团队在使用Spring Cloud的配置中心时也会采用这样的策略.即便大家都使用了Git存储,可能还有各种不同的配置方式,本文就 ...

  7. 【比赛打分展示双屏管理系统-加强版】的两个ini配置文件功能解释及排行榜滚动界面的简答配置等

    加强版目录下有两个ini文件,功能解释如下: 1. ScoreTip.ini: bScoreTip:如果为1,可以启用 回避 功能 或 高低分差值超出 iScoreRange 的 提示功能. iSco ...

  8. iOS常用小功能

    CHENYILONG Blog 常用小功能 技术博客http://www.cnblogs.com/ChenYilong/ 新浪微博http://weibo.com/luohanchenyilong  ...

  9. Gson Json 序列号 最常用的功能 MD

    Markdown版本笔记 我的GitHub首页 我的博客 我的微信 我的邮箱 MyAndroidBlogs baiqiantao baiqiantao bqt20094 baiqiantao@sina ...

随机推荐

  1. Moduli number system

    A number system with moduli is defined by a vector of k moduli, [m1,m2, ···,mk]. The moduli must be p ...

  2. Android开发UI之动画侦听

    动画侦听使用了AnimationListener接口,需要实现三个方法onAnimationStart().onAnimationRepeat().onAnimationEnd() 代码: 实现But ...

  3. 转自 z55250825 的几篇关于FFT的博文(三)

    题目大意:给出n个数qi,定义 Fj为        令 Ei=Fi/qi,求Ei.      其实这道题就是看到有FFT模板才觉得有必要学一下的...    所以实际上就是已经知道题解了... = ...

  4. .NET平台上的Memcached客户端介绍(Memcached Providers)

    早上接到一个任务,需要对Linux服务器的Memcached的update操作进行性能测试,我发现我是一个典型的“手里拿着锤子,就把所有问题都当成钉子”的人.我第一个念头就是,上Memcached的官 ...

  5. [备忘]WCF中使用MessageContract的一些注意点

    准备使用WCF完成上传文件,以取代之前HTTP POST的方式. 但是调试了很久一直报错,后来经过一些修改终于通过,以下是一些可能需要注意的地方: 1.在WCF服务的OperatorContract ...

  6. 【原】Scala学习资料

    Scala是基于JVM的一种通用函数式也是面向对象编程语言,能和Java.C#等主流的编程语言无缝融合. 下面给大家推荐一些Scala的学习资料,序号靠前的重要性比较高. 1.Scala初学指南 (1 ...

  7. Struts2使用拦截器完成权限控制示例

    http://aumy2008.iteye.com/blog/146952 Struts2使用拦截器完成权限控制示例 示例需求:    要求用户登录,且必须为指定用户名才可以查看系统中某个视图资源:否 ...

  8. Linux经久不衰的应用程序

    Linux里面的应用程序一贯以高安全性,高性价比(功能/所占空间),此次记录一下Linux里面比较常用的而且经久不衰的应用程序. Shell:               bash(它结合了 csh ...

  9. 高密度Java应用部署的一些实践

    传统的Java应用部署模式,一般遵循“硬件->操作系统->JVM->Java应用”这种自底向上的部署结构,其中JEE应用可以细化为“硬件->操作系统->JVM->J ...

  10. storm核心组件

    Storm核心组件 了解 Storm 的核心组件对于理解 Storm 原理非常重要,下面介绍 Storm 的整体,然后介绍 Storm 的核心. Storm 集群由一个主节点和多个工作节点组成.主节点 ...