silverlight匯出excel

來源:互聯網
上載者:User

標籤:style   blog   http   color   os   io   ar   for   資料   

開發匯出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時遇到【此操作在當前上下文中不受支援】,最後調試成功,具體原因,是在項目的屬性設定中沒有勾選一個選項,具體參看。

 

點擊 瀏覽器外設定,在彈出介面勾選 在瀏覽器之外運行時需要更高的信任。即可解決

 

silverlight匯出excel

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.