//转成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. ActionBar官方教程(1)简介及各区域介绍

    Action Bar The action bar is a window feature that identifies the user location, and provides user a ...

  2. C#中的泛型详解

    泛型(generic)是C#语言2.0和通用语言运行时(CLR)的一个新特性.泛型为.NET框架引入了类型参数(type parameters)的概念.类型参数使得设计类和方法时,不必确定一个或多个具 ...

  3. INCOIN Importing Multilingual Items (Doc ID 278126.1)

    APPLIES TO: Oracle Inventory Management - Version: 11.5.9 to 11.5.10.CU2 - Release: 11.5 to 11.5 GOA ...

  4. poj3411Paid Roads(dfs)

    链接 想偷点懒用矩阵存 一直WA 后来看讨论说有重边改为邻接表 这题边可能走了不止一次 我设的最多两次可过 #include <iostream> #include<cstdio&g ...

  5. SharePoint 2010 master page 控件介绍(2):ribbon (一同事读听着像泪奔)

    转:http://blog.csdn.net/lgm97/article/details/6409208 <!-- =====  开始Ribbon ======================= ...

  6. 如何破解Adobe Acrobat9 pro?(转)

    解决办法: 1.到 C:\Program Files\Common Files\Adobe\Adobe PCD\cache 文件夹下找到 Cache.db,并删除此文件 . 2.打开Adobe Acr ...

  7. 三种情形容易引起Azure虚拟机重新启动

      与虚拟机或云服务角色中运行的代码有关的问题可能会导致重新启动.但是,Microsoft 在以下情况下也会重新启动您的角色: 来宾操作系统更新 – 仅影响云服务 Web 和辅助角色.有关如何限制这些 ...

  8. shell常用命令总结

    统计文件行数 wc -l filename grep -c "" filename sed -n '$=' filename awk 'END{print NR}' filenam ...

  9. 【Java基础】Java类及成员和修饰符的关系

    修饰符的分类 权限修饰符:private,默认的,protected,public 状态修饰符:static,final 抽象修饰符:abstract 类的修饰符 权限修饰符:默认修饰符,public ...

  10. HW3.11

    import java.util.Scanner; public class Solution { public static void main(String[] args) { Scanner i ...