//DataGirdview手动添加数据

private void btnDataGirdView_Click(object sender,EventArgs e)

{

      dataGridView1.Columns.Add("a","标题1");

      dataGridView1.Columns.Add("b","标题2");

      dataGridView1.Columns.Add("c","标题3");

      string[] dr1= { "1","22","3333" };

      string[] dr2= { "4444","55","6" };

      DataGridViewRow Row=new DataGridViewRow();

      int index=dataGridView1.Rows.Add(Row);

      dataGridView1.Rows[index].Cells[0].Value=dr1[0].ToString();

      dataGridView1.Rows[index].Cells[1].Value=dr1[1].ToString();

      dataGridView1.Rows[index].Cells[2].Value=dr1[2].ToString();

      DataGridViewRow Row2=new DataGridViewRow();

      int index2=dataGridView1.Rows.Add(Row2);

      dataGridView1.Rows[index2].Cells[0].Value=dr2[0];

      dataGridView1.Rows[index2].Cells[1].Value=dr2[1];

      dataGridView1.Rows[index2].Cells[2].Value=dr2[2];  

    }

//DataGirdview导出txt文件,并自动对齐

    private void btnOutPutText_Click(object sender,EventArgs e)

    {

      string FullFileName=@"D:\aaa.txt";

     // FileStream fs=new FileStream(FullFileName,FileMode.CreateNew);

      StreamWriter sw=new StreamWriter(FullFileName,true,Encoding.Default);

      string str="";

      for(int i=0;i<dataGridView1.Rows.Count-1;i++)

      {

        for(int j=0;j<dataGridView1.Columns.Count;j++)

        {

         str=dataGridView1.Rows[i].Cells[j].Value.ToString().Trim();

         if(str.Length<10)

           str=str.PadRight(10,' ');

         str=str+"|";

          sw.Write(str);

        }

        sw.WriteLine("");

      }

      sw.Close();

    }

C# DataGirdview手动添加数据,导出txt文件并自动对齐的更多相关文章

  1. JavaScript 上万条数据 导出Excel文件(改装版)

    最近项目要js实现将数据导出excel文件,网上很多插件实现~~那个开心呀,谁知道后面数据量达到上万条时出问题:浏览器不仅卡死,导出的excel文件一直提示网络失败.... debug调试发现var  ...

  2. JavaScript 上万条数据 导出Excel文件 页面卡死

    最近项目要js实现将数据导出excel文件,网上很多插件实现~~那个开心呀,谁知道后面数据量达到上万条时出问题:浏览器不仅卡死,导出的excel文件一直提示网络失败.... debug调试发现var  ...

  3. php添加数据到xml文件的例子

    php添加数据到xml文件中 时间:2015-12-17 06:30:37来源:网络 导读:php添加数据到xml文件中   xml文件:stu.xml: 复制代码代码如下: <?xml ver ...

  4. 【应用】:shell crontab定时生成oracle表的数据到txt文件,并上传到ftp

    一.本人环境描述      1.oracle服务端装在win7 32位上,oracle版本为10.2.0.1.0      2.Linux为centos6.5 32位,安装在Oracle VM Vir ...

  5. asp mvc 导出txt 文件泛型方法

    asp mvc 导出txt 文件泛型方法分享: public static void ExportFile<T>(T obj) { StringBuilder str = new Stri ...

  6. MATLAB实例:新建文件夹,保存.mat文件并保存数据到.txt文件中

    MATLAB实例:新建文件夹,保存.mat文件并保存数据到.txt文件中 作者:凯鲁嘎吉 - 博客园 http://www.cnblogs.com/kailugaji/ 用MATLAB实现:指定路径下 ...

  7. C#将DataTable数据导出CSV文件

    C#将DataTable数据导出CSV文件通用方法! //导出按钮调用导出方法    protected void btnCSV_Click(object sender, EventArgs e)   ...

  8. sql 存储过程导出指定数据到.txt文件(定时)

    需求:每天生成一份txt文件数据,供第三方通过http方式调用 方法: 1.新建存储过程: USE [LocojoyMicroMessage] GO /****** Object: StoredPro ...

  9. mysql 导出行数据到txt文件,指定字符分割

    select id,name, concat('tel:',phone) from user order by time INTO outfile 'user.txt' FIELDS terminat ...

随机推荐

  1. Unity 资源的优化管理 学习

  2. Git安装和TortoiseGit详细使用教程【基础篇】

    标签:tortoisegit 环境:win8.1 64bit 安装准备: 首先你得安装windows下的git msysgit1.9.5 安装版本控制器客户端tortoisegit  tortoise ...

  3. Linq中left join之多表查询

    using System; using System.Collections; using System.Collections.Generic; using System.Data; using S ...

  4. linux之 修改磁盘调度算法

    IO调度器的总体目标是希望让磁头能够总是往一个方向移动,移动到底了再往反方向走,这恰恰就是现实生活中的电梯模型,所以IO调度器也被叫做电梯. (elevator)而相应的算法也就被叫做电梯算法.而Li ...

  5. Java 解密错误InvalidKeyException: Illegal key size解决方法

    做解密操作,出现如下错误 java.security.InvalidKeyException: Illegal key size // 设置解密模式为AES的CBC模式 Cipher cipher = ...

  6. NET设计模式 第二部分 行为型模式(17):迭代器模式(Iterator Pattern)

    概述 在面向对象的软件设计中,我们经常会遇到一类集合对象,这类集合对象的内部结构可能有着各种各样的实现,但是归结起来,无非有两点是需要我们去关心的:一是集合内部的数据存储结构,二是遍历集合内部的数据. ...

  7. 如何使用Hanlp加载大字典

        问题 因为需要加载一个 近 1G 的字典到Hanlp中,一开始使用了CustomDictionay.add() 方法来一条条的加载,果然到了中间,维护DoubleArraTre 的成本太高,添 ...

  8. Feign 请求拦截器和日志

    Feign 支持请求拦截器,在发送请求前,可以对发送的模板进行操作,例如设置请求头等属性,自定请求拦截器需要实现 feign.RequestInterceptor 接口,该接口的方法 apply 有参 ...

  9. linux Centos 服务器之间NFS文件共享挂载

    linux Centos 6.9服务器之间文件共享挂载 目的:因为服务器设置了负载均衡,多服务器的文件上传必然要同步,这里的目的把服务器1设置为主文件服务器 服务器1:192.168.1.100(共享 ...

  10. 图数据库cayley+mongo的起航之旅

    图数据库,目前比较主流的可能是Neo4j以及cayley了.但是,由于Neo4j只有社区版是免费的,所以,选择cayley作为项目的最终选择! 今天就简单的介绍下,我的起航之旅. 1.安装go语言环境 ...