Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>From what I understand from your question I am not able to reproduce the problem.</p> <p>I selected a range manually in Excel, chose <em>Copy As Picture</em> with the options <em>as shown on screen</em> and <em>Bitmap</em> selected, then I used the following code to save the clipboard data:</p> <pre><code>using System; using System.IO; using System.Windows; using System.Windows.Media.Imaging; using System.Drawing.Imaging; using Excel = Microsoft.Office.Interop.Excel; public class Program { [STAThread] static void Main(string[] args) { Excel.Application excel = new Excel.Application(); Excel.Workbook wkb = excel.Workbooks.Add(Type.Missing); Excel.Worksheet sheet = wkb.Worksheets[1] as Excel.Worksheet; Excel.Range range = sheet.Cells[1, 1] as Excel.Range; range.Formula = "Hello World"; // copy as seen when printed range.CopyPicture(Excel.XlPictureAppearance.xlPrinter, Excel.XlCopyPictureFormat.xlPicture); // uncomment to copy as seen on screen //range.CopyPicture(Excel.XlPictureAppearance.xlScreen, Excel.XlCopyPictureFormat.xlBitmap); Console.WriteLine("Please enter a full file name to save the image from the Clipboard:"); string fileName = Console.ReadLine(); using (FileStream fileStream = new FileStream(fileName, FileMode.Create)) { if (Clipboard.ContainsData(System.Windows.DataFormats.EnhancedMetafile)) { Metafile metafile = Clipboard.GetData(System.Windows.DataFormats.EnhancedMetafile) as Metafile; metafile.Save(fileName); } else if (Clipboard.ContainsData(System.Windows.DataFormats.Bitmap)) { BitmapSource bitmapSource = Clipboard.GetData(System.Windows.DataFormats.Bitmap) as BitmapSource; JpegBitmapEncoder encoder = new JpegBitmapEncoder(); encoder.Frames.Add(BitmapFrame.Create(bitmapSource)); encoder.QualityLevel = 100; encoder.Save(fileStream); } } object objFalse = false; wkb.Close(objFalse, Type.Missing, Type.Missing); excel.Quit(); } } </code></pre> <p>Regarding your second problem: As far as I know it is not possible in Excel to select both a cell range and an image at the same time. If you want to get both in an image at the same time you might have to print the Excel sheet to an image/PDF/XPS file.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload