| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1364 人关注过本帖
标题:导入Excel后就变成为了科学计数法
只看楼主 加入收藏
小丑鱼爱丘
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2010-5-30
结帖率:0
收藏
 问题点数:0 回复次数:2 
导入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
daiwenyi2004
Rank: 2
等 级:论坛游民
帖 子:3
专家分:10
注 册:2010-6-5
收藏
得分:0 
将Excel采用模板式样,然后设置好文字的格式为字符
2010-06-05 10:32
wjnmrywmc
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2012-9-20
收藏
得分:0 
导入数据之前,先设置单元格格式
2016-03-23 19:22
快速回复:导入Excel后就变成为了科学计数法
数据加载中...
 
   



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

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