| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 727 人关注过本帖
标题:C#如何操作Excel 初学者
只看楼主 加入收藏
tianxueshan
Rank: 1
等 级:新手上路
帖 子:19
专家分:5
注 册:2010-1-4
结帖率:100%
收藏
已结贴  问题点数:6 回复次数:2 
C#如何操作Excel 初学者

  在窗体上加一按钮,单击后,在D盘目录下的123.xls单元格A1里填充文字。
搜索更多相关主题的帖子: Excel 
2010-01-15 17:33
qingzhu5753
Rank: 4
等 级:业余侠客
帖 子:64
专家分:248
注 册:2009-10-28
收藏
得分:2 
你需要引用excel包,其他的网上有资料,具体我也没操作过,学习
2010-01-22 10:02
jiaguofu2005
Rank: 2
等 级:论坛游民
帖 子:47
专家分:59
注 册:2009-9-2
收藏
得分:2 
SaveFileDialog saveFileDialog = new SaveFileDialog();
            saveFileDialog.Filter = "Execl files (*.xls)|*.xls";
            saveFileDialog.FilterIndex = 0;
            saveFileDialog.RestoreDirectory = true;
            saveFileDialog.CreatePrompt = true;
            saveFileDialog.Title = "Export Excel File To";

            if (saveFileDialog.ShowDialog() == DialogResult.Cancel)
            {
                return;
            }
            Stream myStream;
            myStream = saveFileDialog.OpenFile();

            int ColumnCount = 3;

            StreamWriter sw = new StreamWriter(myStream, System.Text.Encoding.Unicode);
            string str = "";
            try
            {
                for (int i = 0; i < ColumnCount; i++)   //写标题-------------------------------
                {
                    if (i > 0)
                    {
                        str += "\t";
                    }
                    str += dataGridView2.Columns[i].HeaderText;
                }
                sw.WriteLine(str);

                for (int j = 0; j < dataGridView2.Rows.Count; j++)    //写内容--------------------------------
                {
                    string tempStr = "";
                    for (int k = 0; k < ColumnCount; k++)
                    {
                        if (k > 0)
                        {
                            tempStr += "\t";
                            if (k == 1)
                            {
                                tempStr += "'";
                            }
                        }
                        tempStr += dataGridView2.Rows[j].Cells[k].Value.ToString();
                    }
                    sw.WriteLine(tempStr);
                }
                sw.Close();
                myStream.Close();
                // MessageBox.Show("导出成功!","系统提示");
            }
2010-01-22 14:58
快速回复:C#如何操作Excel 初学者
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.033687 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved