【发布时间】:2015-10-07 15:34:00
【问题描述】:
我有几个 Excel 报告,第一步需要将选定的图表导出为图像。然后我需要将这些图像导入到 PowerPoint 演示文稿中。 看来我快到了,但卡住了。
- 我正在尝试使用方法 chartObjects 获取工作表的所有图表(我已尝试使用方法图表,但后来我的集合为空)。
然后我将选定的图表作为图片复制到剪贴板中(当这将起作用时,我将使用 forEach 来获取我工作簿的所有图表)。
但是,当我尝试保存剪贴板数据时,那里似乎没有图片,而有数据。
$xl = new-object -c excel.application
$xl.displayAlerts = $false
$xl.visible = $false
$wb = $xl.workbooks.open($fileData)
$ws= $wb.sheets.Item("Sheet1")
$chartCollect = $ws.chartObjects()
$chartToExport = $chartCollect.Item(3)
$toClipboard = $charToExport.copyPicture()
$e=[System.Windows.Forms.Clipboard]::GetDataObject()
if ($e -eq $null)
{
Write-Host "there is no data"
}
$img =$e.GetImage()
if ($img -eq $null)
{
Write-Host "there is no picture"
}
$img.save("Path\test.jpg", "jpg")
# I tried using the export method, but it does not exist with chartObjects
$a = $chartToExport.Export("Path\test.gif", "GIF")
- 跳过第 1 步,我尝试将剪贴板数据直接发布到 PowerPoint 演示文稿中,该演示文稿正在运行。
但是,我无法随意放置导入的图片。我尝试在同一时间为文件夹导入图片,然后我没有麻烦地玩它们的位置。
$pptx = "Path\Presentation.pptx"
$pt = New-Object -ComObject powerpoint.application
$presentation = $pt.Presentations.open($pptx)
$slide2 = $presentation.slides.item(2)
$slide3 = $presentation.slides.item(3)
# Paste the Clipboard chart into the PowerPoint presentation.
# Works OK, but I do not success to place where I wish
$shape2 = $slide2.shapes.paste()
$shape2.Left = 10 # Does not work
$shape2.Top = 10 # Does not work
# Test on existing picture, Works OK
$imgTest = "Path\picture.jpg"
$LinkToFile = $msoFalse
$SaveWithDocument = $msoTrue
$Left = 10
$Top = 10
$Width = 10
$Height = 10
$shape3 = $slide3.shapes.addPicture($imgPath, $LinkToFile,
$SaveWithDocument,$Left, $Top, $Width, $Height)
有谁知道如何解决这两个问题中的一个或两个?
【问题讨论】:
标签: excel powershell charts powerpoint