两个常用的功能,将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 ...
随机推荐
- 九九乘法口诀引申出NN乘法口诀
package com.tfj.function; import java.util.Scanner; public class NNTable { public void method1(int n ...
- bzoj1084
乍一看这题好难,根本不会: 直到看到1<=m<=2…… 显然分类讨论dp, 很快想到这题的dp和poj2430相类似 m=2的时候f[i,j,k]表示到第i行用了j个矩阵结尾状态为k时最大 ...
- Reflector+Reflexil 相结合实现对DLL文件修改
在工作过程中,我们有可能遇到这样的问题:公司发给客户的软件包突然报错了,但是你知道哪里报错了,而这个代码已经编译成DLL文件了,源代码不在自己这里.怎么办呢?还好现在有Reflexil插件,这个插件只 ...
- Apache搭建多个站点
如何用Apache搭建的网站系统上运行多个站点呢?最平常的大概有3种方法. 第一种:单IP不同端口 第二种:多IP同端口(独立IP的虚拟空间) 第三种:域名绑定根目录的方式(共享IP的虚拟空间) 下面 ...
- ruby编程语言-学习笔记1
安装完 ruby ri irb ruby-devel 1. 先来个简单的,写个helloworld 给新手们 (terminal中,# 代表root权限,$ 代表用户权限, 前面的就不写了.) # ...
- UVA 11916 Emoogle Grid 离散对数 大步小步算法
LRJ白书上的题 #include <stdio.h> #include <iostream> #include <vector> #include <mat ...
- lightoj 1013
思路:动态规划.设dp[i][j][k]表示用第一个串的前i隔字符和第二个串的前k隔字符组成长度为i的串的个数,那么:若s1[j+1] == s2[k+1] dp[i+1][j+1][k+1] += ...
- c++11 lambda递归调用写法
偶然想到要在函数内部使用lambda递归调用,以下是可行的写法,可参考 std::function<void(Node * container,const BlendFunc &blen ...
- 【CSS】Intermediate2:Grouping and Nesting
1.Grouping 2.Nesting If the CSS is structured well, there shouldn’t be a need to use many class or I ...
- bzoj2946 [Poi2000]公共串(SA,SAM)
[题意] 多串求LCS. [思路] 主要是想找一下SAM的优越感 :) velui good 后缀数组划分height需要注意不少细节 <_<,然后不停debug [代码] ...