我正在更新的软件,削减和拼接PowerPoint幻灯片为最终用户。幻灯片上有图表。我需要找到一种方法来隐藏原始图表数据对接收文件的用户。
在PowerPoint互操作中是否存在本机这样做呢?我尝试过只读,但用户仍然可以获取数据。
发布于 2014-09-30 17:05:27
好的。这是我对我问题的最后答案。这显示了完整的代码,它可以完美地复制幻灯片,同时避免对图表进行编辑,即购买,将其转换为.png。
这也解决了前面保留占位符的问题。
希望这些代码对像我一样在互联网上搜索的人有帮助。
//Open the slides presentation
var pres = _application.Presentations.Open2007(item.PresentationPath,
Microsoft.Office.Core.MsoTriState.msoFalse,
Microsoft.Office.Core.MsoTriState.msoFalse,
Microsoft.Office.Core.MsoTriState.msoFalse,
Microsoft.Office.Core.MsoTriState.msoFalse);
//For slide ranges
foreach (var i in range)
{
//Get the old slide
var oldSlide = pres.Slides[i];
oldSlide.Copy();
//Paste the slide into the new presentation
var newSlide = newPresentation.Slides.Paste(totalSlides + 1);
newSlide.Design = oldSlide.Design;
newSlide.ColorScheme = oldSlide.ColorScheme;
/* The shapes haven't retained their content because we are not in slide...
view because there is no window. */
//Delete all the shapes that were just pasted in because of the slide paste.
for (int k = newSlide.Shapes.Count; k > 0; k--)
{
newSlide.Shapes[k].Delete();
}
//Put in our shapes
//Loop forwards, because we arn't editing the list and forward is required to
//maintain the zorder we want on some slides.
for (int j = 1; j <= oldSlide.Shapes.Count; j++)
{
var oldShape = oldSlide.Shapes[j];
oldShape.Copy();
//Paste Put it where it should be on the page
/* This is a special case where the client have put textboxes in the
Powerpoint and rotated throwing off the position, so we need treat as rotated
shapes to make it right. */
if (oldShape.HasTextFrame == MsoTriState.msoTrue && Math.Abs(oldShape.Rotation) > 0)
{
//Paste as a shape because it's a more complex object
//set ALL THE PROPERTIES just in case.
var newShape = newSlide.Shapes.PasteSpecial(PpPasteDataType.ppPasteShape);
newShape.Rotation = oldShape.Rotation;
newShape.Top = oldShape.Top;
newShape.Left = oldShape.Left;
newShape.TextFrame.Orientation = oldShape.TextFrame.Orientation;
newShape.TextFrame.WordWrap = oldShape.TextFrame.WordWrap;
newShape.TextFrame.VerticalAnchor = oldShape.TextFrame.VerticalAnchor;
}
else // Act normally
{
//Paste the old shape into the new slide as an image to ENSURE FORMATTING
var newShape = newSlide.Shapes.PasteSpecial(PpPasteDataType.ppPastePNG);
newShape.Top = oldShape.Top;
newShape.Left = oldShape.Left;
}
}
totalSlides += ((item.EndIndex - item.StartIndex) + 1);
pres.Close();
}编译新演示文稿后,必须删除所有占位符。
//Loop through all slides
foreach (Slide exportSlide in newPresentation.Slides)
{
//Delete the placeholders
for (int i = exportSlide.Shapes.Placeholders.Count; i > 0; i--)
{
exportSlide.Shapes.Placeholders[i].Delete();
}
}发布于 2014-02-26 16:16:33
取消图表组(以删除与原始数据的任何连接)
Sub UngroupAChart()
Dim oSh As Shape
Dim oNewSh As Shape
Dim oNewShapes As ShapeRange
Dim oSl As Slide
' for demo purposes, use the currently selected
' shape; up to tester to select a chart
Set oSh = ActiveWindow.Selection.ShapeRange(1)
' Get a reference to the shape's parent slide
' We'll need it later
Set oSl = oSh.Parent
' put the shape on the clipboard
oSh.Copy
Set oNewSh = oSl.Shapes.PasteSpecial(ppPasteEnhancedMetafile)(1)
oNewSh.Ungroup
' once you're done testing, delete the original chart
'oSh.Delete
End Sub发布于 2014-02-27 11:43:31
使用Steve代码的主体,我为我的使用创建了一个定制的代码。由于我正在以组件服务的形式与PowerPoint交互,所以我没有ActiveWindow或其他任何东西。
//Loop through all slides
foreach (Slide exportSlide in newPresentation.Slides)
{
//Loop through all shapes
foreach (Shape shape in exportSlide.Shapes)
{
//If the shape is a chart
if (shape.HasChart == MsoTriState.msoTrue)
{
//Copy to clipboard
shape.Copy();
//Paste as an image
var newShape = exportSlide.Shapes.PasteSpecial(PpPasteDataType.ppPastePNG);
//Move back to chart position
newShape.Left = shape.Left;
newShape.Top = shape.Top;
//Delete the original shape
shape.Delete();
}
}
}这可以很好地用图像代替图表(完全没有数据)。现在唯一的问题是,因为用包含图表的布局创建的幻灯片,当您在Powerpoint中打开幻灯片时,GUI会显示一个“插入图表”框。我试过:
exportSlide.Layout = PpSlideLayout.ppLayoutBlank;但是,由于我的客户端自定义模板,这不是空白,因此它是不可用的。
https://stackoverflow.com/questions/22013237
复制相似问题