标题: [转载代码] PowerShell按原尺寸导出Excel中的图片 [打印本页]
作者: DAIC 时间: 2013-9-8 20:47 标题: PowerShell按原尺寸导出Excel中的图片
- $excel = New-Object Microsoft.Office.Interop.Excel.ApplicationClass
- $table=$excel.Workbooks.open("C:\Users\admin\Desktop\test.xls")
- $sheet=$table.Worksheets.Item(1)
- #$excel.Visible=1
- $copylist=$sheet.Pictures()
- $excel.Application.DisplayAlerts = 0
- foreach($copy in $copylist){
- $name=$copy.name
- #选中图片
- $excel.ActiveSheet.Shapes.Range([Array]($name)).Select()
- #重设图片为原始大小
- $excel.Application.Selection.ShapeRange.ScaleWidth(1, [Microsoft.Office.Core.MsoTriState]::msoTrue , [Microsoft.Office.Core.MsoScaleFrom]::msoScaleFromTopLeft)
- $excel.Application.Selection.Copy()
- #新建一个chart
- $Chart=$excel.ActiveSheet.ChartObjects().add(1000, 0, $excel.Application.Selection.Width, $excel.Application.Selection.Height).Chart
- $Chart.Paste()
- #导出成jpg文件
- $null=$Chart.Export("C:\Users\admin\Desktop\test2\$name.jpg","JPG")
- $excel.ActiveSheet.ChartObjects().delete()
- }
- $excel.Application.Quit()
- $excel.quit()
复制代码
http://hi.baidu.com/shrekzz/item/70a6711a29e1e22ef7625ce0
欢迎光临 批处理之家 (http://bbs.bathome.net/) |
Powered by Discuz! 7.2 |