2017-07-17 68 views
1

有没有什么方法可以将.ppt/.pptx文件保存到数据库中,然后能够检索它,以便在应用程序内编辑它?如何将ppt文件保存到WPF数据库并检索它们以进行编辑?

我知道我可以为.doc/.docx文件执行此操作 - 将它们存储为rtf格式并使用粗体,斜体,下划线和字体控件将它们加载到RichTextBox中,但是对于powerpoint文件?

到目前为止,我发现的最接近的解决方案涉及到converting the ppt files to a video format,但这只允许我查看幻灯片,而不是编辑幻灯片;以及使用WebBrowser控件和使用Navigate()在幻灯片之间导航,但是这又不允许任​​何编辑。

有没有解决这个问题的方法?

+0

为什么一个数据库,而不是文件系统? –

+0

你的实际问题是你如何编辑你实施的WPF应用程序中的PowerPoint文件?如果是这种情况,我认为没有办法做到这一点。只有当你自己实现PowerPoint文件的解析器和表示层时 –

回答

3

您可以使用OLE(对象链接和嵌入)将PowerPoint作为WPF中的ActiveX控件托管。不幸的是,WPF不直接支持OLE,而是WinForms。您将不得不使用WindowsFormsHost来放置一个WinForms控件,该控件将在您的WPF应用程序中执行OLE嵌入。

这一切都开始得到复杂,很快,但它可能。有一篇关于如何去做的微软文章here。您可能想将PowerPoint而不是Windows Media Player包装起来,但这个想法是一样的。这将要求最终用户安装了Power Point,并且很可能与应用程序编译的版本相同。

// Create the interop host control. 
System.Windows.Forms.Integration.WindowsFormsHost host = 
    new System.Windows.Forms.Integration.WindowsFormsHost(); 

// Create the ActiveX control. 
AxWMPLib.AxWindowsMediaPlayer axWmp = new AxWMPLib.AxWindowsMediaPlayer(); 

// Assign the ActiveX control as the host control's child. 
host.Child = axWmp; 

// Add the interop host control to the Grid 
// control's collection of child controls. 
this.grid1.Children.Add(host); 

将自己存储在数据库中将是一件容易的事。

here复制:

public static void databaseFilePut(string varFilePath) { 
    byte[] file; 
    using (var stream = new FileStream(varFilePath, FileMode.Open, FileAccess.Read)) { 
     using (var reader = new BinaryReader(stream)) { 
      file = reader.ReadBytes((int) stream.Length);  
     }   
    } 
    using (var varConnection = Locale.sqlConnectOneTime(Locale.sqlDataConnectionDetails)) 
    using (var sqlWrite = new SqlCommand("INSERT INTO Raporty (RaportPlik) Values(@File)", varConnection)) { 
     sqlWrite.Parameters.Add("@File", SqlDbType.VarBinary, file.Length).Value = file; 
     sqlWrite.ExecuteNonQuery(); 
    } 
} 
相关问题