//转成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. MySQL主从复制中断处理一例

    收到mysql主从中断报警邮件,马上登上服务器查看,发现是中继日志损坏. Show slave status\G,提示中继日志损坏,按以往的做法,根据提示重新指定合适的日志文件以及pos点.  Rel ...

  2. codeigniter实现ajax分页

    <?php /** *417 add 主要是实现ajax分页 **/ class MY_Pagination extends CI_Pagination{ public function __c ...

  3. addChildViewController 与 addSubview

    在viewcontrollerA中, 如果想把controllerB.view添加进来, 可以用 addSubview, 但如果controllerB中有个事件, 使用到 self.navigatio ...

  4. epub格式电子书剖析之三:NCX文件构成

    ncx文件是epub电子书的又一个核心文件,用于制作电子书的目录,其文件的命名通常为toc.ncx. ncx文件是一个XML文件,该标准由DAISY Consortium发布(参见http://www ...

  5. lihgtoj 1006

    记忆化搜索下即可. #include<cstdio> #include<string> #include<cstring> #include<iostream ...

  6. HDU-1240 Asteroids! (BFS)这里是一个三维空间,用一个6*3二维数组储存6个不同方向

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission ...

  7. 【原】1.1RDD源码解读(一)

    1.RDD(Resilient Distributed DataSet)是Spark生态系统中最基本的抽象,代表不可变的.可并行操作的分区元素集合.RDD这个类有RDD系列所有基本的操作,比如map. ...

  8. leecode single numer

    http://www.acmerblog.com/leetcode-single-number-ii-5394.html acm之家的讲解总是那么到位 public class Solution { ...

  9. 初探WebService

    写博客也是一件非常费时的事儿啊,之前配置服务器和客户端的Oracle数据库搞了很久,搞定之后懒的记录,现在想想如果让我再配一次,估计又要花很长时间了. 所以把做过的东西整理整理记录下来还是很有必要的, ...

  10. Yii防注入攻击笔记

    网站表单有注入漏洞须对所有用户输入的内容进行个过滤和检查,可以使用正则表达式或者直接输入字符判断,大部分是只允许输入字母和数字的,其它字符度不允许:对于内容复杂表单的内容,应该对html和script ...