| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1364 人关注过本帖
标题:导入Excel后就变成为了科学计数法
取消只看楼主 加入收藏
小丑鱼爱丘
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2010-5-30
结帖率:0
收藏
 问题点数:0 回复次数:0 
导入Excel后就变成为了科学计数法
private void button4_Click(object sender, System.EventArgs e)
        {
            OleDbConnection cn = new OleDbConnection("Data Source=xsxxdb.mdb;Jet OLEDB:Engine Type=5;Provider=Microsoft.Jet.OLEDB.4.0");
            cn.Open();
            string sql = "select StudentInfo.StudentId as 自动编号,studentinfo.studentnumber as 学号,studentinfo.name as 姓名,studentinfo.sex as 性别,studentinfo.race as 族别,studentinfo.address as 家庭住址,studentinfo.telephone as 联系方式,studentinfo.role as 政治面貌,studentinfo.postalcode as 邮政编码,classinfo.classname as 班级名称,studentinfo.remark as 备注 from studentinfo inner join classinfo on studentinfo.classid = classinfo.classid where classinfo.classname='" + comboBox2.Text.ToString() + "' order by studentnumber";
            OleDbDataAdapter adp = new OleDbDataAdapter(sql, oleDbConnection1);
            DataSet ds = new DataSet();
            adp.Fill(ds, "student");
            AddExcel(ds);

        }

        protected void AddExcel(DataSet ds)
        {
            DataTable dt = ds.Tables["student"];
            string fileName = Guid.NewGuid() + ".xls";
            Excel.Application excel = new Excel.ApplicationClass();
            int rowIndex = 1;
            int colIndex = 0;
            excel.Application.Workbooks.Add(true);

            foreach (DataColumn col in dt.Columns)
            {
                colIndex++;
                excel.Cells[1, colIndex] = col.ColumnName;
            }
            foreach (DataRow row in dt.Rows)
            {
                rowIndex++;
                colIndex = 0;
                for (colIndex = 0; colIndex < dt.Columns.Count; colIndex++)
                {
                    excel.Cells[rowIndex, colIndex + 1] = row[colIndex].ToString();
                }
            }
            excel.Visible = true;
            excel.ActiveWorkbook.SaveAs(fileName, Excel.XlFileFormat.xlExcel9795, null, null, false, false, Excel.XlSaveAsAccessMode.xlNoChange, null, null, null, null, null);

            GC.Collect();
        }
搜索更多相关主题的帖子: Excel 计数法 科学 
2010-05-31 19:30
快速回复:导入Excel后就变成为了科学计数法
数据加载中...
 
   



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

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