//转成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. Android list刷新后仍然定位到原来的位置,解决。

    问题: 有一个list,点击item时会做一些事情,然后重新加载数据,此时希望点击重新刷新后item还在原来的位置,而不是跳转到开头. 实现如下: 1.listview添加监听setOnScrollL ...

  2. Mapreduce-Partition分析

    Partition所处的位置 Partition位置 Partition主要作用就是将map的结果发送到相应的reduce.这就对partition有两个要求: 1)均衡负载,尽量的将工作均匀的分配给 ...

  3. BZOJ3166: [Heoi2013]Alo

    3166: [Heoi2013]Alo Time Limit: 20 Sec  Memory Limit: 256 MBSubmit: 394  Solved: 204[Submit][Status] ...

  4. iOS频繁打开相册崩溃: ALAssetsLibrary error - “Too many contexts. No space in contextList.”

    iOS频繁打开相册崩溃: ALAssetsLibrary error - “Too many contexts. No space in contextList.” http://stackoverf ...

  5. c#调用带有安全认证的java webservice

    最近使用c#调用另外一个同事写的java webservice耽误了很多时间,网上资料不太完整,走了很多弯路,希望对大家有帮助. 基本思路是1.拼装soap使用http post ,主要将验证身份信息 ...

  6. HDU5653 Bomber Man wants to bomb an Array 简单DP

    题意:bc 77 div1 1003(中文题面) 分析:先不考虑将结果乘以 1e6. 设 dp[i] 为从前 i 个格子的状态可以获得的最大破坏指数. 那么我们可以枚举每个炸弹,该炸弹向左延伸的距离和 ...

  7. HDU 1953

    #include<stdio.h> #include<math.h> long long int euler(long long int n) { long long int ...

  8. Java笔记(十九)……多线程

    概述 进程: 是一个正在执行中的程序 每一个进程执行都有一个执行顺序,该执行顺序是一个执行路径,或者叫一个控制单元 线程: 就是进程中的一个独立的控制单元,线程在控制着进程的执行 一个进程中至少有一个 ...

  9. 洛谷P1220 关路灯

    洛谷1220 关路灯 题目描述 某一村庄在一条路线上安装了n盏路灯,每盏灯的功率有大有小(即同一段时间内消耗的电量有多有少).老张就住在这条路中间某一路灯旁,他有一项工作就是每天早上天亮时一盏一盏地关 ...

  10. 《Data-Intensive Text Processing with mapReduce》读书笔记之二:mapreduce编程、框架及运行

    搜狐视频的屌丝男士第二季大结局了,惊现波多野老师,怀揣着无比鸡冻的心情啊,可惜随着剧情的推进发展,并没有出现期待中的屌丝奇遇,大鹏还是没敢冲破尺度的界线.想百度些种子吧,又不想让电脑留下污点证据,要知 ...