//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. MySQL中视图

    视图是指计算机数据库中的视图,是一个虚拟表,其内容由查询定义.同真实的表一样,视图包含一系列带有名称的列和行数据.但是,视图并不在数据库中以存储的数据值集形式存在.行和列数据来自由定义视图的查询所引用 ...

  2. 【转】C#获取当前日期时间(转)

    我们可以通过使用DataTime这个类来获取当前的时间.通过调用类中的各种方法我们可以获取不同的时间:如:日期(2008-09-04).时间(12:12:12).日期+时间(2008-09-04 12 ...

  3. sql查询:存在A表而不在B表中的数据

    A.B两表,找出ID字段中,存在A表,但是不存在B表的数据. 方法一:使用 not inselect distinct A.ID from A where A.ID not in (select ID ...

  4. dojo Datagrid 实现数据删除功能

    DataGrid实现数据动态刷新功能见前一个帖子:http://www.cnblogs.com/qq552048250/p/4447103.html 实现数据删除只需要向表格中动态添加按钮,并为按钮的 ...

  5. ASP.NET AJAX入门系列(10):Timer控件简单使用

    本文主要通过一个简单示例,让Web页面在一定的时间间隔内局部刷新,来学习一下ASP.NET AJAX中的服务端Timer控件的简单使用. 主要内容 Timer控件的简单使用 1.添加新页面并切换到设计 ...

  6. show master status, show slave status中的Executed_Gtid_Set

    slave 如果server是slave节点,在server上执行show master staus与show slave status显示的Executed_Gtid_Set是一样的. slave也 ...

  7. KMP(字符串匹配)算法

    unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms ...

  8. windows server core 远程桌面

    要允许其它计算机透过远程桌面登入Server Core主机,我们需要先调整注册机码,并开启对应的防火墙端口号首先,我们开启登录编辑程序(regedit.exe),找到HKEY_LOCAL_MACHIN ...

  9. windebug 与 office Home

    https://officecdn.microsoft.com/sg/492350f6-3a01-4f97-b9c0-c7c6ddf67d60/media/zh-CN/HomeStudentRetai ...

  10. JAVA开源B2C系统

    前言 最近有人想面向境外销售商品,但是又不想依托于亚马逊这些平台,于是找我来帮忙想弄个B2C系统.因为刚开始只是打算试试水,也就不打算投入多少成本了.所以这边就考虑使用开源的B2C系统来直接使用了. ...