如何将 ppt 文件保存到 WPF 数据库并检索它们进行编辑?



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

我知道我可以对 .doc/.docx 文件执行此操作 - 将它们以 rtf 格式存储并将它们加载到具有粗体、斜体、下划线和字体控件的RichTextBox中,但是 PowerPoint 文件有这样的东西吗?

到目前为止,我发现的最接近我想要实现的解决方案包括将ppt文件转换为视频格式,但这只允许我查看PowerPoint,而不是编辑它;以及使用WebBrowser控件并使用Navigate()在幻灯片之间导航,但这再次不允许任何编辑。

有什么解决方案吗?

您可以使用 OLE(对象链接和嵌入(将 PowerPoint 作为 WPF 中的 ActiveX 控件承载。 不幸的是,WPF 不直接支持 OLE,但 WinForms 支持。 您必须使用WindowsFormsHost来放置 WinForms 控件,该控件在 WPF 应用程序中执行 OLE 嵌入。

这一切都开始变得非常复杂,非常快,但这是可能的。 这里有一篇关于如何做到这一点的Microsoft文章。 您可能希望包装PowerPoint而不是Windows Media Player,但想法是相同的。 这将要求最终用户安装了 PowerPoint,并且很可能与编译应用程序所针对的版本相同。

// 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);

将文件本身存储在数据库中将是容易的部分。

从这里复制:

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();
}
}

最新更新