public static void ExportNamedRanges() { OfceExcel.Workbook WB = MyApp.ExcelApp.ActiveWorkbook; foreach (OfceExcel.Name NamedRange in WB.Names) { try { OfceExcel.Range CurRange = NamedRange.RefersToRange; CurRange.CopyPicture(OfceExcel.XlPictureAppearance.xlScreen, OfceExcel.XlCopyPictureFormat.xlBitmap); MyApp.Fullpathname = MyApp.ExcelApp.ActiveWorkbook.Path + "\\" + WB.Name + "_" + NamedRange.Name + ".png"; sysImg.Imaging.ImageFormat PngFormat = sysImg.Imaging.ImageFormat.Png; bool result = MyApp.SaveImage(MyApp.Fullpathname, PngFormat); } catch { } finally { } } foreach (OfceExcel.Worksheet WS in WB.Worksheets) { foreach (OfceExcel.Name NamedRange in WS.Names) { } } }
// ribbon callback public void OnButtonPressed(Microsoft.Office.Core.IRibbonControl control) { //string ExcelWBName = MyApp.ExcelApp.ActiveWorkbook.Name; //Debug.WriteLine(ExcelWBName); MyApp.ExportNamedRanges(); ButtonPressedEventArgs args = new ButtonPressedEventArgs { ControlId = control }; OnButtonPressedEvent(args); }
public void OnAction(Microsoft.Office.Core.IRibbonControl control) { Debug.WriteLine(control.Id); MyApp.ExportNamedRanges(); }
public static void SaveWithWB(string filename) { MyApp.Fullpathname = MyApp.ExcelApp.ActiveWorkbook.Path + "\\" + filename + ".png"; sysImg.Imaging.ImageFormat PngFormat = sysImg.Imaging.ImageFormat.Png; bool result = MyApp.SaveImage(MyApp.Fullpathname, PngFormat); }