-
Download
并从Microsoft安装DSOFile DLL。
-
-
代码
以下是我的代码,归结为最低限度:
namespace Ibs.Ui.OrderPrint
{
public partial class OrderPrintEdit
{
public OrderPrintEdit()
{
InitializeComponent();
}
#region -- reports_SelectedIndexChanged(sender, e) Event Handler --
private void reports_SelectedIndexChanged(object sender, EventArgs e)
{
try
{
DSOFile.OleDocumentPropertiesClass oleDocumentPropertiesClass = new DSOFile.OleDocumentPropertiesClass();
DirectoryInfo reportDirectory = new DirectoryInfo(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + "\\Reports");
oleDocumentPropertiesClass.Open(reportDirectory + "\\" + reports.Text,true,DSOFile.dsoFileOpenOptions.dsoOptionDontAutoCreate);
Object thumbnail = oleDocumentPropertiesClass.SummaryProperties.Thumbnail;
if (thumbnail != null)
{
reportThumbnail.BackgroundImage = IPictureDispHost.GetPictureFromIPicture(thumbnail);
}
else
{
reportThumbnail.BackgroundImage = null;
}
oleDocumentPropertiesClass.Close(false);
}
catch (Exception ex)
{
}
}
#endregion
}
internal sealed class IPictureDispHost : AxHost
{
private IPictureDispHost() : base("{63109182-966B-4e3c-A8B2-8BC4A88D221C}")
{
}
/// <summary>
/// Convert the dispatch interface into an image object.
/// </summary>
/// <param name="picture">The picture interface</param>
/// <returns>An image instance.</returns>
public new static Image GetPictureFromIPicture(object picture)
{
return AxHost.GetPictureFromIPicture(picture);
}
}
}
我正在用表单加载上的报告名称填充一个组合框。在SelectedIndexChanged事件中,我从报告中获取缩略图对象并将其传递给转换方法。这也适用于Office文档。