Board logo

标题: [转载代码] PowerShell按原尺寸导出Excel中的图片 [打印本页]

作者: DAIC    时间: 2013-9-8 20:47     标题: PowerShell按原尺寸导出Excel中的图片

  1. $excel = New-Object Microsoft.Office.Interop.Excel.ApplicationClass
  2. $table=$excel.Workbooks.open("C:\Users\admin\Desktop\test.xls")
  3. $sheet=$table.Worksheets.Item(1)
  4. #$excel.Visible=1
  5. $copylist=$sheet.Pictures()
  6. $excel.Application.DisplayAlerts = 0
  7. foreach($copy in $copylist){
  8.     $name=$copy.name
  9.     #选中图片
  10.     $excel.ActiveSheet.Shapes.Range([Array]($name)).Select()
  11.     #重设图片为原始大小
  12.     $excel.Application.Selection.ShapeRange.ScaleWidth(1, [Microsoft.Office.Core.MsoTriState]::msoTrue , [Microsoft.Office.Core.MsoScaleFrom]::msoScaleFromTopLeft)
  13.     $excel.Application.Selection.Copy()
  14.     #新建一个chart
  15.     $Chart=$excel.ActiveSheet.ChartObjects().add(1000, 0, $excel.Application.Selection.Width, $excel.Application.Selection.Height).Chart
  16.     $Chart.Paste()
  17.     #导出成jpg文件
  18.     $null=$Chart.Export("C:\Users\admin\Desktop\test2\$name.jpg","JPG")
  19.     $excel.ActiveSheet.ChartObjects().delete()
  20. }
  21. $excel.Application.Quit()
  22. $excel.quit()
复制代码
http://hi.baidu.com/shrekzz/item/70a6711a29e1e22ef7625ce0




欢迎光临 批处理之家 (http://www.bathome.net/) Powered by Discuz! 7.2