//转成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. tlplayer for wince 版本正式商用

    开始的时候tlplayer遇到一些问题,后来经过一些简单优化后,可以满足商用条件. 支持http,mms,rtsp等网络协议,支持内存流播放.需要定制或者需要支持hls,rtmp,m3u8等协议的,请 ...

  2. 先贴出代码C++ 中的单例模式

    先贴出代码,代码后面是讲解 自己编写的单例模式: #include <iostream> #include <stdio.h> #include <string> ...

  3. jquery封装的选项卡

    ul,li,div{ margin:; padding:;} ul,li{ list-style:none;} .tab_wrap{ width:450px; margin: auto 50px; o ...

  4. OpenGL绘制自由落体小球

    OpenGL绘制自由落体小球 一.    程序运行的软硬件环境 本次设计在window10系统下进行,运用C++进行编写,在CodeBlocks环境下使用OpenGL进行设计. 所需环境配置分为2部分 ...

  5. 使用curl下载文件

    curl是一个非常好的网络传输库,使用也很简单.常用的使用方式是用它来下载资源文件,以下提供一个下载方法 #include <stdio.h> #include <iostream. ...

  6. 浏览器兼容性的css hack 写法

    IE各版本浏览器之间的识别概括如下: IE6:能识别 * .\9 和 _ ,不能识别 !important IE7:能识别 * .\9 和 !important,不能识别 _ IE8:能识别 \9 和 ...

  7. keystone 手动建立租户,用户,角色,服务,端口

    建立租户: root@cloud:~# keystone tenant-create --name=admin WARNING: Bypassing authentication using a to ...

  8. 组合数学及其应用——格路径与Schroder数

    格路径问题是探讨在如下所示中的一个格点图上,从(0,0)位置到达(p,q)所有可能的情况数.我们称这样的通路为一条格路径. 格点图: · · · · · · · · · · · · · · · · · ...

  9. php5.5 yum源

    PHP官网在下载页面中只有源代码下载,当然使用编译安装也是可以的,但是使用二进制包安装会非常快速.虽然PHP官网没有提供二进制安装包,但是它推荐了两个第三方的YUM源(CentOS中默认的YUM安装的 ...

  10. JS好的学习网站

    1.JavaScript 秘密花园 2.W3CSchool 3.js严格模式 4.js核心之原型 5.尼古拉斯怎么面试前端工程师 6.zepto中文版api 7.jquery API