C# Dsoframer.ocx 如何在winform中嵌入Excel,內嵌Excel,word

來源:互聯網
上載者:User

標籤:

如果你還不太清楚Dspframer.ocx怎麼放到表單上就看上一篇文章,裡面詳細介紹了是如何放到表單上的。

連結:http://www.cnblogs.com/pingming/p/4182045.html

第一步 建立新表單

建立一個新表單,放置一個panel容器控制項,我們就是要將dsoframer.ocx放到panel裡面。

第二步 下面是所有調用的方法,有步驟的。

public partial class ExcelForm : DevExpress.XtraEditors.XtraForm    {        private AxDSOFramer.AxFramerControl m_axFramerControl = new AxDSOFramer.AxFramerControl();        public ExcelForm()        {            InitializeComponent();        }        #region Excel 的載入        //總的載入Excel方法        private void Init(string _ExcelFilePath)        {            try            {                RegControl();                if (!File.Exists(_ExcelFilePath))                {                    XtraMessageBox.Show("檔案不存在或未標識的檔案格式!", "提示資訊");                    return;                    //throw new ApplicationException("檔案不存在或未標識的檔案格式!");                }                AddAxFramerControl();//載入填充控制項                InitOfficeControl(_ExcelFilePath);            }            catch (Exception ex)            {                throw ex;            }        }//第二步:向panel填充AxFramerControl控制項        private void AddAxFramerControl()        {            try            {                this.panelExcel.Controls.Add(m_axFramerControl);                m_axFramerControl.Dock = DockStyle.Fill;            }            catch (Exception ex)            {                XtraMessageBox.Show(ex.Message);                throw;            }        }        //第一步:註冊AxFramerControl        public bool RegControl()        {            try            {                Assembly thisExe = Assembly.GetExecutingAssembly();                System.IO.Stream myS = thisExe.GetManifestResourceStream("NameSpaceName.dsoframer.ocx");                string sPath = System.AppDomain.CurrentDomain.BaseDirectory + @"\dsoframer.ocx";                ProcessStartInfo psi = new ProcessStartInfo("regsvr32", "/s " + sPath);                Process.Start(psi);            }            catch (Exception ex)            {                MessageBox.Show(ex.Message);            }            return true;        }        //下面這個方法是dso開啟檔案時需要的一個參數,代表office檔案類型        /// <summary>        /// 根據尾碼名得到開啟檔案        /// </summary>        /// <param name="_sExten"></param>        /// <returns></returns>        private string LoadOpenFileType(string _sExten)        {            try            {                string sOpenType = "";                switch (_sExten.ToLower())                {                    case "xls":                        sOpenType = "Excel.Sheet";                        break;                    case "doc":                        sOpenType = "Word.Document";                        break;                    case "ppt":                        sOpenType = "PowerPoint.Show";                        break;                    case "vsd":                        sOpenType = "Visio.Drawing";                        break;                    default:                        sOpenType = "Word.Document";                        break;                }                return sOpenType;            }            catch (Exception ex)            {                throw ex;            }        }        /// <summary>        /// 第三步:初始化office控制項,載入Excel        /// </summary>        /// <param name="_sFilePath">本地文檔路徑</param>        private void InitOfficeControl(string _sFilePath)        {            try            {                if (m_axFramerControl == null)                {                    throw new ApplicationException("請先初始化office控制項對象!");                }                //this.m_axFramerControl.SetMenuDisplay(48);                //這個方法很特別,一個組合菜單控制方法,我還沒有找到參數的規律,有興趣的朋友可以研究一下                string sExt = System.IO.Path.GetExtension(_sFilePath).Replace(".", "");                //this.m_axFramerControl.CreateNew(this.LoadOpenFileType(sExt));//建立新的檔案                this.m_axFramerControl.Open(_sFilePath, false, this.LoadOpenFileType(sExt), "", "");//開啟檔案                //隱藏標題                this.m_axFramerControl.Titlebar = false;            }            catch (Exception ex)            {                throw ex;            }        }        /// <summary>        /// 關閉當前介面        /// </summary>        public void Close()        {            try            {                if (this.m_axFramerControl != null)                {                    this.m_axFramerControl.Close();                }            }            catch (Exception ex)            {                throw ex;            }        }        //載入Excel 按鈕        private void sbtnLoading_Click(object sender, EventArgs e)        {            Init(System.AppDomain.CurrentDomain.BaseDirectory + "excel\\項目匯總表.xls");        }        //關閉        private void ExcelForm_FormClosing(object sender, FormClosingEventArgs e)        {            Close();        }        #endregion}

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

C# Dsoframer.ocx 如何在winform中嵌入Excel,內嵌Excel,word

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.