zoukankan      html  css  js  c++  java
  • silverlight导出excel

    开发导出excel,首先需要添加项目引用。

    Microsoft.CSharp

    这个是应用dynamic的前提。

    在代码页,需要添加引用

    using System.Runtime.InteropServices.Automation;

    以下是我具体制作业务导出的其中一个功能的代码,供大家参考。

    private ICommand _excelCommand;
            public ICommand ExcelCommand
            {
                get
                {
                    if (_excelCommand == null)
                    {
                        _excelCommand = new RelayCommand<Grid>((g) =>
                        {
                            dynamic excel = AutomationFactory.CreateObject("Excel.Application");
                            excel.Visible = true;
                            dynamic workbook = excel.workbooks;
                            workbook.Add();
                            dynamic sheet = excel.ActiveSheet;
                            dynamic cell = null;
                            int i = 1;
                            // 将数据传输到Excel
                            foreach (BusinessBillOutModel item in SelectItems)
                            {
                                //ItemCollection.Add(item);
    
                                //销售日期
                                cell = sheet.Cells[i, 1]; // 列和行
                                cell.Value = item.BillDate;
                                cell.ColumnWidth = 25;
                                //名称
                                cell = sheet.Cells[i, 2];
                                cell.Value = SettingSpace.CodeNameConvert(GlobalEnum.BaseType.BasePart, item.PartCode);
                                //金额
                                cell = sheet.Cells[i, 3];
                                cell.Value = item.TotalPrice;
                                //班组
                                cell = sheet.Cells[i, 4];
                                cell.Value = SettingSpace.CodeNameConvert(GlobalEnum.BaseType.TeamWork,item.TeamWork);
                                //收款员(里台员)
                                cell = sheet.Cells[i, 5];
                                cell.Value = SettingSpace.CodeNameConvert(GlobalEnum.BaseType.UserType,item.SellPerson);
                                //司机
                                cell = sheet.Cells[i, 6];
                                cell.Value = SettingSpace.CodeNameConvert(GlobalEnum.BaseType.UserType,item.AgentPerson);
                                //备注
                                cell = sheet.Cells[i, 6];
                                cell.Value = item.BillRemark;
                                
    
                                i++;
                            }
                        });
                    }
    
                    return _excelCommand;
                }
            }
    View Code

    //开发过程中遇到的问题。

    在开发silverlight导出excel时遇到【此操作在当前上下文中不受支持】,最后调试成功,具体原因,是在项目的属性设置中没有勾选一个选项,具体参看截图。

    点击 浏览器外设置,在弹出界面勾选 在浏览器之外运行时需要提升的信任。即可解决

  • 相关阅读:
    【安全测试】sqlmap安装方法
    【安全测试】 WebScarab安装方法
    【安全测试】burpsuite安装方法
    【Jenkins】Windows下安装&访问jenkins
    【Python】下拉框元素的找法
    【python】selenium+python自动化测试环境搭建
    【接口测试】Jenkins+Ant+Jmeter搭建持续集成的接口测试平台
    【修改端口号】linux下修改apache,nginx服务端口号
    【linux】linux下yum安装后Apache、php、mysql默认安装路径
    地址
  • 原文地址:https://www.cnblogs.com/eric_ibm/p/silverlight.html
Copyright © 2011-2022 走看看