C# 导出 EXCEL 科学计数

            ApplicationClass excel = new ApplicationClass();
            excel.Visible = true;       //激活Excel
            Workbook wBook = excel.Workbooks.Add(true);
            Worksheet wSheet = (Worksheet)wBook.ActiveSheet;
            //全表自动列宽
            wSheet.Cells.Select();//先选择
            wSheet.Cells.Columns.AutoFit();//后操作,自动列宽
            wSheet.Cells.NumberFormat = "@";//后操作,设置单元格为广西格式

            wSheet.Name = "联系人信息";
            excel.Cells[1, 1] = "会员卡号";
            excel.Cells[1, 2] = "姓名";
            excel.Cells[1, 3] = "年龄";
            excel.Cells[1, 4] = "电话";
            excel.Cells[1, 5] = "地址";
            excel.Cells[1, 6] = "性别";

            List<AddrLibInfo> results = GetAllInfos();
            int index = 2;
            foreach (AddrLibInfo info in results)
            {
                if (info.Type == "0")
                {
                    excel.Cells[index, 1] = info.BUYERID.ToString();
                    excel.Cells[index, 2] = info.NAME.ToString();
                    excel.Cells[index, 3] = info.AGE.ToString();
                    excel.Cells[index, 4] = info.TEL.ToString();
                    excel.Cells[index, 5] = info.ADDRESS.ToString();
                    excel.Cells[index, 6] = info.GENDER.ToString();
                    index++;
                }
            }

            //设置禁止弹出保存和覆盖的询问提示框
            excel.DisplayAlerts = false;
            excel.AlertBeforeOverwriting = false;
            //保存工作薄
            //wBook.Save();
            //每次保存激活的表,这样才能多次操作保存不同的Excel表,默认保存位置是在”我的文档"
            excel.Cells.Font.Size = 12;
            excel.Cells.Font.Bold = false;
            //wSheet.get_Range(excel.Cells[1, 3], excel.Cells[1, 3]).Font.Size = 24;
            wSheet.get_Range(excel.Cells[1, 1], excel.Cells[1, 6]).Font.Bold = true;
            //wSheet.get_Range(excel.Cells[3, 1], excel.Cells[3, 1]).Font.ColorIndex = 3;//此处设为红色,不能用Font.Color来设置颜色
            excel.ActiveWorkbook.SaveCopyAs(path + "\\联系人信息.xls");
            excel.Quit();

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值