将选定的 PowerPoint 形状(或 DrawingML)转换为 XAML [英] Convert Selected PowerPoint Shapes (or DrawingML) to XAML

查看:37
本文介绍了将选定的 PowerPoint 形状(或 DrawingML)转换为 XAML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要将选定的 PowerPoint 形状转换为 XAML,以便我可以在我的 WPF 应用程序中有效地放置一个等效的基于矢量的形状(XAML 最终结果必须可缩放 - 转换为图像会使我正在尝试做的事情的目的).

I need to convert selected PowerPoint shapes to XAML so I can effectively place an equivalent vector-based shape inside my WPF app (the XAML end result has to be scalable - converting to an image defeats the purpose of what I'm trying to do).

我愿意采用多种方法来实现这一点,包括编写 PowerPoint 插件(如果这能让我访问 PowerPoint 中所选形状的贝塞尔点坐标).我对 PowerPoint 插件不够熟悉,不知道这是否可行.

I'm open to a variety of ways to accomplish this, including writing a PowerPoint addin (if this could get me access to the bezier point coordinates of the selected shapes in PowerPoint). I'm not familiar enough with PowerPoint addins to know if this is possible or not.

我的第一种方法是将 PowerPoint 形状复制到剪贴板,然后将剪贴板内容转换为我可以理解的对象,然后从那里生成 XAML.如果我这样做,我可以得到 DrawingML 表示(通过 Art::GVML ClipFormat),但不清楚如何轻松地将该 DrawingML 转换为 XAML(看起来像从头开始创建数周的容易出错的工作).

My first approach was to copy the PowerPoint shapes to the clipboard, and then convert the clipboard contents to objects I can understand and then generate the XAML from there. If I do this I can get to the DrawingML representation (through the Art::GVML ClipFormat), but it's unclear how to easily convert that DrawingML to XAML (looks like weeks of error-prone work to create from scratch).

剪贴板上还有其他可用的格式(EMF、System.Drawing.Imaging.Metafile、PowerPoint 12.0 Internal Shapes),但它们似乎都是死胡同.

There are other formats available on the clipboard (EMF, System.Drawing.Imaging.Metafile, PowerPoint 12.0 Internal Shapes), but they all appear to be dead ends.

有什么建议吗?

推荐答案

你可以试试这个:

WMF 的 Powerpoint 形状

Powerpoint Shape to WMF

Microsoft.Office.Interop.PowerPoint.Application app = new Microsoft.Office.Interop.PowerPoint.Application();
var pps = app.Presentations;
string d ="filepath.pptx";
Presentation ppt = pps.Open(d, MsoTriState.msoFalse, MsoTriState.msoFalse, MsoTriState.msoFalse);
for (int j = 1; j < ppt.Slides.Count; j++)
{
    Slide sld = ppt.Slides[j];
    List<Microsoft.Office.Interop.PowerPoint.Shape> shapes = new List<Microsoft.Office.Interop.PowerPoint.Shape>();
    for (int k = 1; k < sld.Shapes.Count; k++)
    {
        Microsoft.Office.Interop.PowerPoint.Shape shape = sld.Shapes[k]; 
        shape.Export("outputFilePath.wmf", PpShapeFormat.ppShapeFormatWMF);
    }
}

然后 WMF 到 XAML:微软论坛:

then WMF to XAML: Microsoft Forum:

1) 查看 http://www.wpf-graphics.com/ReaderWmf.aspx 及其相关项目 http://www.wpf-graphics.com/Paste2Xaml.aspx.这些是 WPF 的 EMF/WMF 阅读器.您将编写一个简单的实用程序来读入图像并再次将它们写回.我和他们一起玩了一会儿,而且运气还不错.如果他们为你工作,这将是我的第一选择.你当然需要测试它们.由于各种格式之间的设计差异,这样的转换永远不会完美,因此请确保您没有使用转换器不支持的内容.

1) Check out http://www.wpf-graphics.com/ReaderWmf.aspx and it's related project http://www.wpf-graphics.com/Paste2Xaml.aspx. These are EMF/WMF readers for WPF. You'd write a simple utility to read in the images and write them back out again. I've played with them a little and had pretty good luck with them. If they'll work for you, this would be my first choice. You'll need to test them of course. Conversions like this are never perfect due to difference in design between the various formats so make sure you're not using something that's not supported in the converter.

2) 我遇到的另一个项目是 http://lab.aspitalia.com/15/EmfToXaml-Beta.aspx.我没玩过,但你可以看看.

2) Another project I ran into was http://lab.aspitalia.com/15/EmfToXaml-Beta.aspx. I haven't played with it, but you might give it a look.

3) 如果直接路由不起作用,您可以考虑将 WMF 文件转换为不同的矢量格式,如 SVG,然后将该 SVG 文件转换为 XAML.有很多工具可以将 EMF/WMF 转换为 SVG.对于 SVG 到 XAML 的转换,您可以查看 http://www.codeplex.com/XamlTunehttp://www.wpf-graphics.com/ReaderSvg.aspx.我怀疑这会像直接转换一样有效,但你永远不知道.

3) If the direct route doesn't work, you might consider converting the WMF files to a different vector format like SVG and then converting that SVG file to XAML. There are lots of tools for EMF/WMF to SVG conversion. For the SVG to XAML conversion you can look at http://www.codeplex.com/XamlTune and http://www.wpf-graphics.com/ReaderSvg.aspx. I doubt this will work as well as a direct conversion, but you never know.

关于 PowerPoint 插件和运行上述示例,您需要 Microsoft Office 互操作库.

About PowerPoint Add-ins and Running the above example you need Microsoft Office Interop libraries.

这篇关于将选定的 PowerPoint 形状(或 DrawingML)转换为 XAML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆