More Office-Code cleanup, should use a bit less resources and maybe be more stable. (needs testing)

This commit is contained in:
RKrom 2014-03-17 16:27:21 +01:00
commit 610760a386
6 changed files with 345 additions and 137 deletions

View file

@ -32,15 +32,24 @@ namespace Greenshot.Interop.Office {
public class ExcelExporter {
private static readonly log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(ExcelExporter));
private static readonly OfficeConfiguration officeConfiguration = IniConfig.GetIniSection<OfficeConfiguration>();
private static Version excelVersion;
/// <summary>
/// Get all currently opened workbooks
/// </summary>
/// <returns>List<string> with names of the workbooks</returns>
public static List<string> GetWorkbooks() {
List<string> currentWorkbooks = new List<string>();
using (IExcelApplication excelApplication = COMWrapper.GetInstance<IExcelApplication>()) {
if (excelApplication != null) {
for (int i = 1; i <= excelApplication.Workbooks.Count; i++) {
IWorkbook workbook = excelApplication.Workbooks[i];
if (workbook != null) {
currentWorkbooks.Add(workbook.Name);
using (IExcelApplication excelApplication = GetExcelApplication()) {
if (excelApplication == null) {
return currentWorkbooks;
}
using (IWorkbooks workbooks = excelApplication.Workbooks) {
for (int i = 1; i <= workbooks.Count; i++) {
using (IWorkbook workbook = workbooks[i]) {
if (workbook != null) {
currentWorkbooks.Add(workbook.Name);
}
}
}
}
@ -54,44 +63,103 @@ namespace Greenshot.Interop.Office {
/// <param name="workbookName"></param>
/// <param name="tmpFile"></param>
public static void InsertIntoExistingWorkbook(string workbookName, string tmpFile, Size imageSize) {
using (IExcelApplication excelApplication = COMWrapper.GetInstance<IExcelApplication>()) {
if (excelApplication != null) {
for (int i = 1; i <= excelApplication.Workbooks.Count; i++) {
IWorkbook workbook = excelApplication.Workbooks[i];
if (workbook != null && workbook.Name.StartsWith(workbookName)) {
InsertIntoExistingWorkbook(workbook, tmpFile, imageSize);
using (IExcelApplication excelApplication = GetExcelApplication()) {
if (excelApplication == null) {
return;
}
using (IWorkbooks workbooks = excelApplication.Workbooks) {
for (int i = 1; i <= workbooks.Count; i++) {
using (IWorkbook workbook = workbooks[i]) {
if (workbook != null && workbook.Name.StartsWith(workbookName)) {
InsertIntoExistingWorkbook(workbook, tmpFile, imageSize);
}
}
}
}
}
}
/// <summary>
/// Insert a file into an already created workbook
/// </summary>
/// <param name="workbook"></param>
/// <param name="tmpFile"></param>
/// <param name="imageSize"></param>
private static void InsertIntoExistingWorkbook(IWorkbook workbook, string tmpFile, Size imageSize) {
IWorksheet workSheet = workbook.ActiveSheet;
if (workSheet != null) {
if (workSheet.Shapes != null) {
IShape shape = workSheet.Shapes.AddPicture(tmpFile, MsoTriState.msoFalse, MsoTriState.msoTrue, 0, 0, imageSize.Width, imageSize.Height);
if (shape != null) {
shape.Top = 40;
shape.Left = 40;
shape.LockAspectRatio = MsoTriState.msoTrue;
shape.ScaleHeight(1, MsoTriState.msoTrue, MsoScaleFrom.msoScaleFromTopLeft);
shape.ScaleWidth(1, MsoTriState.msoTrue, MsoScaleFrom.msoScaleFromTopLeft);
if (workSheet == null) {
return;
}
using (IShapes shapes = workSheet.Shapes) {
if (shapes != null) {
using (IShape shape = shapes.AddPicture(tmpFile, MsoTriState.msoFalse, MsoTriState.msoTrue, 0, 0, imageSize.Width, imageSize.Height)) {
if (shape != null) {
shape.Top = 40;
shape.Left = 40;
shape.LockAspectRatio = MsoTriState.msoTrue;
shape.ScaleHeight(1, MsoTriState.msoTrue, MsoScaleFrom.msoScaleFromTopLeft);
shape.ScaleWidth(1, MsoTriState.msoTrue, MsoScaleFrom.msoScaleFromTopLeft);
}
}
}
}
}
/// <summary>
/// Add an image-file to a newly created workbook
/// </summary>
/// <param name="tmpFile"></param>
/// <param name="imageSize"></param>
public static void InsertIntoNewWorkbook(string tmpFile, Size imageSize) {
using (IExcelApplication excelApplication = COMWrapper.GetOrCreateInstance<IExcelApplication>()) {
using (IExcelApplication excelApplication = GetOrCreateExcelApplication()) {
if (excelApplication != null) {
excelApplication.Visible = true;
object template = Missing.Value;
IWorkbook workbook = excelApplication.Workbooks.Add(template);
InsertIntoExistingWorkbook(workbook, tmpFile, imageSize);
using (IWorkbooks workbooks = excelApplication.Workbooks) {
IWorkbook workbook = workbooks.Add(template);
InsertIntoExistingWorkbook(workbook, tmpFile, imageSize);
}
}
}
}
}
/// <summary>
/// Call this to get the running Excel application, returns null if there isn't any.
/// </summary>
/// <returns>IExcelApplication or null</returns>
private static IExcelApplication GetExcelApplication() {
IExcelApplication excelApplication = COMWrapper.GetInstance<IExcelApplication>();
InitializeVariables(excelApplication);
return excelApplication;
}
/// <summary>
/// Call this to get the running Excel application, or create a new instance
/// </summary>
/// <returns>IExcelApplication</returns>
private static IExcelApplication GetOrCreateExcelApplication() {
IExcelApplication excelApplication = COMWrapper.GetOrCreateInstance<IExcelApplication>();
InitializeVariables(excelApplication);
return excelApplication;
}
/// <summary>
/// Initialize static outlook variables like version and currentuser
/// </summary>
/// <param name="excelApplication"></param>
private static void InitializeVariables(IExcelApplication excelApplication) {
if (excelApplication == null || excelVersion != null) {
return;
}
try {
excelVersion = new Version(excelApplication.Version);
LOG.InfoFormat("Using Excel {0}", excelVersion);
} catch (Exception exVersion) {
LOG.Error(exVersion);
LOG.Warn("Assuming Excel version 1997.");
excelVersion = new Version((int)OfficeVersion.OFFICE_97, 0, 0, 0);
}
}
}
}

View file

@ -44,10 +44,6 @@ namespace Greenshot.Interop.Office {
private static readonly string SIGNATURE_PATH = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), @"Microsoft\Signatures");
private static Version outlookVersion = null;
private static string currentUser = null;
private const int OUTLOOK_2003 = 11;
private const int OUTLOOK_2007 = 12;
private const int OUTLOOK_2010 = 14;
private const int OUTLOOK_2013 = 15;
// The signature key can be found at:
// HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles\<DefaultProfile>\9375CFF0413111d3B88A00104B2A6676\<xxxx> [New Signature]
@ -68,7 +64,7 @@ namespace Greenshot.Interop.Office {
return null;
}
if (outlookVersion.Major >= OUTLOOK_2013) {
if (outlookVersion.Major >= (int)OfficeVersion.OFFICE_2013) {
// Check inline "panel" for Outlook 2013
using (var activeExplorer = outlookApplication.ActiveExplorer()) {
if (activeExplorer != null) {
@ -120,7 +116,7 @@ namespace Greenshot.Interop.Office {
if (!mailItem.Sent) {
return true;
}
} else if (outlookVersion.Major >= OUTLOOK_2010 && conf.OutlookAllowExportInMeetings && OlObjectClass.olAppointment.Equals(currentItemClass)) {
} else if (outlookVersion.Major >= (int)OfficeVersion.OFFICE_2010 && conf.OutlookAllowExportInMeetings && OlObjectClass.olAppointment.Equals(currentItemClass)) {
//AppointmentItem appointmentItem = COMWrapper.Cast<AppointmentItem>(currentItem);
AppointmentItem appointmentItem = (AppointmentItem)currentItem;
if (string.IsNullOrEmpty(appointmentItem.Organizer) || (currentUser != null && currentUser.Equals(appointmentItem.Organizer))) {
@ -149,7 +145,7 @@ namespace Greenshot.Interop.Office {
if (outlookApplication == null) {
return false;
}
if (outlookVersion.Major >= OUTLOOK_2013) {
if (outlookVersion.Major >= (int)OfficeVersion.OFFICE_2013) {
// Check inline "panel" for Outlook 2013
using (var activeExplorer = outlookApplication.ActiveExplorer()) {
if (activeExplorer == null) {
@ -271,7 +267,7 @@ namespace Greenshot.Interop.Office {
LOG.InfoFormat("Item '{0}' has format: {1}", mailItem.Subject, mailItem.BodyFormat);
string contentID;
if (outlookVersion.Major >= OUTLOOK_2007) {
if (outlookVersion.Major >= (int)OfficeVersion.OFFICE_2007) {
contentID = Guid.NewGuid().ToString();
} else {
LOG.Info("Older Outlook (<2007) found, using filename as contentid.");
@ -315,7 +311,7 @@ namespace Greenshot.Interop.Office {
// Create the attachment (if inlined the attachment isn't visible as attachment!)
using (IAttachment attachment = mailItem.Attachments.Add(tmpFile, OlAttachmentType.olByValue, inlinePossible ? 0 : 1, attachmentName)) {
if (outlookVersion.Major >= OUTLOOK_2007) {
if (outlookVersion.Major >= (int)OfficeVersion.OFFICE_2007) {
// Add the content id to the attachment, this only works for Outlook >= 2007
try {
IPropertyAccessor propertyAccessor = attachment.PropertyAccessor;
@ -386,7 +382,7 @@ namespace Greenshot.Interop.Office {
// Create the attachment (and dispose the COM object after using)
using (IAttachment attachment = newMail.Attachments.Add(tmpFile, OlAttachmentType.olByValue, 0, attachmentName)) {
// add content ID to the attachment
if (outlookVersion.Major >= OUTLOOK_2007) {
if (outlookVersion.Major >= (int)OfficeVersion.OFFICE_2007) {
try {
contentID = Guid.NewGuid().ToString();
IPropertyAccessor propertyAccessor = attachment.PropertyAccessor;
@ -526,11 +522,11 @@ namespace Greenshot.Interop.Office {
LOG.InfoFormat("Using Outlook {0}", outlookVersion);
} catch (Exception exVersion) {
LOG.Error(exVersion);
LOG.Warn("Assuming outlook version 1.");
outlookVersion = new Version(1, 1, 1, 1);
LOG.Warn("Assuming outlook version 1997.");
outlookVersion = new Version((int)OfficeVersion.OFFICE_97, 0, 0, 0);
}
// Preventing retrieval of currentUser if Outlook is older than 2007
if (outlookVersion.Major >= OUTLOOK_2007) {
if (outlookVersion.Major >= (int)OfficeVersion.OFFICE_2007) {
try {
INameSpace mapiNamespace = outlookApplication.GetNameSpace("MAPI");
currentUser = mapiNamespace.CurrentUser.Name;

View file

@ -28,14 +28,12 @@ using Greenshot.Interop;
namespace Greenshot.Interop.Office {
public class PowerpointExporter {
private static readonly log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(PowerpointExporter));
private static string version = null;
private static Version powerpointVersion;
public static bool isAfter2003() {
if (version != null) {
return !version.StartsWith("11");
}
return false;
return powerpointVersion.Major > (int)OfficeVersion.OFFICE_2003;
}
/// <summary>
/// Get the captions of all the open powerpoint presentations
/// </summary>
@ -43,13 +41,11 @@ namespace Greenshot.Interop.Office {
public static List<string> GetPowerpointPresentations() {
List<string> foundPresentations = new System.Collections.Generic.List<string>();
try {
using (IPowerpointApplication powerpointApplication = COMWrapper.GetInstance<IPowerpointApplication>()) {
using (IPowerpointApplication powerpointApplication = GetPowerpointApplication()) {
if (powerpointApplication == null) {
return foundPresentations;
}
if (version == null) {
version = powerpointApplication.Version;
}
using (IPresentations presentations = powerpointApplication.Presentations) {
LOG.DebugFormat("Open Presentations: {0}", presentations.Count);
for (int i = 1; i <= presentations.Count; i++) {
@ -86,7 +82,7 @@ namespace Greenshot.Interop.Office {
/// <param name="title">A string with the image title</param>
/// <returns></returns>
public static bool ExportToPresentation(string presentationName, string tmpFile, Size imageSize, string title) {
using (IPowerpointApplication powerpointApplication = COMWrapper.GetInstance<IPowerpointApplication>()) {
using (IPowerpointApplication powerpointApplication = GetPowerpointApplication()) {
if (powerpointApplication == null) {
return false;
}
@ -221,7 +217,7 @@ namespace Greenshot.Interop.Office {
/// <returns></returns>
public static bool InsertIntoNewPresentation(string tmpFile, Size imageSize, string title) {
bool isPictureAdded = false;
using (IPowerpointApplication powerpointApplication = COMWrapper.GetOrCreateInstance<IPowerpointApplication>()) {
using (IPowerpointApplication powerpointApplication = GetOrCreatePowerpointApplication()) {
if (powerpointApplication == null) {
return isPictureAdded;
}
@ -239,5 +235,44 @@ namespace Greenshot.Interop.Office {
}
return isPictureAdded;
}
/// <summary>
/// Call this to get the running powerpoint application, returns null if there isn't any.
/// </summary>
/// <returns>IPowerpointApplication or null</returns>
private static IPowerpointApplication GetPowerpointApplication() {
IPowerpointApplication powerpointApplication = COMWrapper.GetInstance<IPowerpointApplication>();
InitializeVariables(powerpointApplication);
return powerpointApplication;
}
/// <summary>
/// Call this to get the running powerpoint application, or create a new instance
/// </summary>
/// <returns>IPowerpointApplication</returns>
private static IPowerpointApplication GetOrCreatePowerpointApplication() {
IPowerpointApplication powerpointApplication = COMWrapper.GetOrCreateInstance<IPowerpointApplication>();
InitializeVariables(powerpointApplication);
return powerpointApplication;
}
/// <summary>
/// Initialize static outlook variables like version and currentuser
/// </summary>
/// <param name="powerpointApplication">IPowerpointApplication</param>
private static void InitializeVariables(IPowerpointApplication powerpointApplication) {
if (powerpointApplication == null || powerpointVersion != null) {
return;
}
try {
powerpointVersion = new Version(powerpointApplication.Version);
LOG.InfoFormat("Using Powerpoint {0}", powerpointVersion);
} catch (Exception exVersion) {
LOG.Error(exVersion);
LOG.Warn("Assuming Powerpoint version 1997.");
powerpointVersion = new Version((int)OfficeVersion.OFFICE_97, 0, 0, 0);
}
}
}
}

View file

@ -29,15 +29,17 @@ using Greenshot.IniFile;
namespace Greenshot.Interop.Office {
public class WordExporter {
private static readonly log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(WordExporter));
private static string version = null;
private static Version wordVersion = null;
private static OfficeConfiguration config = IniConfig.GetIniSection<OfficeConfiguration>();
public static bool isAfter2003() {
if (version != null) {
return !version.StartsWith("11");
}
return false;
/// <summary>
/// Check if the used version is higher than Office 2003
/// </summary>
/// <returns></returns>
private static bool isAfter2003() {
return wordVersion.Major > (int)OfficeVersion.OFFICE_2003;
}
/// <summary>
/// Insert the bitmap stored under the tempfile path into the word document with the supplied caption
/// </summary>
@ -45,12 +47,17 @@ namespace Greenshot.Interop.Office {
/// <param name="tmpFile"></param>
/// <returns></returns>
public static bool InsertIntoExistingDocument(string wordCaption, string tmpFile) {
using (IWordApplication wordApplication = COMWrapper.GetInstance<IWordApplication>()) {
if (wordApplication != null) {
for (int i = 1; i <= wordApplication.Documents.Count; i++) {
using (IWordDocument wordDocument = wordApplication.Documents.item(i)) {
if (wordDocument.ActiveWindow.Caption.StartsWith(wordCaption)) {
return InsertIntoExistingDocument(wordApplication, wordDocument, tmpFile, null, null);
using (IWordApplication wordApplication = GetWordApplication()) {
if (wordApplication == null) {
return false;
}
using (IDocuments documents = wordApplication.Documents) {
for (int i = 1; i <= documents.Count; i++) {
using (IWordDocument wordDocument = documents.item(i)) {
using (IWordWindow activeWindow = wordDocument.ActiveWindow) {
if (activeWindow.Caption.StartsWith(wordCaption)) {
return InsertIntoExistingDocument(wordApplication, wordDocument, tmpFile, null, null);
}
}
}
}
@ -75,23 +82,36 @@ namespace Greenshot.Interop.Office {
wordDocument.Activate();
} catch {
}
if (wordApplication.Selection != null) {
using (ISelection selection = wordApplication.Selection) {
if (selection == null) {
LOG.InfoFormat("No selection to insert {0} into found.", tmpFile);
return false;
}
// Add Picture
using (IInlineShape shape = AddPictureToSelection(wordApplication.Selection, tmpFile)) {
using (IInlineShape shape = AddPictureToSelection(selection, tmpFile)) {
if (!string.IsNullOrEmpty(address)) {
object screentip = Type.Missing;
if (!string.IsNullOrEmpty(tooltip)) {
screentip = tooltip;
}
try {
wordDocument.Hyperlinks.Add(shape, screentip, Type.Missing, screentip, Type.Missing, Type.Missing);
using (IHyperlinks hyperlinks = wordDocument.Hyperlinks) {
hyperlinks.Add(shape, screentip, Type.Missing, screentip, Type.Missing, Type.Missing);
}
} catch (Exception e) {
LOG.WarnFormat("Couldn't add hyperlink for image: {0}", e.Message);
}
}
}
try {
wordDocument.ActiveWindow.ActivePane.View.Zoom.Percentage = 100;
using (IWordWindow activeWindow = wordDocument.ActiveWindow) {
activeWindow.Activate();
using (IPane activePane = activeWindow.ActivePane) {
using (IWordView view = activePane.View) {
view.Zoom.Percentage = 100;
}
}
}
} catch (Exception e) {
if (e.InnerException != null) {
LOG.WarnFormat("Couldn't set zoom to 100, error: {0}", e.InnerException.Message);
@ -101,64 +121,74 @@ namespace Greenshot.Interop.Office {
}
try {
wordApplication.Activate();
} catch {}
} catch {
}
try {
wordDocument.Activate();
} catch {}
try {
wordDocument.ActiveWindow.Activate();
} catch {}
} catch {
}
return true;
}
return false;
}
/// <summary>
/// Helper method to add the file as image to the selection
/// </summary>
/// <param name="selection"></param>
/// <param name="tmpFile"></param>
/// <returns></returns>
private static IInlineShape AddPictureToSelection(ISelection selection, string tmpFile) {
IInlineShape shape = selection.InlineShapes.AddPicture(tmpFile, false, true, Type.Missing);
// Lock aspect ratio
if (config.WordLockAspectRatio) {
shape.LockAspectRatio = MsoTriState.msoTrue;
using (IInlineShapes shapes = selection.InlineShapes) {
IInlineShape shape = shapes.AddPicture(tmpFile, false, true, Type.Missing);
// Lock aspect ratio
if (config.WordLockAspectRatio) {
shape.LockAspectRatio = MsoTriState.msoTrue;
}
selection.InsertAfter("\r\n");
return shape;
}
selection.InsertAfter("\r\n");
return shape;
}
public static void InsertIntoNewDocument(string tmpFile, string address, string tooltip) {
using (IWordApplication wordApplication = COMWrapper.GetOrCreateInstance<IWordApplication>()) {
if (wordApplication != null) {
wordApplication.Visible = true;
wordApplication.Activate();
// Create new Document
object template = string.Empty;
object newTemplate = false;
object documentType = 0;
object documentVisible = true;
IWordDocument wordDocument = wordApplication.Documents.Add(ref template, ref newTemplate, ref documentType, ref documentVisible);
// Add Picture
using (IInlineShape shape = AddPictureToSelection(wordApplication.Selection, tmpFile)) {
if (!string.IsNullOrEmpty(address)) {
object screentip = Type.Missing;
if (!string.IsNullOrEmpty(tooltip)) {
screentip = tooltip;
}
try {
wordDocument.Hyperlinks.Add(shape, screentip, Type.Missing, screentip, Type.Missing, Type.Missing);
} catch (Exception e) {
LOG.WarnFormat("Couldn't add hyperlink for image: {0}", e.Message);
using (IWordApplication wordApplication = GetOrCreateWordApplication()) {
if (wordApplication == null) {
return;
}
wordApplication.Visible = true;
wordApplication.Activate();
// Create new Document
object template = string.Empty;
object newTemplate = false;
object documentType = 0;
object documentVisible = true;
using (IDocuments documents = wordApplication.Documents) {
using (IWordDocument wordDocument = documents.Add(ref template, ref newTemplate, ref documentType, ref documentVisible)) {
using (ISelection selection = wordApplication.Selection) {
// Add Picture
using (IInlineShape shape = AddPictureToSelection(selection, tmpFile)) {
if (!string.IsNullOrEmpty(address)) {
object screentip = Type.Missing;
if (!string.IsNullOrEmpty(tooltip)) {
screentip = tooltip;
}
try {
using (IHyperlinks hyperlinks = wordDocument.Hyperlinks) {
hyperlinks.Add(shape, screentip, Type.Missing, screentip, Type.Missing, Type.Missing);
}
} catch (Exception e) {
LOG.WarnFormat("Couldn't add hyperlink for image: {0}", e.Message);
}
}
}
}
}
try {
wordApplication.Activate();
} catch {
}
try {
wordDocument.Activate();
} catch {
}
try {
wordDocument.ActiveWindow.Activate();
} catch {
try {
wordDocument.Activate();
} catch {
}
try {
wordDocument.ActiveWindow.Activate();
} catch {
}
}
}
}
@ -169,31 +199,72 @@ namespace Greenshot.Interop.Office {
/// </summary>
/// <returns></returns>
public static List<string> GetWordDocuments() {
List<string> documents = new List<string>();
List<string> openDocuments = new List<string>();
try {
using (IWordApplication wordApplication = COMWrapper.GetInstance<IWordApplication>()) {
if (wordApplication != null) {
if (version == null) {
version = wordApplication.Version;
}
for (int i = 1; i <= wordApplication.Documents.Count; i++) {
IWordDocument document = wordApplication.Documents.item(i);
if (document.ReadOnly) {
continue;
}
if (isAfter2003()) {
if (document.Final) {
using (IWordApplication wordApplication = GetWordApplication()) {
if (wordApplication == null) {
return openDocuments;
}
using (IDocuments documents = wordApplication.Documents) {
for (int i = 1; i <= documents.Count; i++) {
using (IWordDocument document = documents.item(i)) {
if (document.ReadOnly) {
continue;
}
if (isAfter2003()) {
if (document.Final) {
continue;
}
}
using (IWordWindow activeWindow = document.ActiveWindow) {
openDocuments.Add(activeWindow.Caption);
}
}
documents.Add(document.ActiveWindow.Caption);
}
}
}
} catch (Exception ex) {
LOG.Warn("Problem retrieving word destinations, ignoring: ", ex);
}
return documents;
return openDocuments;
}
/// <summary>
/// Call this to get the running outlook application, returns null if there isn't any.
/// </summary>
/// <returns>IWordApplication or null</returns>
private static IWordApplication GetWordApplication() {
IWordApplication wordApplication = COMWrapper.GetInstance<IWordApplication>();
InitializeVariables(wordApplication);
return wordApplication;
}
/// <summary>
/// Call this to get the running word application, or create a new instance
/// </summary>
/// <returns>IWordApplication</returns>
private static IWordApplication GetOrCreateWordApplication() {
IWordApplication wordApplication = COMWrapper.GetOrCreateInstance<IWordApplication>();
InitializeVariables(wordApplication);
return wordApplication;
}
/// <summary>
/// Initialize static outlook variables like version and currentuser
/// </summary>
/// <param name="wordApplication"></param>
private static void InitializeVariables(IWordApplication wordApplication) {
if (wordApplication == null || wordVersion != null) {
return;
}
try {
wordVersion = new Version(wordApplication.Version);
LOG.InfoFormat("Using Word {0}", wordVersion);
} catch (Exception exVersion) {
LOG.Error(exVersion);
LOG.Warn("Assuming Word version 1997.");
wordVersion = new Version((int)OfficeVersion.OFFICE_97, 0, 0, 0);
}
}
}
}

View file

@ -23,38 +23,64 @@ namespace Greenshot.Interop.Office {
// See http://msdn.microsoft.com/en-us/library/microsoft.office.interop.excel.application.aspx
[ComProgId("Excel.Application")]
public interface IExcelApplication : ICommon {
IWorkbook ActiveWorkbook { get; }
IWorkbook ActiveWorkbook {
get;
}
//ISelection Selection {get;}
IWorkbooks Workbooks { get; }
bool Visible { get; set; }
IWorkbooks Workbooks {
get;
}
bool Visible {
get;
set;
}
string Version {
get;
}
}
// See: http://msdn.microsoft.com/en-us/library/microsoft.office.interop.excel.workbooks.aspx
public interface IWorkbooks : ICommon, ICollection {
IWorkbook Add(object template);
// Use index + 1!!
IWorkbook this[object Index] { get; }
IWorkbook this[object Index] {
get;
}
}
// See: http://msdn.microsoft.com/en-us/library/microsoft.office.interop.excel.workbook.aspx
public interface IWorkbook : ICommon {
IWorksheet ActiveSheet { get; }
string Name { get; }
IWorksheet ActiveSheet {
get;
}
string Name {
get;
}
void Activate();
IWorksheets Worksheets { get; }
IWorksheets Worksheets {
get;
}
}
// See: http://msdn.microsoft.com/en-us/library/microsoft.office.interop.excel._worksheet_members.aspx
public interface IWorksheet : ICommon {
IPictures Pictures { get; }
IShapes Shapes {get; }
string Name { get; }
IPictures Pictures {
get;
}
IShapes Shapes {
get;
}
string Name {
get;
}
}
// See: http://msdn.microsoft.com/en-us/library/microsoft.office.interop.excel.iworksheets_members.aspx
public interface IWorksheets : ICommon, ICollection {
// Use index + 1!!
IWorksheet this[object Index] { get; }
IWorksheet this[object Index] {
get;
}
}
public interface IPictures : ICommon, ICollection {

View file

@ -21,11 +21,23 @@
using System.Collections;
namespace Greenshot.Interop.Office {
public enum OfficeVersion : int {
OFFICE_97 = 8,
OFFICE_2000 = 9,
OFFICE_2002 = 10,
OFFICE_2003 = 11,
OFFICE_2007 = 12,
OFFICE_2010 = 14,
OFFICE_2013 = 15
}
/// <summary>
/// If the "type" this[object index] { get; } is implemented, use index + 1!!! (starts at 1)
/// </summary>
public interface ICollection : ICommon, IEnumerable {
int Count { get; }
int Count {
get;
}
void Remove(int index);
}
}