silverlight导出excel
生活随笔
收集整理的這篇文章主要介紹了
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;// 將數據傳輸到Excelforeach (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時遇到【此操作在當前上下文中不受支持】,最后調試成功,具體原因,是在項目的屬性設置中沒有勾選一個選項,具體參看截圖。
?
點擊 瀏覽器外設置,在彈出界面勾選 在瀏覽器之外運行時需要提升的信任。即可解決
?
轉載于:https://www.cnblogs.com/eric_ibm/p/silverlight.html
總結
以上是生活随笔為你收集整理的silverlight导出excel的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: OOP组合和继续的优缺点
- 下一篇: zoj3806Incircle and