开发导出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 = ;
// 将数据传输到Excel
foreach (BusinessBillOutModel item in SelectItems)
{
//ItemCollection.Add(item); //销售日期
cell = sheet.Cells[i, ]; // 列和行
cell.Value = item.BillDate;
cell.ColumnWidth = ;
//名称
cell = sheet.Cells[i, ];
cell.Value = SettingSpace.CodeNameConvert(GlobalEnum.BaseType.BasePart, item.PartCode);
//金额
cell = sheet.Cells[i, ];
cell.Value = item.TotalPrice;
//班组
cell = sheet.Cells[i, ];
cell.Value = SettingSpace.CodeNameConvert(GlobalEnum.BaseType.TeamWork,item.TeamWork);
//收款员(里台员)
cell = sheet.Cells[i, ];
cell.Value = SettingSpace.CodeNameConvert(GlobalEnum.BaseType.UserType,item.SellPerson);
//司机
cell = sheet.Cells[i, ];
cell.Value = SettingSpace.CodeNameConvert(GlobalEnum.BaseType.UserType,item.AgentPerson);
//备注
cell = sheet.Cells[i, ];
cell.Value = item.BillRemark; i++;
}
});
} return _excelCommand;
}
}

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

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

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

silverlight导出excel的更多相关文章

  1. js 导出Excel

    最近从Silverlight这边转到javascript过来,现在要导出一个导出excel的功能.上级领导指示当页显示多少数据,就导出多少数据,没有必要从后台在去数据.以前也没有接触过这方面的,在网上 ...

  2. 导入,导出excel

    /// <summary> /// 导出数据 /// </summary> /// <param name="XMMC"></param& ...

  3. C#使用Aspose.Cells导出Excel简单实现

    首先,需要添加引用Aspose.Cells.dll,官网下载地址:http://downloads.aspose.com/cells/net 将DataTable导出Xlsx格式的文件下载(网页输出) ...

  4. 利用poi导出Excel

    import java.lang.reflect.Field;import java.lang.reflect.InvocationTargetException;import java.lang.r ...

  5. [django]数据导出excel升级强化版(很强大!)

    不多说了,原理采用xlwt导出excel文件,所谓的强化版指的是实现在网页上选择一定条件导出对应的数据 之前我的博文出过这类文章,但只是实现导出数据,这次左思右想,再加上网上的搜索,终于找出方法实现条 ...

  6. NPOI导出Excel

    using System;using System.Collections.Generic;using System.Linq;using System.Text;#region NPOIusing ...

  7. ASP.NET Core 导入导出Excel xlsx 文件

    ASP.NET Core 使用EPPlus.Core导入导出Excel xlsx 文件,EPPlus.Core支持Excel 2007/2010 xlsx文件导入导出,可以运行在Windows, Li ...

  8. asp.net DataTable导出Excel 自定义列名

    1.添加引用NPOI.dll 2.cs文件头部添加 using NPOI.HSSF.UserModel; using NPOI.SS.UserModel; using System.IO; 3.代码如 ...

  9. Aspose.Cells导出Excel(1)

    利用Aspose.Cells导出excel 注意的问题 1.DataTable的处理 2.进行编码,便于中文名文件下载 3.别忘了Aspose.Cells.dll(可以自己在网上搜索) public ...

随机推荐

  1. CSS3中的伪类选择器详解

      类选择器和伪类选择器区别 类选择器我们可以随意起名,而伪类选择器是CSS中已经定义好的选择器,不可以随意起名. 伪类选择器以及伪元素 我们把它放到这里 p.aaas{ text-align: le ...

  2. 《基于Apache Kylin构建大数据分析平台》

    Kyligence联合创始人兼CEO,Apache Kylin项目管理委员会主席(PMC Chair)韩卿 武汉市云升科技发展有限公司董事长,<智慧城市-大数据.物联网和云计算之应用>作者 ...

  3. 阿里巴巴、美团等各大互联网公司的 Java类 校招对本科生有什么要求?

    转载: 阿里巴巴.美团等各大互联网公司的 Java类 校招对本科生有什么要求?

  4. 习题 5: 更多的变量和打印 | 笨办法学 Python

    一. 简述 “格式化字符串(format string)” -  每一次你使用 ' ’ 或 " " 把一些文本引用起来,你就建立了一个字符串. 字符串是程序将信息展示给人的方式. ...

  5. 我的mysql测试环境

    版本:5.7 安装方式:yum 修改密码:alter user user() identified by 'root'; 修改配置文件: vi /etc/my.cnf 在my.cnf中添加 skip- ...

  6. yum源安装Mysql

    Mysql版本:5.7 进入mysql官网,复制下载链接 步骤: (1) wget  http://dev.mysql.com/get/mysql57-community-release-el6-9. ...

  7. php 保存到mysql数据库中的中文乱码

    近期又php项目,乱码是个头痛的问题 解决方法: 1,php 文件中 添加 header(“Content-Type: text/html; charset=utf-8"); 2,需要做数据 ...

  8. spring.net 配置文件需要注意换行问题

    今天在做Spring.NET Demo时写配置文件写ObjectNames 节点的Value成这样 <object id="ProxyCreator" type=" ...

  9. iOS安全相关学习资料

    https://github.com/zhengmin1989/iOS_ICE_AND_FIRE  (冰与火代码) http://weibo.com/zhengmin1989?is_hot=1 (蒸米 ...

  10. 多项目开发下的dll文件管理

    阅读目录: DS01:为什么要对生成的dll文件进行管理? DS02:首先介绍以下两个DOS命令 DS03:第一种实现方法(xcopy) DS04:第二种实现方法(attrib) DS05:分享一个有 ...