我制作了一个Excel Add In,它必须将打印区域导出为图像。它工作正常,如果我从程序手动设置打印区域(“Excel.Range range = sheet.Range [”A1“,”E5“]”),但我需要在Excel中设置打印区域并导出该区域作为一个形象。有没有人知道如何获得我在Excel中设置的打印区域?
public static void Save(RibbonControlEventArgs e)
{
Excel.Window window = e.Control.Context;
Excel.Worksheet sheet = ((Excel.Worksheet)window.Application.ActiveSheet);
Excel.Range range = sheet.Range["A1", "E5"];
range.CopyPicture(Excel.XlPictureAppearance.xlPrinter, Excel.XlCopyPictureFormat.xlPicture);
range.Copy(Type.Missing);
string fileName = @"U:\test.jpg";
if (Clipboard.GetDataObject() != null)
{
IDataObject data = Clipboard.GetDataObject();
Image image = (Image)data.GetData(DataFormats.Bitmap, true);
image.Save(fileName, ImageFormat.Jpeg);
}
MessageBox.Show("Save successful!", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
答案 0 :(得分:2)
尝试以下代码:
def find_element(self, by=By.ID, value=None):