엑셀 이미지를 다른 이름으로 저장 2
                                            
                                                
                                                
                                                
                                                
                                                
                                                 11573 단어  ExcelPowerShell엑셀
                    
Excel 이미지를 다른 이름으로 저장
"엑셀 이미지를 다른 이름으로 저장" 에서 VBA를 사용하여 이미지를 저장했습니다.
PowerShell을 사용해 보았습니다.
PowerShell에서 Excel Book에 액세스할 때 책을 닫아야 한다고 생각했지만 열어도 괜찮습니다.
이미지 저장은 saggie의 PowerShell로 클립보드 이미지를 파일에 저장을 사용했습니다.
 사용법

제한 사항, 결함
ExcelToPictue.ps1
Set-StrictMode -Version Latest
Add-Type -AssemblyName System.Windows.Forms
# attach to excel file
$Excel = [System.Runtime.InteropServices.Marshal]::GetActiveObject('Excel.Application')
$bookPath = $Excel.ActiveWorkbook.Path
if ($bookPath -eq "" ) {
  Write-Output ">>> save excel file first."
  exit
}
# save each file
$shapes = $Excel.ActiveWorkBook.ActiveSheet.Shapes
$shapes | ForEach-Object {
  # picture position check
  $address = $_.TopLeftCell.address()
  $isInRange = $False
  if ($_.TopLeftCell.row -gt 1) {
    $isInRange = $true
  }
  else {
    $address = $_.TopLeftCell.address
    Write-Output ">>> row of the picture at $address  must > 1."  
  }
  # file name check
  $fileName = ""
  $str_extension = ""
  if ($isInRange)
  {
    $fileName = $_.TopLeftCell.offset(-1, 0).text
    if ($fileName -ne "") {
      $str_extension = [System.IO.Path]::GetExtension($fileName)
      if ($str_extension -eq "") {
        $str_extension = ".png"
        Write-Output ">>> the picture at $address has no extension, so add .png."
        $fileName += $str_extension
      }
    }
    else { 
      $str_extension = ".png"
      $fileName = $address + $str_extension
      Write-Output ">>> the picture at $address has no file name. So name $fileName."
    }
  }
  # capture and save
  # https://qiita.com/saggie/items/44cb8b317fe0effa5891
  # picture save code is form above. 
  $_.CopyPicture(1, 2) # Appearance:=xlScreen, Format:=xlBitmap
  $clipboardImage = [Windows.Forms.Clipboard]::GetImage()
  if ([Windows.Forms.Clipboard]::ContainsImage() -and ($str_extension -ne ""))
  {
    $outputFilePath = Join-Path $bookPath $fileName
    $clipboardImage.Save($outputFilePath)
  }
  else {
    Write-Output ">>> the picture at $address has not captured." 
  }
}
                Reference
이 문제에 관하여(엑셀 이미지를 다른 이름으로 저장 2), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/momoyamas/items/faa87a7169e7facd1d8c텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
                                
                                
                                
                                
                                
                                우수한 개발자 콘텐츠 발견에 전념
                                (Collection and Share based on the CC Protocol.)