两个常用的功能,将shp数据属性转成TXT和Excel(转)
//转成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(转)的更多相关文章
- Windows校验文件哈希hash的两种常用方式
大家经常都到哪儿去下载软件和应用程序呢?有没想过下载回来的软件.应用程序或资源是否安全呢?在 Windows 10 和 Office 2016 发布当初,很多没权限的朋友都使用第三方网站去下载安装映像 ...
- RealView编译器常用特有功能(转)
源:RealView编译器常用特有功能 一. 关键字和运算符 1. __align(n):指示编译器在n 字节边界上对齐变量. 对于局部变量,n 值可为 1.2.4 或 8. 对于全局变量,n 可以具 ...
- Impala系列: Impala常用的功能函数
--=======================查看内置的函数--=======================hive 不需要进入什么内置数据库, 即可使用 show functions 命令列出 ...
- Pandas常用基本功能
Series 和 DataFrame还未构建完成的朋友可以参考我的上一篇博文:https://www.cnblogs.com/zry-yt/p/11794941.html 当我们构建好了 Series ...
- 常用js功能函数汇总(持续更新ing)
////////////////////获取元素属性/////////////////// function getStyle(obj,name) { if(obj.currentStyle) { r ...
- Spring Cloud Config采用Git存储时两种常用的配置策略
由于Spring Cloud Config默认采用了Git存储,相信很多团队在使用Spring Cloud的配置中心时也会采用这样的策略.即便大家都使用了Git存储,可能还有各种不同的配置方式,本文就 ...
- 【比赛打分展示双屏管理系统-加强版】的两个ini配置文件功能解释及排行榜滚动界面的简答配置等
加强版目录下有两个ini文件,功能解释如下: 1. ScoreTip.ini: bScoreTip:如果为1,可以启用 回避 功能 或 高低分差值超出 iScoreRange 的 提示功能. iSco ...
- iOS常用小功能
CHENYILONG Blog 常用小功能 技术博客http://www.cnblogs.com/ChenYilong/ 新浪微博http://weibo.com/luohanchenyilong ...
- Gson Json 序列号 最常用的功能 MD
Markdown版本笔记 我的GitHub首页 我的博客 我的微信 我的邮箱 MyAndroidBlogs baiqiantao baiqiantao bqt20094 baiqiantao@sina ...
随机推荐
- Drawable(1)各种Drawable Resource介绍
简介 Drawable Resources(可绘资源) 是一系列可以在屏幕上被绘制的资源文件,它不只是图片,可以是 xml文件,在xml文件中配置各种绘制参数. 常见Drawable Resource ...
- 【HDOJ】1241 Oil Deposits
经典的BFS. #include <stdio.h> #include <string.h> #define MAXNUM 105 #define MAXROW 105 #de ...
- spring log4j.properties
log4j.properties log4j.rootLogger=info,appender2,appender3 #appender2\u914D\u7F6E FileAppender log4j ...
- 嵌入式开发软件环境:uboot、kernel、rootfs、data布局分析
uboot+linux的整体方案 开发板的datasheet中都有详细的地址空间的划分,其中比较重要的两块是:DDR地址空间和Flash地址空间.DDR空间是系统和应用的运行空间,一般由linux系统 ...
- [Bhatia.Matrix Analysis.Solutions to Exercises and Problems]ExI.2.2
Show that the following statements are equivalent: (1). $A$ is positive. (2). $A=B^*B$ for some $B$. ...
- vxworks一个超级奇怪的错误(parse error before `char')
void tserver(int id) { if(debug){ useResource(,id);} char msgBuf[MAX_MSG_LEN]; if (msgQReceive(myMsg ...
- Asp.Net MVC4新特性指南(2):新特性介绍
上一章讲解了最基本的MVC4说明.今天就介绍下几种新特性的使用例子: 就当大家有MVC3的基础了.在这个基础上在看下面的介绍就容易多了.1.Web API MVC4包括一个更好的解决方案:A ...
- 如何使用Visual Studio 2013 创建Azure云应用
创建 Azure 云服务 Azure 云服务包括执行应用程序所需操作的角色.当你将云服务发布到 Azure 时,每个角色将在云中的虚拟机上运行.有关如何开发 Azure 云服务的详细信息. 创建 Az ...
- Linux的read命令
对于写bash脚本的朋友,read命令是不可或缺的,需要实践一下就可以了解read命令的大致用途: 编写一个脚本: #!/bin/bash # hao32 test read echo -e &quo ...
- Codeforces Round #226 (Div. 2)C. Bear and Prime Numbers
/* 可以在筛选质数的同时,算出每组数据中能被各个质数整除的个数, 然后算出[0,s]的个数 [l,r] 的个数即为[0,r]的个数减去[0,l]个数. */ #include <stdio.h ...